跳转到内容

User:Chaplin/log.js

维基百科,自由的百科全书
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google ChromeFirefoxMicrosoft EdgeSafari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
// Toolbar Log link by Tietew@jawiki
// This script is under public domain, and comes with ABSOLUTELY NO WARRANTY.
// You can use/modify/redistribute without any permission.
// Localize by Alexsh@zhwiki

function addlogtab()
{
  // get title from URL
  var u = wgPageName;
  
  // insertion point of toolbox
  var lit = document.getElementById('t-recentchangeslinked');
  if(!lit) lit = document.getElementById('t-whatlinkshere');
  // if not found, we're in special page
  if(!lit) return;
  
  // insertion point of actions tab
  var act = document.getElementById('p-cactions');
  act = act.getElementsByTagName('ul')[0];
  
  // get namespace number
  var ns = wgNamespaceNumber;
  if(typeof ns != 'number') return;
  
  // purge cache
  a = document.createElement('a');
  a.appendChild(document.createTextNode(wgULS('清除缓存','清除快取')));
  a.setAttribute('href', '/wiki/' + u + '?action=purge');
  a.setAttribute('title', decodeURI(u));
  li = document.createElement('li');
  li.appendChild(a);
  lit.parentNode.insertBefore(li, lit.nextSibling);
  
  // User: or User_talk:
  if(ns == 2 || ns == 3) {
    // strip subpage
    var user = decodeURI(u).replace(/^[^:]+:/, '').replace(/\/.*/, '');
    // User's log
    a = document.createElement('a');
    a.appendChild(document.createTextNode(wgULS('用户日志','用戶日誌')));
    a.setAttribute('href', '/wiki/Special:Log?user=' + encodeURI(user));
    a.setAttribute('title', 'User:' + user + "'s log");
    li = document.createElement('li');
    li.appendChild(a);
    lit.parentNode.insertBefore(li, lit.nextSibling);
    // IP address
    var m = /^\d+\.\d+\.\d+\.\d+$/.exec(user);
    if(m) {
      a = document.createElement('a');
      a.appendChild(document.createTextNode('whois'));
      a.setAttribute('href', 'http://linky.wikipedia.jp/whois?key=' + encodeURI(user));
      a.setAttribute('title', 'whois query for ' + user);
      li = document.createElement('li');
      li.appendChild(a);
      act.appendChild(li);
    }
  }

  // Page log
  a = document.createElement('a');
  a.appendChild(document.createTextNode(wgULS('页面日志','頁面日誌')));
  a.setAttribute('href', '/wiki/Special:Log?page=' + u);
  a.setAttribute('title', decodeURI(u));
  li = document.createElement('li');
  li.appendChild(a);
  lit.parentNode.insertBefore(li, lit.nextSibling);
  
  // Image: or Image_talk:
  if((ns == 6 || ns == 7) && location.host != 'commons.wikimedia.org') {
    // link to commons
    a = document.createElement('a');
    a.appendChild(document.createTextNode(wgULS('原始图档','原始圖檔')));
    a.setAttribute('href', 'http://commons.wikimedia.org/wiki/' + wgPageName);
    a.setAttribute('title', 'commons:' + decodeURI(wgPageName));
    li = document.createElement('li');
    li.appendChild(a);
    act.appendChild(li);
  }
}
$(addlogtab);