Skip to content

Instantly share code, notes, and snippets.

@arfie
Created October 27, 2015 17:34
Show Gist options
  • Save arfie/f335bf1b328ed79f93e3 to your computer and use it in GitHub Desktop.
Save arfie/f335bf1b328ed79f93e3 to your computer and use it in GitHub Desktop.
TagPro AFK warning
// ==UserScript==
// @name TagPro AFK warning
// @namespace http://www.arfie.nl
// @version 0.1
// @author Ruud Verbeek
// @include http://tagpro-*.koalabeast.com:*
// @include http://tangent.jukejuice.com:*
// NewCompte's servers don't have an AFK timeout
// ==/UserScript==
var a = function() {
var keys = ['left', 'right', 'up', 'down', 'space'],
afkTime = 30,
showWarning = 10; // Seconds before kick to show the warning
var afkWarning = new PIXI.Text("Warning: you'll get kicked for being AFK too long soon.\nPress space to prevent.");
afkWarning.style.fill = "red";
afkWarning.style.strokeThickness = 4;
afkWarning.style.align = "center";
afkWarning.style.font = "bold 12pt Arial";
afkWarning.alpha = 0;
tagpro.renderer.layers.ui.addChild(afkWarning);
var timeout = -1,
warning = function() {
afkWarning.x = (tagpro.renderer.vpWidth - afkWarning.width) / 2;
afkWarning.y = tagpro.renderer.vpHeight / 8;
afkWarning.alpha = 1;
afkWarning.updateText();
},
update = function(time) {
afkWarning.alpha = 0;
timeout >= 0 && clearTimeout(timeout);
timeout = setTimeout(warning, 1e3 * time);
};
var key = function(e) {
var kc = e.keyCode;
for(var k of keys)
if(k.indexOf(kc) >= 0)
return;
update(afkTime - showWarning);
};
$(document).keydown(key);
$(document).keyup(key);
},b=function(){tagpro?tagpro.ready(a):setTimeout(b,0);};b();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment