Skip to content

Instantly share code, notes, and snippets.

@poossee-slawyah
Created May 19, 2015 20:31
Show Gist options
  • Save poossee-slawyah/238145cd7ab134e34987 to your computer and use it in GitHub Desktop.
Save poossee-slawyah/238145cd7ab134e34987 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name TF2Center Scrub Detector
// @namespace tf2csd
// @description Very simple and robust script to notify you about scrubs on TF2Center.
// @include /^http(|s):\/\/tf2center\.com\/lobbies\/[0-9]+$/
// @version 0.14.1
// @grant GM_xmlhttpRequest
// ==/UserScript==
var conjectural_scrubs = document.getElementById("lobbyPanel").getElementsByClassName("filled"),
actual_scrubs;
function detect_scrubs() {
for(var i = 0; i < conjectural_scrubs.length; i++) {
for(var j = 0; j < actual_scrubs.length; j++) {
if(conjectural_scrubs[i].getElementsByTagName("a")[0].getAttribute("href").substr(9) == actual_scrubs[j]) {
var scrub_notification = document.createElement("span");
scrub_notification.setAttribute("class", "darkgrey");
scrub_notification.setAttribute("style", "color: #d4d4d4");
scrub_notification.textContent = "SCRUB!";
var scrub_details = conjectural_scrubs[i].getElementsByClassName("statsContainer")[0];
if(!conjectural_scrubs[i].textContent.match(/SCRUB!/)) scrub_details.insertBefore(scrub_notification, scrub_details.firstChild);
}
}
}
}
GM_xmlhttpRequest({
method: "GET",
url: "http://raw.githubusercontent.com/Yttrium-tYcLief/ScrubDetector/master/scrublist",
onload: function(response) {
actual_scrubs = response.responseText.split("\n");
setInterval(detect_scrubs, 2500);
},
onerror: function(response) {
Notification.requestPermission();
if(Notification.permission === "granted") new Notification(response.status + " " + response.statusText, { body: "I failed to load scrublist, sorry." });
else alert("I failed to load scrublist, sorry. Maybe this can help: " + response.status + " " + response.statusText);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment