Jump to content

User:Legoktm/mtc.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// Adds [[Template:MTC]]]
// Created by [[User:Legoktm|Legoktm]]
// Adds a tab at the top of the page says "mtc"
if(wgNamespaceNumber == 6) {
  if(wgAction == 'edit' || wgAction == 'submit') {
    addOnloadHook(function () { mw.util.addPortletLink('p-cactions','javascript:doMtc()','mtc','ca-mtc'); });
  } else {
    var url = mw.config.get('wgServer') + mw.config.get('wgScript') + '?title=' + encodeURIComponent(mw.config.get('wgPageName')) + '&action=edit&automtc=true';
    addOnloadHook(function () { mw.util.addPortletLink('p-cactions',url,'mtc','ca-mtc'); });
  }
}
if(queryString('automtc')) addOnloadHook(function() { doMtc(); })
function doMtc() {
  var txt = document.getElementById('wpTextbox1');
  if(!txt) return;
  txt.value = '{' + '{' + 'move to commons}}\n\n' + txt.value;
  document.getElementById('wpSummary').value += ' automatically tagging {'+'{mtc}}';
  document.getElementById('wpSave').click();
}
 
function queryString(p) {
  var re = RegExp('[&?]' + p + '=([^&]*)');
  var matches;
  if (matches = re.exec(document.location)) {
    try { 
      return decodeURI(matches[1]);
    } catch (e) {
    }
  }
  return null;
}