MediaWiki:Common.js:修订间差异

imported>Nostalgia
创建页面,内容为“这里的任何JavaScript将为所有用户在每次页面载入时加载。:​ //Tabs function tabs() { $('body').addClass('tab'); $('.Ta...”
 
imported>AnnAngela
R18警告 & Tabs函数更新
第1行: 第1行:
/* 这里的任何JavaScript将为所有用户在每次页面载入时加载。 */
/* 这里的任何JavaScript将为所有用户在每次页面载入时加载。 */
(function() {
     //Tabs
     //Tabs
     function tabs() {
     function tabs() {
        var defaultStyle = {
            purple: {
                labelColor: ' ', //anti check
                labelBackgroundColor: '#9070c0',
                labelBorderColor: '#b090e0 #7050a0 #9070c0 #b090e0',
                labelPadding: '.2em .3em .2em .3em',
                textBorderColor: '#9070c0',
                textBackgroundColor: '#f0edf5',
                textPadding: '1em'
            },
            green: {
                labelColor: ' ',
                labelBackgroundColor: '#75c045',
                labelBorderColor: '#90d060 #60b030 #75c045 #90d060',
                labelPadding: '.2em .3em .2em .3em',
                textBorderColor: '#75c045 #60b030 #60b030 #75c045',
                textBackgroundColor: '#f5fffa',
                textPadding: '1em'
            },
            red: {
                labelColor: ' ',
                labelBackgroundColor: '#FF0000',
                labelBorderColor: '#FF8888 #CC0000 #FF0000 #FF8888',
                labelPadding: '.2em .3em .2em .3em',
                textBorderColor: '#FF0000 #CC0000 #CC0000 #FF0000',
                textBackgroundColor: '#fffafa',
                textPadding: '1em'
            },
            blue: {
                labelColor: ' ',
                labelBackgroundColor: '#5b8dd6',
                labelBorderColor: '#88abde #3379de #5b8dd6 #88abde',
                labelPadding: '.2em .3em .2em .3em',
                textBackgroundColor: '#f0f8ff',
                textBorderColor: '#5b8dd6 #3379de #3379de #5b8dd6',
                textPadding: '1em'
            },
            yellow: {
                labelColor: ' ',
                labelBackgroundColor: '#ffe147',
                labelBorderColor: '#ffe977 #ffd813 #ffe147 #ffe977',
                labelPadding: '.2em .3em .2em .3em',
                textBackgroundColor: '#fffce8',
                textBorderColor: '#ffe147 #ffd813 #ffd813 #ffe147',
                textPadding: '1em'
            },
            orange: {
                labelColor: ' ',
                labelBackgroundColor: '#ff9d42',
                labelBorderColor: '#ffac5d #ff820e #ff9d42 #ffac5d',
                labelPadding: '.2em .3em .2em .3em',
                textBackgroundColor: '#ffeedd',
                textBorderColor: '#ff9d42 #ff820e #ff820e #ff9d42',
                textPadding: '1em'
            },
            black: {
                labelColor: ' ',
                labelBackgroundColor: '#7f7f7f',
                labelBorderColor: '#999999 #4c4c4c #7f7f7f #999999',
                labelPadding: '.2em .3em .2em .3em',
                textBackgroundColor: '#e5e5e5',
                textBorderColor: '#7f7f7f #4c4c4c #4c4c4c #7f7f7f',
                textPadding: '1em'
            }
        };
         $('body').addClass('tab');
         $('body').addClass('tab');
        function StyleSheet() {}
        StyleSheet.prototype.getOwnPropertyNamesLength = function getOwnPropertyNamesLength() {
            return Object.getOwnPropertyNames(this).length;
        };
        String.prototype.toLowerFirstCase = function toLowerFirstCase() {
            return this[0].toLowerCase() + this.substring(1);
        };
         $('.Tabs').each(function(i) {
         $('.Tabs').each(function(i) {
             if ($(this).find('.TabLabel')[0]) return true;
             if ($(this).find('.TabLabel')[0]) return true;
第10行: 第84行:
                     labelBorderColor: null,
                     labelBorderColor: null,
                     labelColor: null,
                     labelColor: null,
                     labelBackgroundColor: $('body').css('background-color'),
                     labelBackgroundColor: $('#content').css('background-color'),
                     textPadding: null,
                     textPadding: null,
                     textBorderColor: null,
                     textBorderColor: null,
                     textBackgroundColor: null,
                     textBackgroundColor: null,
                     defaultTab: 1,
                     defaultTab: 1,
                 }, self.attr('class').length > 4 ? {
                 }, self.attr('class').length > 4 ? defaultStyle[self.attr('class').slice(5)] || {} : {}, this.dataset || {}),
                    purple: {
                        labelColor: ' ', //anti check
                        labelBackgroundColor: '#9070c0',
                        labelBorderColor: '#b090e0 #7050a0 #9070c0 #b090e0',
                        labelPadding: '.2em .3em .2em .3em',
                        textBorderColor: '#9070c0',
                        textBackgroundColor: '#f0edf5',
                        textPadding: '1em'
                    },
                    green: {
                        labelColor: ' ',
                        labelBackgroundColor: '#75c045',
                        labelBorderColor: '#90d060 #60b030 #75c045 #90d060',
                        labelPadding: '.2em .3em .2em .3em',
                        textBorderColor: '#75c045 #60b030 #60b030 #75c045',
                        textBackgroundColor: '#f5fffa',
                        textPadding: '1em'
                    },
                    red: {
                        labelColor: ' ',
                        labelBackgroundColor: '#FF0000',
                        labelBorderColor: '#FF8888 #CC0000 #FF0000 #FF8888',
                        labelPadding: '.2em .3em .2em .3em',
                        textBorderColor: '#FF0000 #CC0000 #CC0000 #FF0000',
                        textBackgroundColor: '#fffafa',
                        textPadding: '1em'
                    },
                    blue: {
                        labelColor: ' ',
                        labelBackgroundColor: '#5b8dd6',
                        labelBorderColor: '#88abde #3379de #5b8dd6 #88abde',
                        labelPadding: '.2em .3em .2em .3em',
                        textBackgroundColor: '#f0f8ff',
                        textBorderColor: '#5b8dd6 #3379de #3379de #5b8dd6',
                        textPadding: '1em'
                    },
                    yellow: {
                        labelColor: ' ',
                        labelBackgroundColor: '#ffe147',
                        labelBorderColor: '#ffe977 #ffd813 #ffe147 #ffe977',
                        labelPadding: '.2em .3em .2em .3em',
                        textBackgroundColor: '#fffce8',
                        textBorderColor: '#ffe147 #ffd813 #ffd813 #ffe147',
                        textPadding: '1em'
                    },
                    orange: {
                        labelColor: ' ',
                        labelBackgroundColor: '#ff9d42',
                        labelBorderColor: '#ffac5d #ff820e #ff9d42 #ffac5d',
                        labelPadding: '.2em .3em .2em .3em',
                        textBackgroundColor: '#ffeedd',
                        textBorderColor: '#ff9d42 #ff820e #ff820e #ff9d42',
                        textPadding: '1em'
                    },
                    black: {
                        labelColor: ' ',
                        labelBackgroundColor: '#7f7f7f',
                        labelBorderColor: '#999999 #4c4c4c #7f7f7f #999999',
                        labelPadding: '.2em .3em .2em .3em',
                        textBackgroundColor: '#e5e5e5',
                        textBorderColor: '#7f7f7f #4c4c4c #4c4c4c #7f7f7f',
                        textPadding: '1em'
                    }
                }[self.attr('class').slice(5)] || {} : {}, this.dataset),
                 tabLabel = self.append('<div class="TabLabel"></div>').find('.TabLabel'),
                 tabLabel = self.append('<div class="TabLabel"></div>').find('.TabLabel'),
                 tabContent = self.append('<div class="TabContent"></div>').find('.TabContent'),
                 tabContent = self.append('<div class="TabContent"></div>').find('.TabContent'),
                 labelPadding = data.labelPadding,
                 labelPadding = data.labelPadding,
                labelBorderColor = data.labelBorderColor,
                labelBackgroundColor = data.labelBackgroundColor,
                 labelColor = data.labelColor,
                 labelColor = data.labelColor,
                 textPadding = data.textPadding,
                 styleSheet = {
                textBorderColor = data.textBorderColor,
                    label: new StyleSheet(),
                textBackgroundColor = data.textBackgroundColor,
                    text: new StyleSheet()
                 labelStyleSheet = {},
                 },
                textStyleSheet = {},
                 defaultTab = parseInt(data.defaultTab);
                 defaultTab,
                objectLength = function(obj) {
                    return Object.getOwnPropertyNames(obj).length;
                };
             self.find('.Tab').each(function() {
             self.find('.Tab').each(function() {
                 $(this).find('.TabLabelText').appendTo(self.find('.TabLabel'));
                 $(this).find('.TabLabelText').appendTo(self.find('.TabLabel'));
第100行: 第104行:
                 $(this).remove();
                 $(this).remove();
             });
             });
            defaultTab = parseInt(data.defaultTab);
             if (isNaN(defaultTab) || defaultTab <= 0 || defaultTab > self.find('.TabLabelText').length) defaultTab = 1;
             if (isNaN(defaultTab) || defaultTab <= 0 || defaultTab > self.find('.TabLabelText').length) defaultTab = 1;
             self.find('.TabLabelText').bind('click', function() {
             self.find('.TabLabelText').on('click', function() {
                 var label = $(this);
                 var label = $(this);
                 label.addClass('selected').siblings().removeClass('selected').css({
                 label.addClass('selected').siblings().removeClass('selected').css({
第109行: 第112行:
                 });
                 });
                 self.find('.TabContentText').eq(self.find('.TabLabelText').index(label)).addClass('selected').siblings().removeClass('selected').removeAttr('style');
                 self.find('.TabContentText').eq(self.find('.TabLabelText').index(label)).addClass('selected').siblings().removeClass('selected').removeAttr('style');
                 if (objectLength(labelStyleSheet)) label.css(labelStyleSheet);
                 if (styleSheet.label.getOwnPropertyNamesLength()) label.css(styleSheet.label);
                 self.find('.TabLabel').height(label.height() + parseFloat(label.css('padding-top')) + parseFloat(label.css('padding-bottom')) + 2);
                 self.find('.TabLabel').height(label.height() + parseFloat(label.css('padding-top')) + parseFloat(label.css('padding-bottom')) + 2);
             }).eq(defaultTab - 1).click();
             }).eq(defaultTab - 1).click();
             if (labelPadding) self.find('.TabLabelText').css('padding', labelPadding);
             if (labelPadding) self.find('.TabLabelText').css('padding', labelPadding);
             if (labelBorderColor) labelStyleSheet.borderColor = labelBorderColor;
             ['labelBorderColor', 'labelBackgroundColor', 'textPadding', 'textBorderColor', 'textBackgroundColor'].forEach(function(n) {
             if (labelBackgroundColor) labelStyleSheet.backgroundColor = labelBackgroundColor;
                var target = /^label/.test(n) ? 'label' : 'text',
             if (labelColor) labelStyleSheet.borderTopColor = labelColor;
                    key = n.replace(target, '').toLowerFirstCase();
             else if (labelStyleSheet.borderColor) labelStyleSheet.borderTopColor = 'green';
                styleSheet[target][key] = data[n];
            if (textPadding) textStyleSheet.padding = textPadding;
             });
            if (textBorderColor) textStyleSheet.borderColor = textBorderColor;
             if (labelColor) styleSheet.label.borderTopColor = labelColor;
            if (textBackgroundColor) textStyleSheet.backgroundColor = textBackgroundColor;
             else if (styleSheet.label.borderColor) styleSheet.label.borderTopColor = 'green';
             tabLabel.find('.selected').click();
             tabLabel.find('.selected').click();
             if (objectLength(textStyleSheet)) tabContent.css(textStyleSheet);
             if (styleSheet.text.getOwnPropertyNamesLength()) tabContent.css(styleSheet.text);
             if (data.autoWidth == 'yes') self.css('display', 'inline-block');
             if (data.autoWidth == 'yes') self.css('display', 'inline-block');
         });
         });
     }
     }
    //R18警告,仅在非首页的(主)名字空间页面运行
    function r18Warning() {
        var content = $('<div id="x18"><div id="x18Context"><div id="x18Title"><div id="x18Icon"></div></div><div class="x18Button"></div></div></div><div class="x18-page-warning" style="position:fixed;top: 0px;left: 0px;z-index:2"><a href="/Mainpage" title="点此返回主页"><img alt="点此返回主页" src="https://img.moegirl.org/common/d/d3/%E6%9C%AC%E6%96%87%E4%B8%8D%E9%80%82%E5%90%88%E6%9C%AA%E6%88%90%E5%B9%B4%E4%BA%BA%E6%B5%8F%E8%A7%88.png" width="227" height="83"></a></div>');
        if (window.localStorage.getItem('x18') !== 1) { //如果没有x18记录
            $('body').css('overflow', 'hidden'); //禁止滚屏
            $('#mw-content-text').css({
                'opacity': 0,
                'transition': 'opacity 0.37s linear'
            }); //禁止偷看并加点动画
            content.prependTo('body').find('.x18Button').append('<div id="x18Yes">是</div><div id="x18No" class="x18Button">否</div>')
                .end().find('#x18Title').append('你是否已年满十八岁?')
                .end().delay(400).queue(function() {
                    $(this).css({
                        'opacity': 1,
                        'transition': 'opacity 0.37s linear'
                    }); //显示警告信息并加点动画
                    $(this).dequeue();
                });
            $('#x18Yes').bind('click', function() {
                window.localStorage.setItem('x18', true); //记录x18
                $('#mw-content-text').css('opacity', 1).delay(400).queue(function() {
                    $(this).removeAttr('style'); //显示内容
                    $(this).dequeue();
                });
                $("#x18").css('opacity', 0).delay(400).queue(function() {
                    $('body').removeAttr('style'); //允许滚屏
                    $(this).remove(); //移除警告信息
                    $(this).dequeue();
                });
            });
            $('#x18No').bind('click', function() {
                window.location.replace(window.location.origin + '/' + mw.config.get('wgMainPageTitle')); //不给你看
            });
        } else $("#x18").remove(); //如果有x18记录
        $('.x18-page-warning').appendTo('.mw-panel');
    }
    $(function() {
        tabs();
        if (mw.config.get('wgMainPageTitle') !== mw.config.get('wgPageName') && mw.config.get('wgNamespaceNumber') === 0) r18Warning();
    });
})();