Skip to content

Instantly share code, notes, and snippets.

@bash-tp
Last active May 20, 2019 03:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bash-tp/65272c9889a3a966ec28fe4455ab67ab to your computer and use it in GitHub Desktop.
Save bash-tp/65272c9889a3a966ec28fe4455ab67ab to your computer and use it in GitHub Desktop.
TagPro Wins Until Next Degree
// ==UserScript==
// @name TagPro Wins Until Next Degree
// @namespace http://www.reddit.com/user/bash_tp/
// @description Displays wins needed until next degree on game screen
// @include *://*.koalabeast.com*
// @include *://*.jukejuice.com*
// @include *://*.newcompte.fr*
// @grant GM_xmlhttpRequest
// @connect koalabeast.com
// @connect jukejuice.com
// @connect newcompte.fr
// @license GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html
// @author bash# (original by ben, modified by ballparts)
// @version 1.3
// @updateURL https://gist.github.com/bash-tp/65272c9889a3a966ec28fe4455ab67ab/raw/tagpro_wins_until_next_degree.user.js
// @downloadURL https://gist.github.com/bash-tp/65272c9889a3a966ec28fe4455ab67ab/raw/tagpro_wins_until_next_degree.user.js
// ==/UserScript==
tagpro.ready(function() {
if (tagpro.renderer === undefined) {
return;
}
var base = window.location.protocol + "//" + window.location.hostname;
var stop = false;
var sprite;
var deg;
var wins;
var update = function() {
if (stop) {
return;
}
if (!sprite) {
sprite = new PIXI.Text(
'',
{
fontSize: "8pt",
strokeThickness: 3,
fill: "#ffffff",
fontWeight: "bold",
}
);
sprite.x = 10;
sprite.y = 30;
tagpro.renderer.layers.ui.addChild(sprite);
}
sprite.text = deg + ", Next degree in " + wins + " win" + (wins > 1 ? "s" : "");
};
GM_xmlhttpRequest({
method: "GET",
url: base,
onload: function(response) {
var obj = $.parseHTML(response.responseText);
var url = $(obj).find('a[href^="/profile"]').attr("href");
if (url !== undefined) {
GM_xmlhttpRequest({
method: "GET",
url: base + url,
onload: function(response) {
var obj = $.parseHTML(response.responseText);
var profile = $(obj).find("div.profile-detail").find("td");
deg = profile.eq(5).html().trim();
wins = profile.eq(7).html().trim();
if (wins == "next win") {
wins = 1;
} else if (wins !== undefined) {
wins = parseInt(wins.substring(3));
}
if (deg !== undefined && wins !== undefined && !isNaN(wins)) {
update();
tagpro.socket.on("chat", function(e) {
if (e.from === null &&
e.message.startsWith(tagpro.players[tagpro.playerId].name + " has reached")) {
sprite.text = "Congrats!";
stop = true;
}
});
tagpro.socket.on("end", function(e) {
var team = tagpro.players[tagpro.playerId].team;
if ((e.winner == "red" && team == 1) || (e.winner == "blue" && team == 2)) {
wins--;
if (wins > 0) {
update();
}
}
});
}
}
});
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment