Skip to content

Instantly share code, notes, and snippets.

@wallyballs-wl
Last active Nov 10, 2017
Embed
What would you like to do?
Make Warlight Great Again
// ==UserScript==
// @name Make Warlight Great Again
// @namespace Wally Balls
// @description Makes Warlight Great Again.
// @include https://www.warlight.net/*
// @version 1.0
// @grant none
// ==/UserScript==
/*Define players block.
To change player names, see the instructions below.
As many players as you like are allowed (i.e. there isn't a limit).
Player names ARE case-sensitive.
If you decide to remove a player's name, replace the name with na or remove the entry.*/
var na = null; //<- don't edit this line!
/* Player names. Separate players using commas, like below, but without the // */
var Players = [
"DanWL", // violating federal laws
// copy the line above and add more trolls here
];
/*Thread exceptions. Separate players using commas, like below, but without the //*/
var threads = [
//"thread1",
//"thread 2",
//"Thread 3",
];
//DON'T MODIFY ANYTHING BEYOND THIS POINT!
var PlayersNo = 0,
threadsNo = 0;
//validate function
function validate(str) {
//set string to lower case
return str.toLowerCase()
//removes - or _ characters
.replace(/[-_]+/g, '')
//removes any non alphanumeric characters
.replace(/[^\w\s]/g, '')
//removes numbers
.replace(/[0-9]/g, '')
//removes spaces
.replace(/ /g, '' );
}
//prevent bugs
try {
document.getElementsByTagName("ins")[0].remove();
}
catch(err) {}
//main
try{
var h = location.pathname,
genF = h.includes("m/f1") || h.includes("m/F1"),
mapF = h.includes("m/f4") || h.includes("m/F4"),
ladF = h.includes("m/f5") || h.includes("m/F5"),
progF = h.includes("m/f6") || h.includes("m/F6"),
helpF = h.includes("m/f7") || h.includes("m/F7"),
OTF = h.includes("m/f8") || h.includes("m/F8"),
clansF = h.includes("m/f9") || h.includes("m/F9"),
stratF = h.includes("m/f10") || h.includes("m/F10"),
subForum = genF || mapF || ladF || progF || helpF || OTF || clansF || stratF,
allF = h.includes("m/fo") || h.includes("m/Fo"),
threadP = h.includes("m/1") || h.includes("m/2") || h.includes("m/3") || h.includes("m/4") || h.includes("m/5") || h.includes("m/6") || h.includes("m/7") || h.includes("m/8") || h.includes("m/9"),
mail = h.includes("/Discussion/MyMail"),
clanF = h.includes("/Clans/forum") || h.includes("/Clans/Forum"),
sHT = document.createElement("button"),
hT = document.createElement("button"),
td1 = document.createElement("td"),
li1 = document.createElement("li"),
li0 = document.createElement("li"),
ddM = document.getElementsByClassName("dropdown-menu")[0],
li1S = li1.style,
sHTS = sHT.style,
hTS = hT.style,
a = document.getElementsByTagName("a"),
aNo = "",
f = document.getElementsByTagName("font"),
fNo = 0,
d = document.getElementsByTagName("tr"),
dNo = "",
dh = "detail_hidden",
dhCN = document.getElementsByClassName(dh),
ds = "detail_shown",
dsCN = document.getElementsByClassName(ds),
dg = "detail_good",
db = "detail_blank",
dbCN = document.getElementsByClassName(db),
n = "none",
y = "table-row",
Apr1 = new Date();
//show who's threads are getting hidden
li0.className = "dropdown-divider";
li1.innerHTML = "Make Warlight Great Again";
li1.onclick = function() {userScriptConfig();};
li1S.color = "#555";
li1S.paddingTop = "3px";
li1S.paddingRight = "15px";
li1S.paddingBottom = "3px";
li1S.paddingLeft = "15px";
li1S.cursor = "pointer";
li1.onmouseover = function() {li1.style.backgroundColor = "#08C"; li1.style.color = "#fff";};
li1.onmouseleave = function() {li1.style.backgroundColor = "inherit"; li1.style.color = "#555";};
if (ddM !== undefined) {
ddM.appendChild(li0);
ddM.appendChild(li1);
}
//Players array to another array where Players[PlayersNo] is a single var
//And Player string array (for hidden players)
//alert(Players);
var p = [],
ps = "",
pNo = 0;
pS = [],
psS = "",
pSNo = 0;
function PlayersToPThenPs() {
while (PlayersNo < Players.length) {
ps = Players[PlayersNo];
p.push(ps);
PlayersNo++;
}
pNo = 0;
PlayersNo = 0;
while (pNo < p.length) {
psS = "\n" + p[pNo];
pS.push(psS);
pNo++;
}
pNo = 0;
}
PlayersToPThenPs();
function fixPAndPsBug() {
//fixes bug that causes p and pS to not reset when Player changes are made
for (var i=Players.length-1; i>=0; i--) {
p.splice(i, 1);
pS.splice(i, 1);
}
}
//check forum type
function checkF() {
if (subForum || allF) {
dNo = 4;
}
else {
dNo = 3;
}
if (mail || clanF || allF) {
aNo = 20;
}
else {
aNo = 21;
}
//alert(dNo + " " + aNo);
}
if (subForum || allF || clanF || mail) {
var TBL = document.getElementsByTagName("table")[document.getElementsByTagName("table").length - 1];
//make hide threads function
function hideThreads() {
//hide all-caps
checkF();
while (dNo + 1 < d.length) {
if (a[aNo].href.match(/"?Offset="/gi) === null) {
if (Apr1.getDate() === 1 && Apr1.getMonth() === 3) {
a[aNo].innerHTML = "Happy April Fools!";
if (mail === false) {
var afh = a[aNo].href.split("/");
var afh1 = afh[4].split("-");
a[aNo].href = afh[0] + "//" + afh[2] + "/" + afh[3] + "/" + afh1[0] + "-happy-april-fools";
}
}
if (a[aNo].innerHTML.match(/[A-Z]/g) != na || a[aNo].innerHTML.match(/^\d+$/) != na) {
if (a[aNo].innerHTML.match(/[A-Z]/g) != na) {
if (a[aNo].innerHTML.match(/[A-Z]/g).length > a[aNo].innerHTML.length - 1 === true) {
d[dNo].className = dh;
d[dNo].style.display = n;
d[dNo].style.textDecoration = "line-through";
a[aNo].title = "This thread has an all-caps subject";
//alert(dNo + " " + aNo + a[aNo].innerHTML + " all-caps");
}
if (a[aNo].innerHTML.match(/^\d+$/) != na) {
d[dNo].className = "";
d[dNo].style = "";
a[aNo].title = "";
//alert(dNo + " " + aNo + a[aNo].innerHTML + " is a number");
}
}
}
}
//turns blanked-out subjects to [blank subject] so that subject becomes visible
if (a[aNo].innerHTML.match(/\uA0/gi) || a[aNo].innerHTML.match(/\uAD/gi) || a[aNo].innerHTML.match(/\u2DE/gi) || a[aNo].innerHTML.match(/\u00AD/gi) || a[aNo].innerHTML.match(/\u02DE/gi) || a[aNo].innerHTML.match(/\u1361/gi) || a[aNo].innerHTML.match(/\u1680/gi) || a[aNo].innerHTML.match(/\u180E/gi) || a[aNo].innerHTML.match(/\u2000/gi) || a[aNo].innerHTML.match(/\u2001/gi) || a[aNo].innerHTML.match(/\u2002/gi) || a[aNo].innerHTML.match(/\u2003/gi) || a[aNo].innerHTML.match(/\u2004/gi) || a[aNo].innerHTML.match(/\u2005/gi) || a[aNo].innerHTML.match(/\u2006/gi) || a[aNo].innerHTML.match(/\u2007/gi) || a[aNo].innerHTML.match(/\u2008/gi) || a[aNo].innerHTML.match(/\u2009/gi) || a[aNo].innerHTML.match(/\u200A/gi) || a[aNo].innerHTML.match(/\u200B/gi) || a[aNo].innerHTML.match(/\u202F/gi) || a[aNo].innerHTML.match(/\u205F/gi) || a[aNo].innerHTML.match(/\u2800/gi) || a[aNo].innerHTML.match(/\u3000/gi) || a[aNo].innerHTML.match(/\u3164/gi) || a[aNo].innerHTML.match(/\uFEFF/gi)) {
a[aNo].innerHTML = "[blank subject]";
}
//alert(dNo + " " + aNo + a[aNo].innerHTML + "isn't all-caps and all-numbers");
aNo++;
dNo++;
}
//hide threads
checkF();
fNo = 0;
while (fNo < f.length) {
//alert(a[aNo].innerHTML + f[fNo].innerHTML);
pNo = 0;
while (pNo < p.length) {
//alert(f[fNo].innerHTML + ".includes(" + p[pNo] + ") == " + f[fNo].innerHTML.includes(p[pNo]));
if (f[fNo].innerHTML.match(/\uA0/gi) || f[fNo].innerHTML.match(/\uAD/gi) || f[fNo].innerHTML.match(/\u2DE/gi) || f[fNo].innerHTML.match(/\u00AD/gi) || f[fNo].innerHTML.match(/\u02DE/gi) || f[fNo].innerHTML.match(/\u1361/gi) || f[fNo].innerHTML.match(/\u1680/gi) || f[fNo].innerHTML.match(/\u180E/gi) || f[fNo].innerHTML.match(/\u2000/gi) || f[fNo].innerHTML.match(/\u2001/gi) || f[fNo].innerHTML.match(/\u2002/gi) || f[fNo].innerHTML.match(/\u2003/gi) || f[fNo].innerHTML.match(/\u2004/gi) || f[fNo].innerHTML.match(/\u2005/gi) || f[fNo].innerHTML.match(/\u2006/gi) || f[fNo].innerHTML.match(/\u2007/gi) || f[fNo].innerHTML.match(/\u2008/gi) || f[fNo].innerHTML.match(/\u2009/gi) || f[fNo].innerHTML.match(/\u200A/gi) || f[fNo].innerHTML.match(/\u200B/gi) || f[fNo].innerHTML.match(/\u202F/gi) || f[fNo].innerHTML.match(/\u205F/gi) || f[fNo].innerHTML.match(/\u2800/gi) || f[fNo].innerHTML.match(/\u3000/gi) || f[fNo].innerHTML.match(/\u3164/gi) || f[fNo].innerHTML.match(/\uFEFF/gi)) {
//turns blanked-out names to [blank name] so that player's name becomes visible and then hides threads by that player
f[fNo].innerHTML = "by [blank name]";
Players.push(f[fNo].innerHTML.replace("by ", ""));
fixPAndPsBug();
PlayersToPThenPs();
//alert(pS.length);
}
if (f[fNo].innerHTML.includes(p[pNo])) {
d[dNo].className = dh;
d[dNo].style.display = n;
d[dNo].style.textDecoration = "line-through";
//alert(a[aNo].innerHTML + f[fNo].innerHTML + " hidden");
}
pNo++;
}
fNo++;
dNo++;
aNo++;
}
fNo = 0;
//thread exceptions
//threads array to another array where threads[threadsNo] is a single var
//alert(threads);
var t = [],
ts = "",
tNo = 0;
while (threadsNo < threads.length) {
ts = threads[threadsNo];
t.push(ts);
threadsNo++;
}
threadsNo = 0;
checkF();
while (dNo + 1 < d.length) {
tNo = 0;
//alert("tNo = "+ tNo);
while (tNo < t.length) {
//alert("dNo = " + dNo + "\na[aNo].innerHTML = " + a[aNo].innerHTML);
//alert(a[aNo].innerHTML + ".includes(" + t[tNo] + ") == " + a[aNo].innerHTML.includes(t[tNo]));
if (a[aNo].innerHTML.includes(t[tNo])) {
d[dNo].className = "detail_good";
d[dNo].style.textDecoration = "";
a[aNo].title = "This thread is NOT being hidden";
d[dNo].style.display = y;
//alert(aNo + a[aNo].innerHTML + " not hidden");
}
tNo++;
}
aNo++;
dNo++;
}
hTS.display = n;
if (dhCN.length > 1) {
sHT.innerHTML = "Show " + dhCN.length + " hidden threads";
sHTS.display = "block";
}
else if (dhCN.length === 1) {
sHT.innerHTML = "Show 1 hidden thread";
sHTS.display = "block";
}
else {
sHTS.display = n;
}
}
//make show hidden threads function
function showHiddenThreads() {
var dhNo = 0;
if (dhCN !== undefined) {
while (dhNo < dhCN.length) {
dhCN[dhNo].className = ds;
dhNo + 1;
}
}
var dsNo = 0;
if (dsCN !== undefined) {
while (dsNo < dsCN.length) {
dsCN[dsNo].style.display = y;
dsNo++;
}
}
sHTS.display = n;
if (dsCN.length > 1) {
hT.innerHTML = "Hide " + dsCN.length + " threads";
hTS.display = "block";
}
else if (dsCN.length === 1) {
hT.innerHTML = "Hide 1 thread";
hTS.display = "block";
}
else {
hTS.display = n;
}
//dhNo = 0;
//dsNo = 0;
}
//hide threads straight away
hideThreads();
}
else if (threadP || location.href.includes("https://www.warlight.net/Discussion/?ID=")) {
if (Apr1.getDate() === 1 && Apr1.getMonth() === 3) {
document.title = "Happy April Fools! - Play Risk Online Free - WarLight";
fNo = 0;
while (fNo < f.length) {
if (f[fNo].parentNode == "[object HTMLTableCellElement]" && f[fNo].innerHTML != "WarLight Creator") {
f[fNo].innerHTML = "Happy April Fools!";
}
fNo++;
}
}
fNo = 0;
//make hide replies function
function hideReplies() {
var psttbls = [],
psttbl = "",
psttblNo = 0,
players = [],
player = "",
playerNo = 0;
aNo = 20;
while (aNo < a.length - 18) {
if (a[aNo].href.includes("warlight.net/Profile?p=") && a[aNo].parentNode == "[object HTMLTableCellElement]") {
psttbl = a[aNo].parentNode.parentNode.parentNode.parentNode;
psttbls.push(psttbl);
//turns blanked-out names to [blank name] so that players link becomes visible and then hide replies by that player
if (a[aNo].innerHTML.match(/\uA0/gi) || a[aNo].innerHTML.match(/\uAD/gi) || a[aNo].innerHTML.match(/\u2DE/gi) || a[aNo].innerHTML.match(/\u00AD/gi) || a[aNo].innerHTML.match(/\u02DE/gi) || a[aNo].innerHTML.match(/\u1361/gi) || a[aNo].innerHTML.match(/\u1680/gi) || a[aNo].innerHTML.match(/\u180E/gi) || a[aNo].innerHTML.match(/\u2000/gi) || a[aNo].innerHTML.match(/\u2001/gi) || a[aNo].innerHTML.match(/\u2002/gi) || a[aNo].innerHTML.match(/\u2003/gi) || a[aNo].innerHTML.match(/\u2004/gi) || a[aNo].innerHTML.match(/\u2005/gi) || a[aNo].innerHTML.match(/\u2006/gi) || a[aNo].innerHTML.match(/\u2007/gi) || a[aNo].innerHTML.match(/\u2008/gi) || a[aNo].innerHTML.match(/\u2009/gi) || a[aNo].innerHTML.match(/\u200A/gi) || a[aNo].innerHTML.match(/\u200B/gi) || a[aNo].innerHTML.match(/\u202F/gi) || a[aNo].innerHTML.match(/\u205F/gi) || a[aNo].innerHTML.match(/\u2800/gi) || a[aNo].innerHTML.match(/\u3000/gi) || a[aNo].innerHTML.match(/\u3164/gi) || a[aNo].innerHTML.match(/\uFEFF/gi)) {
a[aNo].innerHTML = "[blank name]";
Players.push(a[aNo].innerHTML.replace("by ", ""));
fixPAndPsBug();
PlayersToPThenPs();
}
player = a[aNo].innerHTML;
players.push(player);
}
aNo++;
}
playerNo = 0;
psttblNo = 0;
while (playerNo < players.length) {
pNo = 0;
//alert(players);
while (pNo < p.length) {
if (players[playerNo].includes(p[pNo])) {
psttbls[psttblNo].className = dh;
psttbls[psttblNo].style.display = n;
}
pNo++;
}
playerNo++;
psttblNo++;
}
hTS.display = n;
if (dhCN.length > 1) {
sHT.innerHTML = "Show " + dhCN.length + " hidden replies";
sHTS.display = "block";
}
else if (dhCN.length === 1) {
sHT.innerHTML = "Show 1 hidden reply";
sHTS.display = "block";
}
else {
sHTS.display = n;
}
}
//link rels
aNo = 21;
while (aNo < a.length - 18) {
if (a[aNo].href.includes("warlight.net/wiki")) {
a[aNo].rel = "help";
}
aNo++;
}
//hide replies straight away
hideReplies();
}
}
//deals with errors
catch(err){
var msg = prompt("An error occurred while loading Dan's Userscript.\nTo fix this, update your browser. If that doesn't work, message Dan these details:\n", err.message),
trb = document.getElementsByClassName("TopRightBar")[0].childNodes[1];
msg;
if (msg !== null) {
var Window = window.open("https://www.warlight.net/Discussion/SendMail?PlayerID=222685","_blank","left=0,top=0,menubar=no,status=no,channelmode=yes,fullscreen=yes,toolbar=no,width="+screen.width+",height="+screen.height,""),
subject = "Userscript Error",
message = "Platform: " + navigator.platform + ". User agent: " + navigator.userAgent + ". Error: " + msg + ". Error on page: " + location + ". Found by: " + trb.childNodes[5].innerHTML + " - " + trb.childNodes[5].href + ".";
Window.focus();
try{Window.document.getElementsByTagName("ins")[0].remove();}
catch(err) {}
setTimeout('if (Window.document.getElementById("SubjectBox") != na) {Window.document.getElementById("SubjectBox").value = subject;} if (Window.document.getElementById("TextArea_0") != na) {Window.document.getElementById("TextArea_0").value = message;}',3000);
}
}
//remove extra Muli's Userscript menu - a script causes this bug to happen
setTimeout('if (document.getElementsByClassName("userscript-menu")[0] !== null) {if (document.getElementsByClassName("userscript-menu")[1] !== null) {document.getElementsByClassName("userscript-menu")[1].remove();}}',500);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment