Jump to content

User:Frietjes/CAT.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Frietjes (talk | contribs) at 17:39, 28 May 2012. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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.
if(wgNamespaceNumber != -1) addOnloadHook(CATscriptButton)
function CATscriptButton() {
  addPortletLink('p-tb','javascript:catscriptfunction()','Add categories','t-catit');
}

function catscriptfunction()
{
  var myContent = document.getElementById('wpTextbox1').value;

  // add noinclude section if it's not there
  if( myContent.search(/<noinclude>/g) < 0 ) {
    myContent = myContent + '<noinclude>\n</noinclude>';
  }
  if( myContent.search(/\[\[Category/gi) < 0 ) {
    myContent = myContent.replace(/(<noinclude>)/, '$1\n[[Category:]]');
  }

  if(document.getElementById('wpTextbox1').value != myContent) {
    document.getElementById('wpTextbox1').value = myContent;
    document.getElementById('wpSummary').value  = 'add categories';
  }
}