User:Awesome Aasim/Wikibreakenforcer.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.
/* Start wikibreak enforcer: [[User:Awesome Aasim/Wikibreakenforcer]] */
function wikibreakenforcer(year, month, day) {
	var currentDate = new Date();
	var enforcedDate = new Date(year, month-1, day);
	var action = mw.config.get("wgAction");
	var un = mw.config.get("wgUserName");
	var fUN = "";
	for (var i = 0; i < un.length; i++) {
		if (un[i] == " ") {
			fUN += "_";
		} else {
			fUN += un[i];
		}
	}
	if (!(/.*common\.js.*/.test(mw.config.get("wgTitle")) && mw.config.get("wgNamespaceNumber") == 2) && !(mw.config.get("wgPageName") == "User_talk:Awesome_Aasim/Wikibreakenforcer.js") && currentDate <= enforcedDate) {
		try {document.getElementById("ca-edit").remove();} catch (Error) {}
		try {document.getElementById("ca-viewsource").remove();} catch (Error) {}
		try {document.getElementById("ca-addsection").remove();} catch (Error) {}
		switch (action) {
			case "edit": $('#wpTextbox1').attr('disabled', true);
			$('#wpSave').attr('disabled', true);
			try {document.getElementById("wikiEditor-ui-toolbar").parentNode.remove();} catch (Error) {}
			document.getElementById("mw-content-text").innerHTML = "<table class=\"plainlinks fmbox fmbox-system\" role=\"presentation\"><tbody><tr><td class=\"mbox-image\"><img width=\"40\" height=\"40\" alt=\"\" src=\"//upload.wikimedia.org/wikipedia/en/thumb/1/1d/Information_icon4.svg/40px-Information_icon4.svg.png\" srcset=\"//upload.wikimedia.org/wikipedia/en/thumb/1/1d/Information_icon4.svg/60px-Information_icon4.svg.png 1.5x, //upload.wikimedia.org/wikipedia/en/thumb/1/1d/Information_icon4.svg/80px-Information_icon4.svg.png 2x\" data-file-height=\"620\" data-file-width=\"620\" decoding=\"async\"></td><td class=\"mbox-text\">A <a href=\"/wiki/Wikipedia:Wikibreak\">wikibreak</a> is <a href=\"/wiki/User:Awesome_Aasim/Wikibreakenforcer\">enforced</a> until " + enforcedDate.toString() + ". You can end your wikibreak early by removing the wikibreak script from your <a href=\"/wiki/Special:MyPage/common.js\">common.js</a> page.</td></tr></tbody></table>" + document.getElementById("mw-content-text").innerHTML;
			break;
			case "history": try {
				var d = document.getElementsByClassName("mw-history-undo");
				for (var i = d.length-1; i >= 0; i--) {
					d[i].parentNode.parentNode.remove();
				}
				} catch (Error) {}
			break;
			case "submit": $('#wpTextbox1').attr('disabled', true);
			$('#wpSave').attr('disabled', true);
			try {document.getElementById("wikiEditor-ui-toolbar").parentNode.remove();} catch (Error) {}
			document.getElementById("mw-content-text").innerHTML = "<table class=\"plainlinks fmbox fmbox-system\" role=\"presentation\"><tbody><tr><td class=\"mbox-image\"><img width=\"40\" height=\"40\" alt=\"\" src=\"//upload.wikimedia.org/wikipedia/en/thumb/1/1d/Information_icon4.svg/40px-Information_icon4.svg.png\" srcset=\"//upload.wikimedia.org/wikipedia/en/thumb/1/1d/Information_icon4.svg/60px-Information_icon4.svg.png 1.5x, //upload.wikimedia.org/wikipedia/en/thumb/1/1d/Information_icon4.svg/80px-Information_icon4.svg.png 2x\" data-file-height=\"620\" data-file-width=\"620\" decoding=\"async\"></td><td class=\"mbox-text\">A <a href=\"/wiki/Wikipedia:Wikibreak\">wikibreak</a> is <a href=\"/wiki/User:Awesome_Aasim/Wikibreakenforcer\">enforced</a> until " + enforcedDate.toString() + ". You can end your wikibreak early by removing the wikibreak script from your <a href=\"/wiki/Special:MyPage/common.js\">common.js</a> page.</td></tr></tbody></table>" + document.getElementById("mw-content-text").innerHTML;
			break;
			case "view": 
			try {
			var d = document.getElementsByClassName("mw-diff-edit");
				for (var i = d.length-1; i >= 0; i--) {
					d[i].remove();
				}
			} catch (Error) {}
			try {
			var d = document.getElementsByClassName("mw-diff-tool");
				for (var i = d.length-1; i >= 0; i--) {
					d[i].remove();
				}
			} catch (Error) {}
			try {
			var d = document.getElementsByClassName("mw-diff-undo");
				for (var i = d.length-1; i >= 0; i--) {
					d[i].remove();
				}
			} catch (Error) {}
			try {
			var d = document.getElementsByClassName("mw-editsection");
				for (var i = d.length-1; i >= 0; i--) {
					d[i].remove();
				}
			} catch (Error) {}
			break;
		}
	} else if ((action == "edit" || action == "submit") && mw.config.get("wgPageName").includes(fUN) && mw.config.get("wgPageName").includes("common.js") && currentDate <= enforcedDate) {
		document.getElementById("mw-content-text").innerHTML = "<table class=\"plainlinks fmbox fmbox-system\" role=\"presentation\"><tbody><tr><td class=\"mbox-image\"><img width=\"40\" height=\"40\" alt=\"\" src=\"//upload.wikimedia.org/wikipedia/en/thumb/1/1d/Information_icon4.svg/40px-Information_icon4.svg.png\" srcset=\"//upload.wikimedia.org/wikipedia/en/thumb/1/1d/Information_icon4.svg/60px-Information_icon4.svg.png 1.5x, //upload.wikimedia.org/wikipedia/en/thumb/1/1d/Information_icon4.svg/80px-Information_icon4.svg.png 2x\" data-file-height=\"620\" data-file-width=\"620\" decoding=\"async\"></td><td class=\"mbox-text\">A <a href=\"/wiki/Wikipedia:Wikibreak\">wikibreak</a> is <a href=\"/wiki/User:Awesome_Aasim/Wikibreakenforcer\">enforced</a> until " + enforcedDate.toString() + ". You can end your wikibreak early by removing the wikibreak script below.</td></tr></tbody></table>" + document.getElementById("mw-content-text").innerHTML;
	}
}

$("document").ready(function() {
	wikibreakenforcer(year, month, day); //replace "year", "month", and "day" with the expiry of your wikibreak.  No leading zeros!
});
/* End enforcer */