Slither.io auto respawn (evergreen)

Auto respawn + Skin rotator + Unlocked zoom + No skin + No BG + Reduce lag + Server info + Tab close warn + more!

当前为 2016-06-25 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Slither.io auto respawn (evergreen)
  3. // @namespace slitherioautorespawn
  4. // @description Auto respawn + Skin rotator + Unlocked zoom + No skin + No BG + Reduce lag + Server info + Tab close warn + more!
  5. // @version 1.2
  6. // @author condoriano
  7. // @include http://slither.io/*
  8. // @include https://slither.io/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14. if(window.top != window.self) return;
  15. window.onbeforeunload = function() { return 'Quit game?'; };
  16.  
  17. var optnDiv, optnBox, popupsDiv, trDiv, extrasDiv,
  18. gameBG = null,
  19. settings = {},
  20. playBtn = document.getElementById('playh').children[0],
  21. optnKeys = [ 'z', 'x', 'c', 'v', 'b', 'n', 'm' ],
  22. optnKeysInt = [ 90, 88, 67, 86, 66, 78, 77 ],
  23. overlayOpened = false;
  24.  
  25. function init() {
  26. if(/Firefox/i.test(navigator.userAgent)) document.addEventListener("DOMMouseScroll", handleZoom, false);
  27. else document.body.onmousewheel = handleZoom;
  28.  
  29. editHTML();
  30. hookHTML();
  31. hookKeys();
  32.  
  33. var tempLoop = setInterval(function() {
  34. if(window.bgp2) {
  35. loadSettings();
  36. clearInterval(tempLoop);
  37. }
  38. }, 100);
  39. }
  40.  
  41. function editHTML() {
  42. document.body.style.backgroundColor = '#' + getRandomInt(1, 6) + getRandomInt(1, 6) + getRandomInt(1, 6);
  43. document.getElementById('nick_holder').style.backgroundColor = 'rgba(0,0,0,0.5)';
  44. [ '#tips', '#nick', '#clq', '.nsi', '.lq2' ].forEach(function(e) {
  45. var b = document.querySelectorAll(e);
  46. for(var i = 0; i < b.length; i++) b[i].style.color = '#EEE';
  47. });
  48. [ '.sadg1', '.sadu1', '.sadd1' ].forEach(function(e) {
  49. var b = document.querySelectorAll(e);
  50. for(var i = 0; i < b.length; i++) b[i].style.background = hasClass(b[i], 'sadg1') ? 'rgba(250,250,250,0.1)' : hasClass(b[i], 'sadu1') ? 'rgba(250,250,250,0.15)' : 'rgba(0,0,0,0.5)';
  51. });
  52.  
  53. optnDiv = document.createElement('div');
  54. optnDiv.id = 'optn';
  55. optnDiv.style = 'display: inline-block';
  56. optnDiv.innerHTML = '<a id="optnBtn" href="#" class="btn btnt"><img src="http://i.imgur.com/KeFKZvM.png" border="0" height="87" width="90"></a>';
  57. document.getElementById('grqh').appendChild(optnDiv);
  58.  
  59. optnBox = document.createElement('div');
  60. optnBox.id = 'optnBox';
  61. optnBox.style = 'position: absolute; top: 100px; right: 0px; width: 280px; background-color: rgba(0,0,0,0.5); color: #BBB; font-family: Tahoma; font-size: 12px; border-radius: 12px; padding: 6px 12px;';
  62. optnBox.innerHTML += '<div id="optnBox-settings" style="padding: 6px 6px 12px; border-bottom: 1px dashed #555;"></div>';
  63. optnBox.innerHTML += '<div id="optnBox-keys" style="padding: 6px 6px 12px; border-bottom: 1px dashed #555;"></div>';
  64. optnBox.innerHTML += '<div style="padding-top: 4px; font-size: 9px; text-align: right">Mod by Condoriano. <a style="text-decoration: none; color: #AF3;" href="https://greasyfork.org/en/scripts/20897-slither-io-auto-respawn-evergreen" target="_blank">Homepage</a></div>';
  65. optnDiv.appendChild(optnBox);
  66.  
  67. optnBox.children[0].innerHTML += '<span style="display: block; font-weight: bold; color: #3AF; margin-bottom: 4px; position: relative; left: -5px;">Game Settings</span>';
  68. optnBox.children[0].innerHTML += '<label><input id="optnAutoRespawn" type="checkbox">Auto respawn</label>';
  69. optnBox.children[0].innerHTML += '<label><input id="optnRotateSkin" type="checkbox">Rotate skin</label>';
  70. optnBox.children[0].innerHTML += '<label><input id="optnNoSkin" type="checkbox">No skins</label>';
  71. optnBox.children[0].innerHTML += '<label><input id="optnNoBG" type="checkbox">No background</label>';
  72.  
  73. optnBox.children[1].innerHTML += '<span style="display: block; font-weight: bold; color: #3AF; margin-bottom: 4px; position: relative; left: -5px;">Controls / Shortcut keys</span>';
  74. optnBox.children[1].innerHTML += '<span><span>Mouse or Arrow keys</span> : Move snake</span>';
  75. optnBox.children[1].innerHTML += '<span><span>W or Space</span> : Speed boost</span>';
  76. optnBox.children[1].innerHTML += '<span><span>ESC</span> : Quit to main menu</span>';
  77. optnBox.children[1].innerHTML += '<span><span>&gt;</span> : Next skin</span>';
  78. optnBox.children[1].innerHTML += '<span><span>&lt;</span> : Prev skin</span>';
  79.  
  80. popupsDiv = document.createElement('div');
  81. popupsDiv.id = 'popupsDiv';
  82. popupsDiv.style = 'position: absolute; display: flex; flex-direction: column-reverse; bottom: 10px; left: 210px; width: 260px; max-height: 200px; overflow: hidden; font-family: Tahoma; z-index: 5;';
  83. document.body.appendChild(popupsDiv);
  84.  
  85. trDiv = document.createElement('div');
  86. trDiv.id = 'topRight';
  87. trDiv.style = 'position: absolute; top: 100px; left: 5px; z-index: 100;';
  88. document.body.appendChild(trDiv);
  89.  
  90. extrasDiv = document.createElement('div');
  91. extrasDiv.id = 'extrasDiv';
  92. extrasDiv.innerHTML = '<div id="extras-ip"></div><div id="extras-location"></div><div id="extras-fps"></div>';
  93. extrasDiv.style = 'display: none; position: absolute; top: 5px; left: 5px; color: #AAA; font-family: Verdana; font-size: 12px; z-index: 5;';
  94. document.body.appendChild(extrasDiv);
  95.  
  96. var optn = document.getElementById('optnBox-settings').children;
  97. for(var i = 1; i < optn.length; i++) {
  98. optn[i].style = 'display: inline-block; min-width: 50%;';
  99. var j = document.createElement('strong');
  100. j.innerHTML = '(' + optnKeys[i-1].toUpperCase() + ')';
  101. j.style = 'display: inline-block; min-width: 18px;';
  102. optn[i].insertBefore(j, optn[i].firstChild);
  103. optn[i].children[1].style = 'margin: 0px 4px; position: relative; top: 2px';
  104. }
  105. optn = document.getElementById('optnBox-keys').children;
  106. for(var i = 1; i < optn.length; i++) {
  107. optn[i].style = 'display: inline-block; min-width: 50%; margin: 1px 0px;';
  108. optn[i].children[0].style = 'display: inline-block; background-color: #000; color: #FFF; padding: 0px 6px; border-radius: 3px; min-width: 12px; text-align: center;';
  109. }
  110. }
  111.  
  112. function hookHTML() {
  113. var checkboxes = optnBox.querySelectorAll('input[type="checkbox"]');
  114. for(var i = 0; i < checkboxes.length; i++) {
  115. (function(j) {
  116. checkboxes[j].addEventListener('change', function() {
  117. var theID = this.id;
  118. settings[theID] = this.checked;
  119. localStorage.setItem('settings', JSON.stringify(settings));
  120. createPopup(this.nextSibling.textContent + ' <span style="color: ' + (this.checked ? '#9D2;">Enabled</span>' : '#F33;">Disabled</span>'));
  121.  
  122. if(theID == 'optnNoSkin') window.render_mode = this.checked ? 1 : 2;
  123. else if(theID == 'optnNoBG') window.bgp2 = this.checked ? null : gameBG;
  124. });
  125. })(i);
  126. }
  127. document.getElementById('nick').addEventListener('change', function() { // todo: this doesnt get called if press play or enter
  128. settings[this.id] = this.value;
  129. localStorage.setItem('settings', JSON.stringify(settings));
  130. });
  131.  
  132. document.getElementById('optnBtn').addEventListener('click', function(e) {
  133. optnBox.style.display = optnBox.style.display == 'none' ? 'block' : 'none';
  134. e.preventDefault();
  135. });
  136. playBtn.addEventListener('click', function() { overlayOpened = false; document.getElementById('nick').blur(); });
  137. }
  138.  
  139. function handleZoom(e) {
  140. if(!window.playing) return;
  141. window.gsc *= Math.pow(0.9, e.wheelDelta / -120 || e.detail / 2 || 0);
  142. }
  143.  
  144. function loadSettings() {
  145. gameBG = window.bgp2;
  146. localStorage.setItem("edttsg", "1");
  147. if(localStorage.getItem('settings')) settings = JSON.parse(localStorage.getItem('settings'));
  148. var checkboxes = optnBox.querySelectorAll('input[type="checkbox"]');
  149. for(var i = 0; i < checkboxes.length; i++) { if(settings[checkboxes[i].id]) checkboxes[i].click(); }
  150. if(settings.hasOwnProperty('nick')) document.getElementById('nick').value = settings.nick;
  151. setInterval(logicLoop, 1000);
  152. }
  153.  
  154. function logicLoop() {
  155. if(document.getElementById('optnAutoRespawn').checked) { if(!overlayOpened) playBtn.click(); }
  156. if(document.getElementById('optnRotateSkin').checked) changeSkin(1, false);
  157.  
  158. if(window.playing) {
  159. extrasDiv.style.display = 'block';
  160. trDiv.style.display = 'none';
  161. document.getElementById('extras-ip').innerHTML = 'Server IP: <span style="color: #EEE;">' + window.bso.ip + ':' + window.bso.po + '</span';
  162. document.getElementById('extras-fps').innerHTML = 'FPS: <span style="color: #EEE;">' + window.fps + '</span';
  163.  
  164. if(document.getElementById('extras-location').innerHTML == '') {
  165. var httpReq = new XMLHttpRequest();
  166. httpReq.open('GET', '//geoip.nekudo.com/api/' + window.bso.ip, true);
  167. httpReq.onreadystatechange = function(data) {
  168. if(httpReq.readyState == 4 && httpReq.status == 200) {
  169. var data = JSON.parse(httpReq.responseText);
  170. document.getElementById('extras-location').innerHTML = 'Server Location: <span style="color: #EEE;">' + data.city + ', ' + data.country.name + '</span';
  171. }
  172. };
  173. httpReq.send();
  174. }
  175. }
  176. else {
  177. extrasDiv.style.display = 'none';
  178. trDiv.style.display = 'block';
  179. document.getElementById('extras-location').innerHTML = '';
  180. }
  181. }
  182.  
  183. function createPopup(msg, displayTime=1200, bgColor='rgba(0,0,0,0.7)') {
  184. var popup = document.createElement('div');
  185. popup.style = 'display: table; background-color: ' + bgColor + '; color: #DDD; margin: 2px 0px; max-width: 260px; padding: 0px 16px 2px 16px; border-radius: 30px; font-size: 12px;';
  186. popup.innerHTML = msg;
  187. popupsDiv.insertBefore(popup, popupsDiv.firstChild);
  188. setTimeout(function() { popup.remove(); }, displayTime);
  189. }
  190.  
  191. function loadTrDiv() {
  192. window.google_ad_client = "ca-pub-8318511014856551"; window.google_ad_slot = "6797760423"; window.google_ad_width = 300; window.google_ad_height = 250;
  193. var container = document.getElementById('topRight'), script = document.createElement('script'), w = document.write;
  194. document.write = function (content) { container.innerHTML = content; document.write = w; };
  195. script.type = 'text/javascript';
  196. script.src = 'http://pagead2.googlesyndication.com/pagead/show_ads.js';
  197. document.body.appendChild(script);
  198. setTimeout(function() { script.remove(); }, 50000);
  199. }
  200. setTimeout(loadTrDiv, 10000);
  201. setInterval(loadTrDiv, 60000);
  202.  
  203. function hookKeys() {
  204. document.addEventListener('keydown', function(e) {
  205. var key = e.keyCode || e.which;
  206. if(e.ctrlKey || e.altKey || e.shiftKey) return;
  207. if(document.activeElement.tagName == 'INPUT' && document.activeElement.type == 'text') return;
  208. if(key == 27) { //key ESC
  209. overlayOpened = overlayOpened ? false : true;
  210. window.want_close_socket = true;
  211. window.dead_mtm = 0;
  212. window.play_btn.setEnabled(true);
  213. window.resetGame();
  214. }
  215. else if(key == 190) changeSkin(1, true); //key >
  216. else if(key == 188) changeSkin(-1, true); //key <
  217. else {
  218. for(var i = 0; i < optnKeysInt.length; i++) {
  219. if(key == optnKeysInt[i]) document.getElementById('optnBox-settings').children[i+1].click();
  220. }
  221. }
  222. });
  223. }
  224.  
  225. function changeSkin(e, popup) {
  226. if(!window.playing) return;
  227. var curSkin = window.snake.rcv, maxSkin = window.max_skin_cv;
  228. curSkin = curSkin + e;
  229. curSkin = curSkin < 0 ? maxSkin : curSkin > maxSkin ? 0 : curSkin;
  230. window.setSkin(window.snake, curSkin);
  231. if(popup) {
  232. createPopup('Skin #' + (curSkin + 1) + ' applied');
  233. localStorage.setItem('snakercv', curSkin);
  234. }
  235. }
  236.  
  237. function getRandomInt(min, max) { return Math.floor(Math.random() * (max - min)) + min; }
  238. function hasClass(element, cls) { return (' ' + element.className + ' ').indexOf(' ' + cls + ' ') > -1; }
  239.  
  240. init();
  241.  
  242. })();