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 14:53, 1 May 2017. 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.
jQuery(document).ready(function($) {

if(mw.config.get('wgNamespaceNumber') != -1) {
	mw.loader.using(['mediawiki.util']).done( function() {
		var portletlink = mw.util.addPortletLink('p-tb','#','Add categories','t-catit');
		$(portletlink).click(function(e) {
			e.preventDefault();
			catscriptfunction();
		});
	});
}
// -------------------------------------------------------------------------------- //
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';
  }
}
// -------------------------------------------------------------------------------- //
});