Jump to content

User:Ais523/cattab.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.
// Add category tab. By [[User:ais523]], on a request by [[User:Gary King]].
// ([[User:ais523/cattab.js]])
// <source lang="javascript">
$(function(){
  if(wgNamespaceNumber==0&&wgAction=="view")
  {
    if(document.getElementById("ca-edit"))
      mw.util.addPortletLink('p-cactions', 'javascript:cattab()', 'add cat', 'ca-cattag',
                                   'Add a category to this page', '');
  }
  if(location.href.indexOf("&autoaddcattag=")!=-1&&document.getElementById('wpTextbox1')!=null)
  {
    var x=decodeURIComponent(location.href.split("&autoaddcattag=")[1]);
    var a=document.getElementById('wpTextbox1').value.split('['+'[Category:');
    a[0]+="["+"[Category:"+x+"]]\n";
    document.getElementById('wpTextbox1').value=a.join('['+'[Category:');
    document.getElementById('wpSummary').value=
      "Tagging with ["+"[Category:"+x+"]] using [[WP:US/S|user scripts]]";
    document.getElementById('wpPreview').click();
  }
});

function cattab()
{
  var x=prompt("Which category?");
  if(x==null) return;
  location.href=mw.config.get('wgServer')+mw.config.get('wgScript')+"?title="+encodeURIComponent(mw.config.get('wgPageName'))+                                  
                "&action=edit&autoaddcattag="+encodeURIComponent(x);
}

// </source> [[Category:Wikipedia scripts]]