Jump to content

User:Lwarrenwiki/hamiltrash.js

From Wikipedia, the free encyclopedia
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.
// <pre><nowiki>
// hamiltrash.js
// --------------------------------
// Lwarrenwiki's change log:
// 2018-05-01 copied from User:Kbh3rd/whackamole.js, customized by Lwarrenwiki
// --------------------------------
// Original header:
// Put some functions in the toolbox for the anti-vandal whack-a-mole game.
// Documented at http://en.wikipedia.org/wiki/User:Kbh3rd/Vandal_warning_toolbox
//
// ****************
//  Google Lookup 
// ****************
//
function whackGoogleLookup() {
	var q = "" + (window.getSelection ? window.getSelection() :
		document.getSelection ? document.getSelection() :
		document.selection.createRange()
		.text);
	if (!q)
		q = prompt("You didn't select any text.  Enter a search phrase:", "");
	if (q !== null)
		// location="http://www.google.com/search?q=" + escape(q).replace(/ /g, "+");
		window.open("http://www.google.com/search?q=" + escape(q)
			.replace(/ /g, "+"), 'new-tab');
}

// **************
// Month section
// **************

function whackMonth() {
	var d = new Date();
	var f = document.editform;

	var month = new Array(12);
	month[0] = "January";
	month[1] = "February";
	month[2] = "March";
	month[3] = "April";
	month[4] = "May";
	month[5] = "June";
	month[6] = "July";
	month[7] = "August";
	month[8] = "September";
	month[9] = "October";
	month[10] = "November";
	month[11] = "December";

	f.wpTextbox1.value += "\n== " + month[d.getMonth()] + " " + d.getFullYear() + " ==\n\n";
	f.wpSummary.value = month[d.getMonth()];
	f.wpMinoredit.checked = true;
	f.wpWatchthis.checked = false;
	if (f.wpTextbox1.scrollTop || true)
		f.wpTextbox1.scrollTop = f.wpTextbox1.scrollHeight;
}

// **
// Check for month when making an edit
// **

function whackCheckMonth() {

	var d = new Date();
	var f = document.editform;

	var month = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September",
		"October", "November", "December");
	var myregexstr = new String('== *' + month[d.getMonth()] + " " + d.getFullYear() + ' *==');
	var myregex = new RegExp(myregexstr);
	if (myregex.test(f.wpTextbox1.value) !== true) {
		f.wpTextbox1.value += "\n== " + month[d.getMonth()] + " " + d.getFullYear() + " ==\n";
		f.wpSummary.value = month[d.getMonth()];
		if (f.wpTextbox1.scrollTop || true)
			f.wpTextbox1.scrollTop = f.wpTextbox1.scrollHeight;
	}
}

// **************
// Warnings
// **************

function whackEdit(message, msg2, summary, level) {
	var f = document.editform;
	var tbox = document.editform.wpTextbox1;
	var a = "" + (window.getSelection ? window.getSelection() :
		document.getSelection ? document.getSelection() :
		document.selection.createRange()
		.text);
	if (msg2 !== "") {
		a = prompt("Article name?  (Cancel to abort; OK w/empty field for a generic message.)", a);
		if (a === null) return;
		a = a.replace(/^\s+/, '');
		a = a.replace(/\.?\s*$/, '');

		if (a !== null && a !== "") {
			message = message.replace(/\|/, "|" + a);
			summary += " in [[" + a + "]]";
		}
		else {
			message = msg2;
		}
	}
	whackCheckMonth();
	f.wpTextbox1.value += "\n" + message + "<br clear=\"both\" />\n";
	f.wpSummary.value = summary;
	if (level > 0 && level <= 4) {
		f.wpSummary.value += ". Warning level: Uw-" + level + ".";
	}
	if (document.getElementById('wpMinoredit')) f.wpMinoredit.checked = false;
	f.wpWatchthis.checked = false;
	f.wpTextbox1.focus();
	if (f.wpTextbox1.scrollTop || true) f.wpTextbox1.scrollTop = f.wpTextbox1.scrollHeight;
}

// **************
// Little whack functions
// **************

function whackHamiltrash(x) {
	whackEdit("{{subst:Uw-vandalism" + x + "|}} ~~~~", "{{subst:Uw-vandalism" + x + "}} ~~~~",
		"[[List of fandom nicknames#Hamiltrash|Hamiltrash]] pattern of vandalism – user warning by [[:User:Lwarrenwiki/hamiltrash.js|script]]; rv edit",
		x);
}

function whackVandal(x) {
	whackEdit("{{subst:Uw-vandalism" + x + "|}} ~~~~", "{{subst:Uw-vandalism" + x + "}} ~~~~",
		"Vandalism – user warning by [[:User:Lwarrenwiki/hamiltrash.js|script]]; rv edit", x);
}

function whackUnsourced(x) {
	whackEdit("{{subst:Uw-unsourced" + x + "|}} ~~~~", "{{subst:Uw-unsourced" + x + "}} ~~~~",
		"Needs [[WP:RS|reliable sources]] – user warning by [[:User:Lwarrenwiki/hamiltrash.js|script]]; rv edit", x);
}

function whackMeatwarn(x) {
	whackEdit("{{subst:Uw-meatwarn" + "|}} ~~~~", "{{subst:Uw-meatwarn" + "}} ~~~~",
		"Suspected [[WP:MEAT|meatpuppetry]] – user warning by [[:User:Lwarrenwiki/hamiltrash.js|script]]; rv edit", 0);
}

function whackNPOV(x) {
	whackEdit("{{subst:Uw-npov" + x + "|}} ~~~~", "{{subst:Uw-npov" + x + "}} ~~~~",
		"[[WP:NPOV|NPOV]] – user warning by [[:User:Lwarrenwiki/hamiltrash.js|script]]; rv edit", x);
}

function whackNOR(x) {
	whackEdit("{{subst:Uw-nor" + x + "|}} ~~~~", "{{subst:Uw-nor" + x + "}} ~~~~",
		"[[WP:NOR|Original research issues]] – user warning by [[:User:Lwarrenwiki/hamiltrash.js|script]]; rv edit", x);
}

function whackCopyvio(x) {
	whackEdit("{{subst:Uw-copyright|}} ~~~~", "{{subst:Uw-copyright}} ~~~~",
		"[[WP:COPYVIO|Copyright violation]]  – user warning by [[:User:Lwarrenwiki/hamiltrash.js|script]]; rv edit", 0);
}

function whackSeparator(x) {
	whack_addlilink(document.getElementById('p-tb').getElementsByTagName('ul')[0], -1, "",
		"——————————", 0, 0);
}

//
// Unused functions commented out by Lwarrenwiki
/*
function whackWarn(x) {
	whackEdit("{{subst:Uw-test" + x + "|}} ~~~~", "{{subst:Uw-test" + x + "}} ~~~~", "Experimenting", x);
}

function whackSelf(x) {
	whackEdit("{{subst:Uw-selfrevert|}} ~~~~", "{{subst:Uw-selfrevert}} ~~~~", "Self-reverted test", 0);
}

function whackBlank(x) {
	whackEdit("{{subst:Uw-delete" + x + "|}} ~~~~", "{{subst:Uw-delete" + x + "}} ~~~~",
		"Blanking – reverted; added user warning by [[:User:Lwarrenwiki/Hamiltrash.js|script]]", x);
}

function whackErrors(x) {
	whackEdit("{{subst:Uw-error" + x + "|}} ~~~~", "{{subst:Uw-error" + x + "}} ~~~~", "Introducing errors", x);
}

function whackBLP(x) {
	whackEdit("{{subst:Uw-biog" + x + "|}} ~~~~", "{{subst:Uw-biog" + x + "}} ~~~~",
		"[[WP:BLP|Living persons issues]]", x);
}

function whackSpam(x) {
	whackEdit("{{subst:Uw-spam" + x + "|}} ~~~~", "{{subst:Uw-spam" + x + "}} ~~~~", "Spamming", x);
}

function whackAds(x) {
	whackEdit("{{subst:Uw-ad" + x + "|}} ~~~~", "{{subst:Uw-ad" + x + "}} ~~~~", "Advertising", x);
}

function whackHoax(x) {
	whackEdit("{{subst:Uw-hoax|}} ~~~~", "{{subst:Uw-hoax}} ~~~~", "Hoax", 0);
}

function whackBlatant(x) {
	whackEdit("{{subst:Uw-bv|}} ~~~~", "{{subst:Uw-bv}} ~~~~", "Blatant vandalism", 0);
}

function whackBlocked(x) {
	whackEdit("{{subst:Uw-block" + x + "|sig=~~~~}}", "", "** BLOCKED **", x);
}

function whackBlocked2() {
	whackEdit("[[Image:Modern_clock_chris_kemps_01.png|left|32px]]" +
		"You have been temporarily [[Wikipedia:Blocking policy|blocked from editing]] because of your disruptive edits." +
		" You are [[Wikipedia:Contributing to Wikipedia|invited to contribute]]" +
		" in a [[Wikipedia:Five pillars|constructive manner]] as soon as the block expires.", "", "Blocked");
}
*/

// **************************************************
// Installation
// **************************************************

window.whack_addlilink = function (tabs, n, url, name, id, title, key) {
	var na;
	var ix;
	var li = document.createElement('li');
	if (n == -1) {
		li.appendChild(document.createTextNode(name));
		tabs.appendChild(li);
	}
	else {
		if (n > 0) {
			li.appendChild(document.createTextNode(name));
			for (ix = 1; ix <= n; ix++) {
				na = document.createElement('a');
				na.href = url.replace(/XX/g, ix);
				na.appendChild(document.createTextNode(" " + ix));
				li.appendChild(na);
			}
		}
		else {
			na = document.createElement('a');
			na.href = url;
			na.appendChild(document.createTextNode(name));
			li.appendChild(na);
		}
		if (id)
			li.id = id;
		tabs.appendChild(li);
		if (id) {
			if (key && title) ta[id] = [key, title];
			else if (key) ta[id] = [key, ''];
			else if (title) ta[id] = ['', title];
		}
		// re-render the title and accesskeys from existing code in wikibits.js
		// ?? akeytt();
	}
	return li;
}

window.whack_addToolboxLink = function (n, url, name, id) {
	var tb = document.getElementById('p-tb')
		.getElementsByTagName('ul')[0];
	whack_addlilink(tb, n, url, name, id);
}

window.playWhackMoles = function () {
	if (document.title.match("Editing User talk:") || document.title.match("Creating User talk:")) {
		whack_addToolboxLink(-1, 'javascript:{whackSeparator(XX);};void(0);', '——————————', 'toolbox_sep');
		whack_addlilink(document.getElementById('p-tb')
			.getElementsByTagName('ul')[0], 0,
			"http://en.wikipedia.org/wiki/Wikipedia:Template_messages/User_talk_namespace#Multi_level_templates",
			"Warning Templates:", "uTemplates");
		//
		// Test and Self Test functions commented out by User:Kbh3rd
		/*
		whack_addToolboxLink(3, 'javascript:{whackWarn(XX);};void(0);', 'Test',' toolbox_test');
		whack_addToolboxLink(1, 'javascript:{whackSelf(XX);};void(0);', 'Self Test',' toolbox_selftest');
		*/
		whack_addToolboxLink(4, 'javascript:{whackHamiltrash(XX);};void(0);', 'Hamiltrash', 'toolbox_Hamil_vandal');
		whack_addToolboxLink(4, 'javascript:{whackVandal(XX);};void(0);', 'Vandal', 'toolbox_vandal');
		whack_addToolboxLink(4, 'javascript:{whackUnsourced(XX);};void(0);', 'Unsourced', 'toolbox_rs');
		whack_addToolboxLink(4, 'javascript:{whackNPOV(XX);};void(0);', 'NPOV', 'toolbox_npov');
		whack_addToolboxLink(4, 'javascript:{whackNOR(XX);};void(0);', 'O.R.', 'toolbox_nor');
		whack_addToolboxLink(1, 'javascript:{whackCopyvio(XX);};void(0);', 'Copyright', 'toolbox_copyvio');
		whack_addToolboxLink(0, 'javascript:{whackMeatwarn();};void(0);', 'Meatwarn', 'toolbox_meat');
		whack_addToolboxLink(0, 'javascript:{whackGoogleLookup();};void(0);', 'Google', 'toolbox_googlelookup');
		whack_addToolboxLink(-1, 'javascript:{whackSeparator(XX);};void(0);', '——————————', 'toolbox_sep');
		//
		// Other functions commented out by Lwarrenwiki
		/*
		whack_addToolboxLink(4, 'javascript:{whackBlank(XX);};void(0);', 'Blank', 'toolbox_dele');
		whack_addToolboxLink(3, 'javascript:{whackErrors(XX);};void(0);', 'Errors', 'toolbox_errors');
		whack_addToolboxLink(4, 'javascript:{whackBLP(XX);};void(0);', 'BLP', 'toolbox_blp');
		whack_addToolboxLink(4, 'javascript:{whackSpam(XX);};void(0);', 'Spam', 'toolbox_spam');
		whack_addToolboxLink(4, 'javascript:{whackAds(XX);};void(0);', 'Ads', 'toolbox_ads');
		whack_addToolboxLink(1, 'javascript:{whackBlatant(XX);};void(0);', 'Blatant', 'toolbox_blatant');
		whack_addToolboxLink(3, 'javascript:{whackBlocked(XX);};void(0);', 'BLOCK', 'toolbox_block');
		*/
	}
	else {
		whack_addToolboxLink(-1, 'javascript:{whackSeparator(XX);};void(0);', '——————————', 'toolbox_sep');
		whack_addToolboxLink(0, 'javascript:{whackGoogleLookup();};void(0);', 'Google', 'toolbox_googlelookup');
	}
}

// onload
window.simpleAddOnload = function (f) {
	if (window.addEventListener) window.addEventListener("load", f, false);
	else if (window.attachEvent) window.attachEvent("onload", f);
}

simpleAddOnload(playWhackMoles);

// </nowiki></pre>