Jump to content

User:Addihockey10/global.js

From Meta, a Wikimedia project coordination wiki

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)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
//<nowiki>
// [[File:Hoo man/tagger.js‎‎]]
mw.loader.load('//meta.wikimedia.org/w/index.php?title=User:Hoo_man/tagger.js‎&action=raw&ctype=text/javascript');
// [[File:Hoo man/smart_rollback.js‎]]
mw.loader.load('//meta.wikimedia.org/w/index.php?title=User:Hoo_man/smart_rollback.js&action=raw&ctype=text/javascript');
// [[File:Hoo man/useful_links.js‎]]
mw.loader.load('//meta.wikimedia.org/w/index.php?title=User:Hoo_man/useful_links.js&action=raw&ctype=text/javascript');


/* Global JavaScript
     Function importAnyScript() by Mike.lifeguard
*/
function importAnyScript(lang,family,script) {
    //use importScriptURI with the full-qualified source, else importScript(); runs in the context of the remote wiki, finding nothing.
	mw.loader.load('http://'
		+ encodeURIComponent(lang) + '.'
		+ encodeURIComponent(family) + '.org/w/index.php?title='
		+ encodeURIComponent(script) + '&action=raw&ctype=text/javascript');
}
importAnyScript('meta','wikimedia','User:Quentinv57/HideButtonsFromNonGsProjects.js');

 
// A tool very similar to the Nuke Extension, but with more features
// by [[m:user:Hoo man]] <http://meta.wikimedia.org/wiki/User:Hoo_man/Scripts/SledgeHammer>
mw.loader.load('//meta.wikimedia.org/w/index.php?title=User:Hoo_man/sledgeHammer.js&action=raw&ctype=text/javascript');

//by m:User:Hoo man
// quick and dirty hack, not supported, is going to break SOON
// DO NOT REUSE
function fastTag(tag, editSummary) {
	//section to edit
	section = null;
	hoofr.inProcess('start', '<img src="//upload.wikimedia.org/wikipedia/commons/d/de/Ajax-loader.gif">');
	var content;
	if(mw.config.get('wgCurRevisionId') !== 0) {
		content = hoofr.getPage(mw.config.get('wgPageName'), mw.config.get('wgCurRevisionId'), section);
	}else{
		content = false;
	}
	if(content === false && mw.config.get('wgCurRevisionId') === 0) {
		alert('Error');
		return;
	}
	var create = false;
	if(content === false) {
		content = '';
		create = true;
	}
	if(!section || content === '') {
		content = tag + '\n' + content;
	}else{
		content = content.replace(/^([=]{1,6}.*[=]{1,6})/i, '$1\n' + tag);
	}
	var data, result, curRevId;
	if(create) {
		data = hoofr.getToken('edit', mw.config.get('wgPageName'), false);
		result = hoofr.editPage(mw.config.get('wgPageName'), content, editSummary, true, undefined, undefined, section);
	}else{
		data = hoofr.getToken('edit', mw.config.get('wgPageName'), true);
		if(mw.util.getParamValue('oldid') !== null) {
			curRevId = mw.util.getParamValue('oldid');
		}else{
			curRevId = mw.config.get('wgCurRevisionId');
		}
		if(mw.config.get('wgCurRevisionId') != data.revid || curRevId != data.revid) {
			alert('Error');
			return;
		}
		result = hoofr.editPage(mw.config.get('wgPageName'), content, editSummary, true, data.editToken, data.timestamp, section);
	}
	hoofr.inProcess('stop');
	if(result === true) {
		window.location.href = mw.config.get('wgServer') + mw.config.get('wgArticlePath').replace('$1', mw.config.get('wgPageName'));
	}else{
		alert('Error: ' + result);
	}
}
function initFastTaggers() {
	hoofr.addToolLink('Spam', function() { fastTag('{{delete|Spam --~~~~}}', 'Tagged for deletion : Spam') });
	hoofr.addToolLink('Vand', function() { fastTag('{{delete|Vandalism --~~~~}}', 'Tagged for deletion : Vandalism') });
        hoofr.addToolLink('Nonsense', function() { fastTag('{{delete|Nonsense --~~~~}}', 'Tagged for deletion : Nonsense') });
        hoofr.addToolLink('NAA', function() { fastTag('{{delete|Not an article --~~~~}}', 'Tagged for deletion : Not an article') }); 
        hoofr.addToolLink('NFF', function() { fastTag('{{delete|Non-free file --~~~~}}', 'Tagged for deletion : Unused non-free file') });
}
$.ajax({
	url: '//meta.wikimedia.org/w/index.php?title=User:Hoo_man/functions.js&action=raw&ctype=text/javascript',
	dataType: 'script',
	cache: true,
	success: initFastTaggers
});
//</nowiki>