-
-
Save anonymous/54c1512306d285558ea26a38ff2510aa 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 New Userscript | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description try to take over the world! | |
// @author You | |
// @include http://tagpro-*.koalabeast.com:* | |
// @grant none | |
// ==/UserScript== | |
tagpro.ready(function() { | |
let whichServer = 'pi'; //case insensitive | |
let thresholdPlayerCount = 4; //greater than or equal to | |
let checkEvery = 5000; //5 seconds | |
//////////////////////// | |
let serverHost = "tagpro-"+whichServer.toLowerCase()+".koalabeast.com"; | |
if(serverHost===tagpro.serverHost) return console.warn('Already on '+whichServer.charAt(0).toUpperCase()+whichServer.slice(1)); | |
let gameCount = -1; | |
let playerCount = -1; | |
var socket = window.io.connect("ws://"+serverHost+":80", {transports: ["websocket"]}); | |
let interval = setInterval(function() { | |
socket.emit('stats',{},function(data) { //data.games, data.players, data.playerCapacity | |
if(data.players>=thresholdPlayerCount) { | |
gameCount = data.games; | |
playerCount = data.players; | |
location.replace('http://'+serverHost+'/games/find'); | |
} | |
}); | |
}, checkEvery); | |
window.onbeforeunload = function(e) { | |
if(tagpro.state===1) { | |
clearInterval(interval); | |
socket.disconnect(); | |
return playerCount+" players in "+gameCount+" different games were found on "+whichServer.charAt(0).toUpperCase()+whichServer.slice(1)+". Leave to play a game on that server?"; //this won't show | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment