User:Zhangjintao/interwiki.js
外观
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google Chrome、Firefox、Microsoft Edge及Safari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
$(function ($) {
var translate = {
'en': {
removeinterwikis: "Remove interwikis",
summary: "Removed $2 sitelink(s) migrated to [[d:$1|an item]] on [[WP:WDATA|Wikidata]]"
},
'zh': {
removeinterwikis: "移除跨语言链接",
summary: "移动 $2 跨语言链接[[d:$1|an item]]到[[WP:WDATA|维基数据]]"
},
}
var namespace = mw.config.get('wgNamespaceNumber'),
lang = mw.config.get('wgPageContentLanguage'),
m = translate[ lang ] || translate.en,
page = namespace === 0 ? mw.config.get('wgTitle') : mw.config.get('wgFormattedNamespaces')[ namespace ] + ':' + mw.config.get('wgTitle').replace(/\/doc$|\/Dokumentácia$|\/Dokumentacija$/, ''),
editbox = document.getElementById( "wpTextbox1" );
function removeInterwikis() {
document.body.style.cursor = "wait";
$.ajax({
url: '//www.wikidata.org/w/api.php',
data: {
'format': 'json',
'action': 'wbgetentities',
'sites': mw.config.get('wgDBname'),
'titles': page,
'props': 'sitelinks',
'languages': lang
},
dataType: 'jsonp',
success: function (data) {
if (data.success) {
for (var i in data.entities) {
if ( i != -1 ) {
var item = data.entities[i] && data.entities[i].sitelinks, numberremoved = 0;
if ( item ) {
for ( var ii in item ) {
var interw = "[[" + item[ ii ].site.split("wiki")[0].replace(/_/g,"-") + ":" + item[ ii ].title + "]]";
editbox.value !== (editbox.value = editbox.value.replace( interw + "\n", "" ).replace( interw, "" )) && numberremoved++;
}
}
var editsum = document.getElementById("wpSummary");
editsum && (editsum.value += ( m.summary || '' ).replace(/\$1/g, i.toUpperCase()).replace(/\$2/g, numberremoved));
}
}
}
document.body.style.cursor = "";
}
});
}
editbox && $( mw.util.addPortletLink( 'p-cactions', '#', m.removeinterwikis ) ).on( "click", removeInterwikis);
});