您似乎还未注册一个账号?我们强烈推荐您点击此处创建一个账户。|如果您在H萌娘上发现某些内容错误/空缺/不中立,请勇于按右上角编辑按钮!

MediaWiki:Common.js

H萌娘,万物皆可H的百科全书!
imported>=海豚=2020年3月12日 (四) 12:06的版本 (搬运代码以实现编辑备份)
跳转到导航 跳转到搜索

注意:这类代码页面在保存之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。

  • 按住CTRL+SHIFT+DEL 或 ⌘-Shift-R来清除缓存!
  • 或尝试在地址栏的地址最后添加代码?_=1来访问最新页面。
    添加代码后的本页地址如下:-{R|https://hmoegirl.com/MediaWiki:Common.js?_=1}-
  • 你还可以在设置中勾选小工具在页面右上角添加清除缓存按钮!
1. 桌面版CSS MediaWiki:Common.css
2. 桌面版JS MediaWiki:Common.js
3. 移动端CSS MediaWiki:Mobile.css
4. 移动端JS MediaWiki:Mobile.js
5. 全局共用CSS MediaWiki:Gadget-site-styles.css
6. 全局共用JS MediaWiki:Gadget-site-javascript.js
7. 管理员CSS MediaWiki:Group-sysop.css
8. 管理员JS MediaWiki:Group-sysop.js
9. 编辑时载入 MediaWiki:Common.js/edit.js
引用api时用mw.loader.using("mw.Api"),引用uri时用mw.loader.using("mediawiki.Uri")
/* 这里的任何JavaScript将为所有用户在每次页面载入时加载。 */
(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');
        // 新建一个Class 以避免许多问题
        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) {
            if ($(this).find('.TabLabel')[0]) return true;
            var self = $(this),
                data = $.extend({
                    labelPadding: null,
                    labelBorderColor: null,
                    labelColor: null,
                    labelBackgroundColor: $('#content').css('background-color'),
                    textPadding: null,
                    textBorderColor: null,
                    textBackgroundColor: null,
                    defaultTab: 1,
                }, self.attr('class').length > 4 ? defaultStyle[self.attr('class').slice(5)] || {} : {}, this.dataset || {}),
                tabLabel = self.append('<div class="TabLabel"></div>').find('.TabLabel'),
                tabContent = self.append('<div class="TabContent"></div>').find('.TabContent'),
                labelPadding = data.labelPadding,
                labelColor = data.labelColor,
                styleSheet = {
                    label: new StyleSheet(),
                    text: new StyleSheet()
                },
                defaultTab = parseInt(data.defaultTab);
            self.find('.Tab').each(function() {
                $(this).find('.TabLabelText').appendTo(self.find('.TabLabel'));
                $(this).find('.TabContentText').appendTo(self.find('.TabContent'));
                $(this).remove();
            });
            if (isNaN(defaultTab) || defaultTab <= 0 || defaultTab > self.find('.TabLabelText').length) defaultTab = 1;
            self.find('.TabLabelText').on('click', function() {
                var label = $(this);
                label.addClass('selected').siblings().removeClass('selected').css({
                    'border-color': '#aaa',
                    'background-color': 'inherit'
                });
                self.find('.TabContentText').eq(self.find('.TabLabelText').index(label)).addClass('selected').siblings().removeClass('selected').removeAttr('style');
                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);
            }).eq(defaultTab - 1).click();
            if (labelPadding) self.find('.TabLabelText').css('padding', labelPadding);
            ['labelBorderColor', 'labelBackgroundColor', 'textPadding', 'textBorderColor', 'textBackgroundColor'].forEach(function(n) {
                var target = /^label/.test(n) ? 'label' : 'text',
                    key = n.replace(target, '').toLowerFirstCase();
                styleSheet[target][key] = data[n];
            });
            if (labelColor) styleSheet.label.borderTopColor = labelColor;
            else if (styleSheet.label.borderColor) styleSheet.label.borderTopColor = 'green';
            tabLabel.find('.selected').click();
            if (styleSheet.text.getOwnPropertyNamesLength()) tabContent.css(styleSheet.text);
            if (data.autoWidth == 'yes') self.css('display', 'inline-block');
        });
    }
        //注释内列表
        $(".reference-text > ul,.reference-text > ol").each(function() {
            if (this.parentElement.childNodes[0] === this) { $(this).addClass("listInRef"); }
        });
        //列表侧边距
        setInterval(function() {
            $(".mw-parser-output ul, .mw-parser-output ol").not(".margin-left-set").each(function() {
                if (/none.+none/i.test($(this).css("list-style")) || $(this).is(".gallery")) {
                    if ($(this).parent().is("li") && $(this).parent().parent().is("ul,ol")) { $(this).css("margin-left", "1.2em"); } else { $(this).css("margin-left", "0.2em"); }
                } else if ($(this).is("ol")) {
                    var l = $(this).children("li").length;
                    if ($(this).attr("start")) { l += parseInt($(this).attr("start")); }
                    $(this).css("margin-left", (l + "").length * 0.5 + 1.2 + "em");
                } else { $(this).css("margin-left", "1.2em"); }
                $(this).addClass("margin-left-set");
            });
        }, 200);
     //编辑自动备份到浏览器
$(function(){
  if(! /action=(edit|submit)/.test(location.href)){ return }

  var editBox = $('#wpTextbox1'),
  btns = $('#wpSaveWidget, #wpPreviewWidget, #wpDiffWidget'),
  title = decodeURIComponent(location.search.match(/title=([^&]+)/)[1]),
  backupList = JSON.parse(localStorage.getItem('Moegirl-koharubiyori-editBackup') || '{}')
  
  $.each(backupList, function(key, val){
  	var time = new Date().getTime()
  	if(val.expires < time){
  		delete backupList[key]
  	}
  })

	setTimeout(function(){
	  var backup = backupList[title]
	  if(backup){
		var btn = $('<span class="oo-ui-widget oo-ui-widget-enabled oo-ui-inputWidget oo-ui-buttonElement oo-ui-buttonElement-framed oo-ui-labelElement oo-ui-buttonInputWidget"><input type="button" value="还原备份" class="oo-ui-inputWidget-input oo-ui-buttonElement-button" /></span>')
		.click(function(){ 
			editBox.val(backup.content)
	    	mw.notify('已还原备份!', { type: 'warn' })     
		})    	
	  }else{
	  	var btn = $('<span class="oo-ui-widget oo-ui-inputWidget oo-ui-buttonElement oo-ui-buttonElement-framed oo-ui-labelElement oo-ui-buttonInputWidget oo-ui-widget-disabled"><input type="button" value="还原备份" class="oo-ui-inputWidget-input oo-ui-buttonElement-button" disabled /></span>')
	  }
	  $('#wpDiffWidget').after(btn)
	})

  btns.mousedown(function(e){
      var content = editBox.val()
	  var expire = new Date().getTime() + 1000 * 60 * 60 * 24 * 7
	  backupList[title] = {
	  	expires : expire,
	  	content : content
	  }
	  localStorage.setItem('Moegirl-koharubiyori-editBackup', JSON.stringify(backupList))
  })
})
    //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>');
        if (!window.localStorage.getItem('x18')) { //如果没有x18记录
            $('body').css('overflow', 'hidden'); //禁止滚屏
            $('#mw-content-text').css({
                'opacity': 0
            }); //禁止偷看
            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
                    }); //显示警告信息
                    $(this).dequeue();
                });
            $('#x18Yes').on('click', function() {
                window.localStorage.setItem('x18', true); //记录x18
                $('#mw-content-text').css('opacity', 1).removeAttr('style'); //显示内容
                $("#x18").remove(); //移除警告信息
                $('body').removeAttr('style'); //允许滚屏
            });
            $('#x18No').on('click', function() {
                window.location.replace(window.location.origin + '/' + mw.config.get('wgMainPageTitle')); //不给你看
            });
        } else $("#x18").remove(); //如果有x18记录
    }
    $(function() {
        tabs();
        r18Warning();
    });
})();