「MediaWiki:Common.js」の版間の差分

提供:saveMLAK
ナビゲーションに移動 検索に移動
(fix obsolete addOnloadHook. cf. https://www.mediawiki.org/wiki/ResourceLoader/Migration_guide_(users)#addOnloadHook)
 
(他の1人の利用者による、間の2版が非表示)
14行目: 14行目:
 
   if(/[\?&]uselang=([^&]+)/.test(l)) l = RegExp.$1;
 
   if(/[\?&]uselang=([^&]+)/.test(l)) l = RegExp.$1;
 
   // else if(/\/wiki\/([^\?]+)/.test(l)) l = RegExp.$1;
 
   // else if(/\/wiki\/([^\?]+)/.test(l)) l = RegExp.$1;
   else return;
+
   else l = "ja";
 
   
 
   
 
   // insertion point of toolbox
 
   // insertion point of toolbox
38行目: 38行目:
 
   if(l == "en") {
 
   if(l == "en") {
 
     a.appendChild(document.createTextNode('Purge cache'));
 
     a.appendChild(document.createTextNode('Purge cache'));
 +
    a.setAttribute('href', '/wiki/' + u + '?lang=en&uselang=en&action=purge');
 
   } else {
 
   } else {
 
     a.appendChild(document.createTextNode('最新の情報に更新'));
 
     a.appendChild(document.createTextNode('最新の情報に更新'));
 +
    a.setAttribute('href', '/wiki/' + u + '?action=purge');
 
   }
 
   }
  a.setAttribute('href', '/wiki/' + u + '?action=purge');
 
 
   a.setAttribute('title', decodeURI(u));
 
   a.setAttribute('title', decodeURI(u));
 
   li = document.createElement('li');
 
   li = document.createElement('li');
48行目: 49行目:
 
}
 
}
  
addOnloadHook(purgelink);
+
$( function () {
 +
  purgelink();
 +
} );

2018年10月7日 (日) 17:54時点における最新版

/* ここにあるすべてのJavaScriptは、すべてのページ読み込みですべての利用者に対して読み込まれます */

// add Purge link
function purgelink()
{
  // get title from URL
  var u = location.href;
  if(/[\?&]title=([^&]+)/.test(u)) u = RegExp.$1;
  else if(/\/wiki\/([^\?]+)/.test(u)) u = RegExp.$1;
  else return;

  // get lang info from URL
  var l = location.href;
  if(/[\?&]uselang=([^&]+)/.test(l)) l = RegExp.$1;
  // else if(/\/wiki\/([^\?]+)/.test(l)) l = RegExp.$1;
  else l = "ja";
 
  // 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 = document.body.className.split(' ');
  for(var i = 0; i < ns.length; ++i) {
    var r = /^ns-([0-9]+)$/.exec(ns[i]);
    if(r) { ns = parseInt(r[1]); break; }
  }
  if(typeof ns != 'number') return;
 
  // purge cache
  a = document.createElement('a');
  if(l == "en") {
    a.appendChild(document.createTextNode('Purge cache'));
    a.setAttribute('href', '/wiki/' + u + '?lang=en&uselang=en&action=purge');
  } else {
    a.appendChild(document.createTextNode('最新の情報に更新'));
    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);
}

$( function () {
  purgelink();
} );