User:Ais523/cattab.js
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
// Add category tab. By [[User:ais523]], on a request by [[User:Gary King]].
// ([[User:ais523/cattab.js]])
// <source lang="javascript">
addOnloadHook(function(){
if(wgNamespaceNumber==0&&wgAction=="view")
{
if(document.getElementById("ca-edit"))
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=wgServer+wgScript+"?title="+encodeURIComponent(wgPageName)+
"&action=edit&autoaddcattag="+encodeURIComponent(x);
}
// </source> [[Category:Wikipedia scripts]]