Last active
March 21, 2017 02:00
-
-
Save Element00/39ef62014e75d03d1bd6c31a4f554111 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Generals.io FriendsList | |
// @namespace http://tampermonkey.net/ | |
// @version 0.3.0 | |
// @description try to take over the world! | |
// @author President Trump | |
// @match http://generals.io/ | |
// @match http://generals.io/profiles/* | |
// @match http://*.generals.io/profiles/* | |
// @match http://*.generals.io/ | |
// @grant none | |
// ==/UserScript== | |
var version = "0.3.0"; | |
// Add friends by adding their EXACT name in ""s. | |
var myFriends = ["President Trump", | |
"[uw] zhu☭ge liang", | |
"Spraget", | |
"KJ", | |
"☑", | |
"Norden", | |
"[uw]zhou en☭lai", | |
"point", | |
"ぱげてぃ", | |
"Wuped", | |
"PioIsPro", | |
"o_o", | |
"ERIKER", | |
"fuzzything44", | |
"0xGG", | |
"Sean", | |
"sora", | |
"Shadøw", | |
"Darth Calculus", | |
"Clearly", | |
"Firefly", | |
"DMG-Damageinc", | |
"Popey ", | |
"Or", | |
"Blazek", | |
"Rhino Cock", | |
"啊雷Alan Ray", | |
"poofytoo", | |
"hipp0", | |
"Sammy", | |
"DankTemplar", | |
"rhobes", | |
"Lokraan"]; | |
myFriends.sort(); | |
/*var friendsFromStorage = []; | |
friendsFromStorage = JSON.parse(localStorage.getItem("Friends")); | |
myFriends.concat(friendsFromStorage);*/ | |
console.log("Current Friends: "+myFriends); | |
var friendsOnline = []; | |
var latestGame = [], lastGame = [], last2v2stars = []; | |
var emptyArray = []; | |
var myObj, i, j, k, x, y, boolean, xmlhttp, newFriend, node; | |
var FriendsList = document.createElement("span"); | |
var txt1 = document.createTextNode("Who's online: v"+version); | |
var txt2 = document.createElement("u"); | |
txt2.appendChild(txt1); | |
txt2.style.lineHeight = "120%"; | |
FriendsList.appendChild(txt2); | |
FriendsList.id = "FriendsList"; | |
FriendsList.style.position = "fixed"; | |
FriendsList.style.overflowY = "scroll"; | |
FriendsList.style.whiteSpace = "pre-wrap"; | |
FriendsList.style.top = "50%"; | |
FriendsList.style.right = "2em"; | |
FriendsList.style.width = "3em"; | |
FriendsList.style.background = "#008080"; | |
FriendsList.style.color = "white"; | |
FriendsList.style.width = "20%"; | |
FriendsList.style.maxHeight = "40%"; | |
FriendsList.style.padding = "0.25% 0.5%"; | |
FriendsList.style.borderStyle = "solid"; | |
document.getElementsByTagName("body")[0].appendChild(FriendsList); | |
for (j = 0; j < myFriends.length; j++){ | |
y = document.createElement("a"); | |
y.innerHTML = "\n"+myFriends[j]+": Loading . . ."; | |
y.setAttribute("href","http://"+window.location.hostname+"/profiles/"+myFriends[j]+""); | |
y.setAttribute("target","_blank"); | |
FriendsList.appendChild(y);//.appendChild(x)); | |
friendsOnline[j] = false; | |
latestGame[j] = 0; | |
} | |
function round(value, decimals) { | |
return Number(Math.round(value+'e'+decimals)+'e-'+decimals); | |
} | |
var searchbox = document.createElement("input"); | |
searchbox.setAttribute("type", "text"); | |
searchbox.setAttribute("placeholder", "Type a name and click ADD"); | |
searchbox.id = "searchName"; | |
searchbox.setAttribute("maxlength", "18"); | |
searchbox.style.width = "70%"; | |
FriendsList.appendChild(searchbox); | |
var searchbutton = document.createElement("button"); | |
searchbutton.addEventListener("click", addFriend); | |
searchbutton.style.width = "26%"; | |
searchbutton.style.fontSize = "100%"; | |
searchbutton.style.height = "50%"; | |
searchbutton.innerHTML = "add"; | |
searchbutton.textAlign = "center"; | |
FriendsList.appendChild(searchbutton); | |
function addFriend(){ | |
var addName = document.getElementById('searchName').value; | |
if(addName===""){return;} | |
y = document.createElement("a"); | |
y.innerHTML = "\n"+addName+": Loading . ."; | |
y.setAttribute("href","http://"+window.location.hostname+"/profiles/"+addName); | |
y.setAttribute("target","_blank"); | |
FriendsList.insertBefore(y,FriendsList.childNodes[FriendsList.childNodes.length - 2]); | |
console.log("Added "+addName+" to the list."); | |
myFriends.push(addName); | |
myFriends.sort(); | |
localStorage.setItem("Friends", JSON.stringify(myFriends)); | |
} | |
var friendsList = document.getElementById("FriendsList"); | |
function checkOnline(name, num){ | |
if (window.XMLHttpRequest) { | |
xmlhttp = new XMLHttpRequest(); | |
} else { | |
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); | |
} | |
xmlhttp.onreadystatechange = function () { | |
if (this.readyState == 4 && this.status == 200) { | |
myObj = JSON.parse(this.responseText); | |
now = new Date(); | |
if(myObj == emptyArray){ | |
friendsOnline[num] = false; | |
latestGame[num] = null; | |
return; | |
} | |
last2v2stars = []; | |
latestGame[num] = now.valueOf() - myObj[0].started; | |
if(latestGame[num] == (now.valueOf() - 1483557570911)) latestGame[num] = null; | |
lastGame[num] = ((myObj[0].type=="classic"&&myObj[0].ranking.length>2)?"FFA":myObj[0].type); | |
if(((latestGame[num]) < 600000) && latestGame[num] !== null){ | |
friendsOnline[num] = true; | |
}else{ | |
friendsOnline[num] = false; | |
} | |
} | |
}; | |
xmlhttp.open("GET", "http://"+window.location.hostname+"/api/replaysForUsername?u="+name+"&offset=0&count=1", true); | |
xmlhttp.send(); | |
} | |
setInterval(function(){ | |
for(i = 0; i < myFriends.length; i++){ | |
checkOnline(myFriends[i], i); | |
node = friendsList.childNodes[i+1]; | |
if(friendsOnline[i]){ | |
node.textContent = "\n"+myFriends[i]+": ONLINE - playing: "+lastGame[i]; | |
node.style.fontWeight = "bold"; | |
node.style.color = "#00FF00"; | |
console.log(myFriends[i]+" is online - latest game: "+lastGame[i]); | |
}else{ | |
if(latestGame[i]===null){ | |
node.textContent = "\n"+myFriends[i]+": ERROR: not found"; | |
node.style.color = "#ffc656"; | |
continue; | |
} | |
time = round((latestGame[i]/(1000*60*60)),2); | |
node.textContent = time===0?"\n"+myFriends[i]+": Loading . . .":("\n"+myFriends[i]+": offline for "+(time<24?time+" hrs.":round(time/24,2)+" days")); | |
node.style.fontWeight = "normal"; | |
node.style.color = (time<1&&time!==0?"#bfffbf":"white"); | |
node.setAttribute("href","http://"+window.location.hostname+"/profiles/"+myFriends[i]); | |
console.log(myFriends[i]+" is offline"); | |
} | |
} | |
}, 5000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment