Advertisement
IskarVela

SWC Droid Bookmarklet (Minified)

Feb 9th, 2018
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Chart(){this.map=new Array(20);for(var e=0;e<this.map.length;e++){this.map[e]=new Array(20);for(var t=0;t<this.map[e].length;t++)this.map[e][t]=0}this.contacts=new Array,this.galpos={x:-1,y:-1}}function getXMLVal(e,t){return e.getElementsByTagName(t)[0].childNodes[0]?e.getElementsByTagName(t)[0].childNodes[0].nodeValue:0}function Contact(e){this.name=getXMLVal(e,"name"),this.typename=getXMLVal(e,"typeName"),this.hull=getXMLVal(e,"hull"),this.hullMax=getXMLVal(e,"hullMax"),this.shield=getXMLVal(e,"shield"),this.shieldMax=getXMLVal(e,"shieldMax"),this.ionic=getXMLVal(e,"ionic"),this.ionicMax=getXMLVal(e,"ionicMax"),this.underCons="Yes"==getXMLVal(e,"underConstruction"),this.sharingSens="Yes"==getXMLVal(e,"sharingSensors"),this.x=getXMLVal(e,"x"),this.y=getXMLVal(e,"y"),this.travelDir=getXMLVal(e,"travelDirection"),this.owner=getXMLVal(e,"ownerName"),this.iff=getXMLVal(e,"iffStatus"),this.id=getXMLVal(e,"entityID")}function parseChart(){var e=new Chart,t=document.getElementsByClassName("cockpitContent")[0].innerHTML,l=t.slice(t.indexOf("Galactic Position: "),t.indexOf("<br>"));e.galpos.x=parseInt(l.slice(l.indexOf("(")+1,l.indexOf(","))),e.galpos.y=parseInt(l.slice(l.indexOf(",")+1,l.indexOf(")")));for(var a=document.getElementById("mapMoveable").getElementsByClassName("sensorSemiTrans"),n=0;n<a.length;n++){var r=parseInt(a[n].style.width),i=parseInt(a[n].style.top);if(20==r){var s=parseInt(a[n].style.left)/20,o=i/20;e.map[s][o]=1}else for(var c=r/20,d=parseInt(a[n].style.left),p=0;p<c;p++){s=(20*p+d)/20,o=i/20;e.map[s][o]=1}}var h=new XMLHttpRequest;h.open("GET","/members/scanners/list.php?cockpit&xml",!1),h.send();var y=h.responseXML.getElementsByTagName("item");for(n=0;n<y.length;n++){var g=new Contact(y[n]);e.contacts.push(g)}return e}function addMenuButton(e,t,l){var a=document.createElement("BUTTON");a.style.border="1px solid black",a.style.borderRadius="5px",a.style.margin="0 auto",a.style.backgroundColor="black",a.style.color="white",a.style.width="150px",a.style.display="inline",a.innerHTML=t,a.onclick=l,e.appendChild(a)}function viewChart(e){document.documentElement.getBoundingClientRect();var t=document.createElement("DIV");t.style.position="fixed",t.style.zIndex=150,t.style.left="200px",t.style.top="200px",t.style.width="900px",t.style.height="450px",t.style.backgroundColor="white",t.style.color="black",t.style.border="1px solid black",t.style.whiteSpace="nowrap";var l=document.createElement("DIV");l.style.left="0px",l.style.marginTop="25px",l.style.width="200px",l.style.height="400px",l.style.display="inline-block",l.style.paddingLeft="15px",l.style.float="left",addMenuButton(l,"Wipe memory",function(){deleteChart(),console.log("Memory wipe complete.")}),t.appendChild(l);var a=document.createElement("CANVAS");t.appendChild(a),a.width=400,a.height=400,a.style.marginTop="25px",a.style.border="1px solid black",a.style.display="inline-block";var n=document.createElement("DIV");t.appendChild(n),n.style.right="0px",n.style.marginTop="25px",n.style.width="275px",n.style.height="400px",n.style.border="1px solid black",n.style.display="inline-block",n.style.overflow="scroll";var r=document.createElement("DIV");r.style.position="fixed",r.style.zIndex=151,r.style.border="1px solid black",r.style.backgroundColor="darkgrey",r.style.color="black",r.style.left="0",r.style.top="0",r.innerHTML="0, 0",r.style.display="none";var i=document.createElement("DIV");n.appendChild(i),i.style.right="0px",i.style.marginTop="0px",i.style.width="100px",i.style.backgroundColor="black",i.style.color="white",i.style.display="block",i.style.fontFamily="Lucida Grande,Lucida Sans,Lucida Sans Unicode,sans-serif",i.innerHTML="DATA<br />",t.appendChild(r),document.body.appendChild(t);var s=a.getBoundingClientRect().left,o=a.getBoundingClientRect().top;a.addEventListener("mousemove",function(e){r.style.display="block",r.style.left=e.clientX+15+"px",r.style.top=e.clientY+15+"px";var t=parseInt((e.clientX-s)/20),l=parseInt((e.clientY-o)/20);r.innerHTML=t+", "+l}),a.addEventListener("mouseout",function(e){r.style.display="none"}),a.addEventListener("click",function(t){var l=parseInt((t.clientX-s)/20),a=parseInt((t.clientY-o)/20);if(l>=0&&l<=19&&a>=0&&a<=19){var r="<b>Galactic Position ("+e.galpos.x+", "+e.galpos.y+")</b><br /><b><u>Square ("+l+", "+a+")</u></b>";0==e.map[l][a]?r+=" &lt;UNSCANNED&gt;":2==e.map[l][a]&&(r+=" &lt;NOT CURRENT&gt;"),r+="<hr /><br />";for(var c=0;c<e.contacts.length;c++){r+="<div style = 'margin-left: 5px'>";var d=e.contacts[c];d.x==l&&d.y==a&&(r+="<u>"+d.name+"</u><br /><i>"+d.typename+"</i><br /><br />Hull: "+d.hull+"/"+d.hullMax+"<br />Shields: "+d.shield+"/"+d.shieldMax+"<br />Ionic: "+d.ionic+"/"+d.ionicMax+"<br />Owner: "+d.owner+"<br />IFF: "+d.iff+"<br />Direction: "+d.travelDir+"<br /><br />"),r+="</div>"}n.innerHTML="",n.appendChild(i),n.innerHTML+=r}});var c=a.getContext("2d");c.fillStyle="black",c.fillRect(0,0,400,400);for(var d=e.map,p=e.contacts,h=0;h<d.length;h++)for(var y=0;y<d[h].length;y++)1==d[h][y]?(c.fillStyle="white",c.fillRect(20*h,20*y,20,20)):2==d[h][y]&&(c.fillStyle="grey",c.fillRect(20*h,20*y,20,20)),c.strokeStyle="green",c.strokeRect(20*h,20*y,20,20);for(h=0;h<p.length;h++)c.fillStyle="purple","Friend"==p[h].iff?c.fillStyle="green":"Enemy"==p[h].iff&&(c.fillStyle="red"),c.beginPath(),c.arc(20*p[h].x+10,20*p[h].y+10,5,0,2*Math.PI),c.fill(),c.closePath()}function chTransfer(e,t){if(e.galpos.x!=t.galpos.x||e.galpos.y!=t.galpos.y){var l=saveChart(loadChart());return console.log("New Galactic Position detected! Please manually save scan data of ("+e.galpos.x+", "+e.galpos.y+"). Outputting string now."),console.log(l),deleteChart(),t=parseChart()}for(var a=0;a<e.map.length;a++)for(var n=0;n<e.map[a].length;n++)1==e.map[a][n]?0==t.map[a][n]&&(t.map[a][n]=2):2==e.map[a][n]&&0==t.map[a][n]&&(t.map[a][n]=2);var r=new Array;for(a=0;a<t.contacts.length;a++)for(n=0;n<e.contacts.length;n++)t.contacts[n].id==e.contacts[n].id&&r.push(e.contacts[n].id);for(a=0;a<e.contacts.length;a++){var i=!1;for(n=0;n<r.length;n++)if(e.contacts[a].id==r[n]){i=!0;break}i||t.contacts.push(e.contacts[a])}return t}function saveChart(e){for(var t=JSON.stringify(e),l="",a=0;a<t.length;a++)'"'==t[a]?l+="~":l+=t[a];return localStorage.setItem("SWCdroiddat",l),l}function loadChart(){var e=localStorage.getItem("SWCdroiddat");if(e){for(var t="",l=0;l<e.length;l++)"~"==e[l]?t+='"':t+=e[l];return JSON.parse(t)}return!1}function deleteChart(){localStorage.removeItem("SWCdroiddat")}if("http://www.swcombine.com/members/cockpit/"==window.location.href&&document.getElementById("mapOverlay")){var oldch=loadChart();if(oldch){var newch=parseChart();saveChart(chart=chTransfer(oldch,newch)),viewChart(chart)}else{var chart;saveChart(chart=parseChart()),viewChart(chart)}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement