User:DarkArcherPrince/cattab.js

// Add category tab. By User:ais523, on a request by User:Gary King.

// (User:ais523/cattab.js)

function init(){

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 user scripts";

document.getElementById('wpPreview').click();

}

}

// disabled due to phab:T72470

// $(init)

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);

}

// Category:Wikipedia scripts