User:Awesome Aasim/Wikibreakenforcer.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | This user script seems to have a documentation page at User:Awesome Aasim/Wikibreakenforcer. |
/* 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=\"/media/wikipedia/en/thumb/1/1d/Information_icon4.svg/40px-Information_icon4.svg.png\" srcset=\"/media/wikipedia/en/thumb/1/1d/Information_icon4.svg/60px-Information_icon4.svg.png 1.5x, /media/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=\"/media/wikipedia/en/thumb/1/1d/Information_icon4.svg/40px-Information_icon4.svg.png\" srcset=\"/media/wikipedia/en/thumb/1/1d/Information_icon4.svg/60px-Information_icon4.svg.png 1.5x, /media/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=\"/media/wikipedia/en/thumb/1/1d/Information_icon4.svg/40px-Information_icon4.svg.png\" srcset=\"/media/wikipedia/en/thumb/1/1d/Information_icon4.svg/60px-Information_icon4.svg.png 1.5x, /media/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 */