User:LovelyA72/common.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
The accompanying .css page for this skin is at User:LovelyA72/common.css. |
//<nowiki>
mw.loader.load('//fr.wikipedia.org/w/index.php?title=Utilisateur:Ltrlg/scripts/TemplateDataEditor.js&action=raw&ctype=text/javascript');
// install [[User:Cacycle/wikEd]] in-browser text editor
( function () { var script = document.createElement( 'script' ); script.src = '//wiki.riteme.site/w/index.php?title=User:Cacycle/wikEd.js&action=raw&ctype=text/javascript'; script.async = true; document.getElementsByTagName( 'head' )[ 0 ].appendChild( script ); } ) ();
{{documentation}}
<!-- Categories go on the /doc subpage and interwikis go on Wikidata. -->
</noinclude>
/* 这里的任何JavaScript将在全站加载
* 请尊重萌娘百科版权,以下代码复制需要注明原自萌娘百科,并且附上URL地址http://zh.moegirl.org/MediaWiki:Common.js
* 版权协定:知识共享 署名-非商业性使用-相同方式共享 3.0
* loader模块 写法参见 https://www.mediawiki.org/wiki/ResourceLoader/Modules#mw.loader.load
*/
(function($, mw) { //使用匿名函数防止污染顶级变量
/* 函数定义体 */
//滚动公告
function AutoScroll(obj) {
$(obj).slideDown().find("ul:first").animate({
marginTop: "-25px"
}, 500, function() {
$(this).css({
marginTop: "0px"
}).find("li:first").appendTo(this);
});
}
//Extension:MultimediaViewer的半透明化修改,用于保持背景文字处于原位,本应修改插件达成的,暂时先用JavaScript应急处理下
function multimediaViewer() {
$('a.image img[srcset][data-file-width][data-file-height], .mw-mmv-filepage-buttons a.mw-mmv-view-expanded').on('click', function() {
if ($(this).closest('.TabLabelText')[0] || $(this).closest('a').closest('.mw-customtoggle')[0]) return;
var scrollTop = document.body.scrollTop;
$('html, body').add(document).on('scroll.multimediaViewer', function() {
//console.debug(document.body.scrollTop, scrollTop); //检测锚点
window.setTimeout(function() {
document.body.scrollTop = scrollTop;
}, 0);
}).scroll();
});
window.setInterval(function() {
if ($('.mw-mmv-close')[0]) {
if (mw.config.get('wgMultimediaViewer') !== 'on') {
mw.config.set('wgMultimediaViewer', 'on');
$('.mw-mmv-image img').off().on('click', function() {
window.open($(this).attr('src'), '_blank').focus();
return false;
});
$('.mw-mmv-image').off().on('click', function(e) {
if ($(e.target).is('img')) return false;
else if ($(e.target).closest('.error-box')[0]) return;
else $('.mw-mmv-close').click();
});
}
} else if (mw.config.get('wgMultimediaViewer') === 'on' && !$('.mw-mmv-close')[0]) $('html, body').add(document).off('scroll.multimediaViewer');
}, 137);
}
//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');
// A 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).children('.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>').children('.TabLabel'),
tabContent = self.append('<div class="TabContent"></div>').children('.TabContent'),
labelPadding = data.labelPadding,
labelColor = data.labelColor,
styleSheet = {
label: new StyleSheet(),
text: new StyleSheet()
},
defaultTab = parseInt(data.defaultTab);
self.children('.Tab').each(function() {
$(this).children('.TabLabelText').appendTo(tabLabel);
$(this).children('.TabContentText').appendTo(self.children('.TabContent'));
$(this).remove();
});
if (isNaN(defaultTab) || defaultTab <= 0 || defaultTab > tabLabel.children('.TabLabelText').length) defaultTab = 1;
tabLabel.children('.TabLabelText').on('click', function() {
var label = $(this);
label.addClass('selected').siblings().removeClass('selected').css({
'border-color': '#aaa',
'background-color': 'inherit'
});
tabContent.children('.TabContentText').eq(tabLabel.children('.TabLabelText').index(label)).addClass('selected').siblings().removeClass('selected').removeAttr('style');
if (styleSheet.label.getOwnPropertyNamesLength()) label.css(styleSheet.label);
if (label.is(':visible')) tabLabel.height(label.height() + parseFloat(label.css('padding-top')) + parseFloat(label.css('padding-bottom')) + 2);
else tabLabel.removeAttr('style');
}).eq(defaultTab - 1).click();
if (labelPadding) tabLabel.children('.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');
});
}
//子页面页顶链接
function subpage_links() {
var links = mw.config.get('wgPageName').split('/'),
link = '',
subpages = $('.subpages')[0] ? $('.subpages').remove().empty().text('<') : $('<span class="subpages"/>').text('<'),
length = links.length - 1,
index;
if (mw.config.get('wgPageName').indexOf('Special:移动页面') != -1) links.splice(0, 1);
for (index = 0; index < length; index++) {
link += '/' + links[index];
subpages.append($('<a/>', {
text: ' ' + links[index],
href: link
}));
if (length - index > 1) subpages.append(" |");
}
if (subpages.find('a')[0]) $('#contentSub').prepend(subpages);
}
//重复文件列表函数
function duplicatedFileList() {
if (window.location.href.indexOf("title") == -1) window.location.replace("http://zh.moegirl.org/index.php?title=Special:ListDuplicatedFiles&limit=500&offset=0");
$('#mw-content-text .mw-spcontent ol').attr("id", "picOl");
$('#picOl').before('<p id="picOlTitle">图片列表:</p>').after('<p id="MP3OlTitle">MP3列表:</p><ol start="1" id="MP3Ol"></ol>');
$("#picOlTitle, #MP3OlTitle").hide();
$("#picOl").find("[href$='.mp3'], [href$='.ogg']").parent().appendTo("#MP3Ol");
if ($("#picOl").find("li").length) $("#picOlTitle").show();
if ($("#MP3Ol").find("li").length) $("#MP3OlTitle").show();
$(".mw-spcontent > p:nth-child(1), .mw-spcontent > p:nth-child(2), .mw-spcontent > p:nth-child(7)").hide();
}
//复制修改内容
function copyRights() {
var div = $('<div>', {
css: {
position: 'absolute',
left: '-99999px',
'z-index': '-99999'
},
html: '<pre></pre><br>阅读更多:' + (/%/.test(mw.util.wikiUrlencode(mw.config.get('wgPageName'))) ? mw.config.get('wgPageName') + '(https://zh.moegirl.org/' + encodeURIComponent(mw.config.get('wgPageName')) + ')' : 'https://zh.moegirl.org/' + mw.config.get('wgPageName')) + '<br>本文引自萌娘百科(https://zh.moegirl.org/),文字内容遵守【知识共享 署名-非商业性使用-相同方式共享 3.0】协议。'
}).appendTo('body'),
valueNode = div.find('pre');
$(document.body).on('copy', function() {
var selection = window.getSelection(),
value = selection.toString(),
range = selection.getRangeAt(0);
if (!value.length || value.length < 128 //当复制内容为空或长度小于定值时不添加声明
|| $(selection.anchorNode).add(selection.basenode).add(selection.focusNode).closest('.Wikiplus-InterBox')[0]) //如果选中了wikiplus的内容
return;
valueNode.text(value);
selection.selectAllChildren(div[0]);
window.setTimeout(function() { //以下将还原选区
selection.removeAllRanges();
selection.addRange(range);
valueNode.empty();
}, 0);
});
}
//编辑请求
function editRequest() {
var nsIds = mw.config.get('wgNamespaceIds'),
nsId = mw.config.get('wgNamespaceNumber'),
ns = [];
for (var i in nsIds) {
if (nsIds[i] == nsId) ns.push(i);
}
if (!ns[0]) return;
var user = mw.config.get('wgUserName'),
usergroup = mw.config.get('wgUserGroups'),
page = mw.config.get('wgPageName');
for (var j = 0, l = ns.length; j < l; j++) {
if (/^[A-Za-z0-9]+[ _]talk$/i.test(ns[j])) return;
if (/^[a-zA-Z0-9]+$/.test(ns[j])) var talkns = ns[j] + '_talk:';
page = page.replace(new RegExp('^' + ns[j] + ':', 'i'), '');
}
var talkpage = talkns + page;
if (!$('.permissions-errors')) return;
var container = $('<div/>', {
class: 'editRequest'
});
container.append('您虽然无权编辑本页面,但您可以点击右侧按钮在本页的讨论页提出编辑请求,让可以编辑的人代为编辑:');
$('<span/>').addClass("newComment").text('提出编辑请求').on('click', function() {
window.open('https://zh.moegirl.org/index.php?action=edit&preload=Template:编辑请求/comment&preloadtitle=编辑请求 - ' + mw.config.get("wgUserName") + '§ion=new&title=' + talkpage, '_blank');
}).appendTo(container);
$('#mw-content-text').children('.wikiEditor-ui:first, textarea[readonly]:first').before('<hr>').before(container);
}
/* 函数执行体 */
$(function() {
//Template:heimu在safari上的暴力workaround
if (!/chrome/i.test(navigator.userAgent) && /safari/i.test(navigator.userAgent)) $('.heimu').on('click', function() {
$(this).toggleClass('off');
});
var copyRightsNameSpaces = [ // 以下为允许添加版权声明的名字空间列表
0, // (主)
4, // 萌娘百科
8, // MediaWiki
10, // Template
12, // Help
614 // R18
];
//滚动公告
setInterval(function() {
AutoScroll("#scrollDiv");
}, 5000);
//Extension:MultimediaViewer的半透明化修改
if ($('img[srcset][data-file-width][data-file-height]')[0]) multimediaViewer();
// Add "mainpage" class to the body element
if (mw.config.get('wgMainPageTitle') === mw.config.get('wgPageName') && mw.config.get('wgAction') === 'view') $('body').addClass('mainpage');
//重复文件列表区分图片和音频
if ($(".mw-special-ListDuplicatedFiles").length && $('.mw-spcontent > p').length > 1) duplicatedFileList();
//需要时载入对应的 scripts
if (mw.config.get('wgAction') == "edit" || mw.config.get('wgAction') == "submit" || mw.config.get('wgCanonicalSpecialPageName') == 'Search')
mw.loader.load('/index.php?title=MediaWiki:Common.js/edit.js&action=raw&ctype=text/javascript');
// Tabs执行
if ($('.Tabs')[0]) tabs();
//子页面页顶链接
if (mw.config.get('wgPageName').indexOf('/') != -1 && (mw.config.get('wgNamespaceIds').special != mw.config.get('wgNamespaceNumber') || mw.config.get('wgPageName').indexOf('Special:移动页面') != -1) && !window._unsubpage)
subpage_links();
//复制内容版权声明
if (window.getSelection && mw.config.get('wgUserGroups').indexOf('sysop') + mw.config.get('wgUserGroups').indexOf('patroller') == -2 && ['edit', 'submit'].indexOf(mw.config.get('wgAction')) === -1 && copyRightsNameSpaces.indexOf(mw.config.get('wgNamespaceNumber')) !== -1)
copyRights();
//编辑请求
if (['edit', 'submit'].indexOf(mw.config.get('wgAction')) !== -1 && !mw.config.get('wgIsProbablyEditable') && mw.config.get('wgUserName')) editRequest();
//修复代码编辑器$.ucFirst引用错误
jQuery.extend({
ucFirst: function(s) {
s += '';
return s.charAt(0).toUpperCase() + s.substring(1);
}
});
//注释内列表
$('.reference-text > ul,.reference-text > ol').each(function() {
if (this.parentElement.childNodes[0] === this) $(this).addClass('listInRef');
});
//修正hash跳转错误
if ($('.mw-collapsible')[0]) mw.loader.using('jquery.makeCollapsible').then(function() {
$('.mw-collapsible').makeCollapsible();
var hash = location.hash;
location.hash = '';
location.hash = hash;
});
//以下代码必须在全部内容加载完成后才能正常工作
$(window).on('load', function() {
//语言对应
$('.mw-helplink').each(function() {
var linkHref = this.href;
if (linkHref.indexOf('/zh') != linkHref.length - 3) this.href += '/zh';
});
});
});
})(jQuery, mediaWiki); //立即执行匿名函数并传递原始变量以防止冲突
//</nowiki>