NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name X-fighter underground interactive map // @version 0.1 // @description Adds indicator to position on the map as well as key bindings (currently AWSD) // @match http://x-fighter.pl/abyss.php* // @copyright 2014, Blid // ==/UserScript== $(function(){function a(){this.x=null;this.y=null}$.extend(a.prototype,{get:function(){var e=$(".statsy td").eq(3);this.x=parseInt(e.find("b").eq(2).text());this.y=parseInt(e.find("b").eq(1).text());return{x:this.x,y:this.y}}});function c(e){this.map={O:'<span class="yellow">O</span>',M:'<span class="red">M</span>',T:'<span class="green">T</span>',A:'<span class="cyan">C</span>'};this.input=e}c.prototype.getHTML=function(){return this.map[this.input]||this.input};function b(){this.$old=$("pre");this.$new=$('<table class="underground-map">');this.$old.hide();this.representation=[];this.parse()}$.extend(b.prototype,{parse:function(){var h=this.$old.text().trim(),g=h.split("\n"),f,e,k;for(f=2;f<g.length-1;f++){k=g[f].split("");for(e=2;e<k.length-1;e++){this.representation[f-2]=this.representation[f-2]||[];this.representation[f-2][e-2]=new c(k[e])}}},renderToString:function(){var e=new a().get(),k,h;var g="";for(k=0;k<this.representation.length;k++){var m=this.representation[k];var n="<tr>";for(h=0;h<m.length;h++){var l=this.representation[k][h].getHTML(),f="";if((k+1)==e.y&&(h+1)==e.x){f="highlight"}n+='<td class="'+f+'">'+l+"</td>"}n+="</tr>";g+=n}this.$new=this.$new.append(g);return this.$new},append:function(){this.$old.after(this.$new)}});function d(){this.base_url="http://x-fighter.pl/abyss.php";this.map={w:"GORA",a:"LEWO",s:"DOL",d:"PRAWO"};this.bindEvents()}$.extend(d.prototype,{send:function(f){var e=this.map[f];$('input[value="'+e+'"]').siblings('[type="submit"]').click()},bindEvents:function(){$("body").on("keydown",function(f){switch(f.which){case 87:this.send("w");break;case 83:this.send("s");break;case 65:this.send("a");break;case 68:this.send("d");break}}.bind(this))}});$(function(){var f=new b();new d();var e=' <style type="text/css"> .underground-map { border-spacing: 3px; border: 1px dashed gray; } .underground-map td { padding: 5px !important; text-align: center; line-height: 12px; } .underground-map .highlight { background-color: #FFCC66; border-radius: 25px; } </style> ';$("head").append(e);f.renderToString();f.append()})});