Guest User

Untitled

a guest
May 3rd, 2016
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.33 KB | None | 0 0
  1. // ==UserScript==
  2. // @name SLITio by szymy
  3. // @namespace slitio.szymy
  4. // @version 0.1.16
  5. // @description slither.io MOD
  6. // @author szymy
  7. // @match http://slither.io/*
  8. // @updateURL http://ogario.ovh/slitio/download/SLITio.user.js
  9. // @run-at document-body
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. // Source: http://slitio.ogario.ovh
  14.  
  15. (function(w) {
  16. var modVersion = "v0.1.16",
  17. renderMode = 2, // 3 - normal, 2 - optimized, 1 - simple (mobile)
  18. normalMode = false,
  19. gameFPS = null,
  20. positionHUD = null,
  21. ipHUD = null,
  22. fpsHUD = null,
  23. styleHUD = "color: #FFF; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; font-size: 14px; position: fixed; opacity: 0.35; z-index: 7;",
  24. inpNick = null,
  25. currentIP = null,
  26. retry = 0,
  27. bgImage = null,
  28. rotate = false;
  29. function init() {
  30. // Append DIVs
  31. appendDiv("position-hud", "nsi", styleHUD + "right: 30; bottom: 120px;");
  32. appendDiv("ip-hud", "nsi", styleHUD + "right: 30; bottom: 150px;");
  33. appendDiv("fps-hud", "nsi", styleHUD + "right: 30; bottom: 170px;");
  34. positionHUD = document.getElementById("position-hud");
  35. ipHUD = document.getElementById("ip-hud");
  36. fpsHUD = document.getElementById("fps-hud");
  37. // Add zoom
  38. if (/firefox/i.test(navigator.userAgent)) {
  39. document.addEventListener("DOMMouseScroll", zoom, false);
  40. } else {
  41. document.body.onmousewheel = zoom;
  42. }
  43. // Keys
  44. w.addEventListener("keydown", function(e) {
  45. switch(e.keyCode) {
  46. // ESC - quick resp
  47. case 27: forceConnect();
  48. break;
  49. // A - Auto skin rotator
  50. case 65: rotate = !rotate; rotateSkin();
  51. break;
  52. // Q - Quit to menu
  53. case 81: quit();
  54. break;
  55. // S - Change skin
  56. case 83: changeSkin();
  57. break;
  58. // Z - Reset zoom
  59. case 90: resetZoom();
  60. break;
  61. }
  62. }, false);
  63. // Hijack console log
  64. /*
  65. if (w.console) {
  66. w.console.logOld = console.log;
  67. w.console.log = getConsoleLog;
  68. }
  69. */
  70. // Set menu
  71. setMenu();
  72. // Set leaderboard
  73. setLeaderboard();
  74. // Set graphics
  75. setGraphics();
  76. // Update loop
  77. updateLoop();
  78. // Show FPS
  79. showFPS();
  80. }
  81. // Append DIV
  82. function appendDiv(id, className, style) {
  83. var div = document.createElement("div");
  84. if (id) {
  85. div.id = id;
  86. }
  87. if (className) {
  88. div.className = className;
  89. }
  90. if (style) {
  91. div.style = style;
  92. }
  93. document.body.appendChild(div);
  94. }
  95. // Zoom
  96. function zoom(e) {
  97. if (!w.gsc || !w.playing) {
  98. return;
  99. }
  100. w.gsc *= Math.pow(0.9, e.wheelDelta / -120 || e.detail / 2 || 0);
  101. }
  102. // Reset zoom
  103. function resetZoom() {
  104. w.gsc = 0.9;
  105. }
  106. // Get console log
  107. function getConsoleLog(log) {
  108. //w.console.logOld(log);
  109. if (log.indexOf("FPS") != -1) {
  110. gameFPS = log;
  111. }
  112. }
  113. // Set menu
  114. function setMenu() {
  115. var login = document.getElementById("login");
  116. if (login) {
  117. // Unblock skins
  118. w.localStorage.setItem("edttsg", "1");
  119. // Load settings
  120. loadSettings();
  121. // Keys info
  122. var div = document.createElement("div");
  123. div.style.width = "300px";
  124. div.style.color = "#56ac81";
  125. div.style.fontFamily = "'Lucida Sans Unicode', 'Lucida Grande', sans-serif";
  126. div.style.fontSize = "12px";
  127. div.style.textAlign = "center";
  128. div.style.opacity = "0.5";
  129. div.style.margin = "0 auto";
  130. div.style.padding = "10px 0";
  131. div.innerHTML = "[ESC] - Quick resp | [Q] - Quit to menu<br/>[A] - Auto skin rotator | [S] - Change skin<br/>[Z] - Reset zoom | [Space] - Boost";
  132. login.appendChild(div);
  133. // Menu container
  134. var sltMenu = document.createElement("div");
  135. sltMenu.style.width = "260px";
  136. sltMenu.style.color = "#8058D0";
  137. sltMenu.style.backgroundColor = "#1e262e";
  138. sltMenu.style.borderRadius = "29px";
  139. sltMenu.style.fontFamily = "'Lucida Sans Unicode', 'Lucida Grande', sans-serif";
  140. sltMenu.style.fontSize = "14px";
  141. sltMenu.style.textAlign = "center";
  142. sltMenu.style.margin = "0 auto 100px auto";
  143. sltMenu.style.padding = "10px 14px";
  144. sltMenu.innerHTML = "MOD: <strong>SLITio by szymy</strong> | <strong>" + modVersion + "</strong>";
  145. login.appendChild(sltMenu);
  146. // IP input container
  147. var div = document.createElement("div");
  148. div.style.color = "#8058D0";
  149. div.style.backgroundColor = "#4C447C";
  150. div.style.borderRadius = "29px";
  151. div.style.margin = "10 auto";
  152. div.style.padding = "8px";
  153. sltMenu.appendChild(div);
  154. // IP input
  155. var input = document.createElement("input");
  156. input.id = "server-ip";
  157. input.type = "text";
  158. input.placeholder = "Server address (IP:port)";
  159. input.style.height = "24px";
  160. input.style.display = "inline-block";
  161. input.style.background = "none";
  162. input.style.color = "#e0e0ff";
  163. input.style.border = "none";
  164. input.style.outline = "none";
  165. div.appendChild(input);
  166. // Connect (play) button
  167. var button = document.createElement("input");
  168. button.id = "connect-btn";
  169. button.type = "button";
  170. button.value = "Play";
  171. button.style.height = "24px";
  172. button.style.display = "inline-block";
  173. button.style.borderRadius = "12px";
  174. button.style.color = "#FFF";
  175. button.style.backgroundColor = "#56ac81";
  176. button.style.border = "none";
  177. button.style.outline = "none";
  178. button.style.cursor = "pointer";
  179. button.style.padding = "0 20px";
  180. div.appendChild(button);
  181. // Select server container
  182. var div = document.createElement("div");
  183. div.style.backgroundColor = "#919191";
  184. div.style.borderRadius = "29px";
  185. div.style.margin = "10 auto";
  186. div.style.padding = "8px";
  187. sltMenu.appendChild(div);
  188. // Select server
  189. var select = document.createElement("select");
  190. select.id = "select-srv";
  191. select.style.background = "none";
  192. select.style.border = "none";
  193. select.style.outline = "none";
  194. var option = document.createElement("option");
  195. option.value = "";
  196. option.text = "-- Select a server --";
  197. select.appendChild(option);
  198. div.appendChild(select);
  199. // Select graph container
  200. var div = document.createElement("div");
  201. div.style.backgroundColor = "#A5A5A5";
  202. div.style.borderRadius = "29px";
  203. div.style.margin = "10 auto";
  204. div.style.padding = "8px";
  205. sltMenu.appendChild(div);
  206. // Select graph
  207. var select = document.createElement("select");
  208. select.id = "select-graph";
  209. select.style.background = "none";
  210. select.style.border = "none";
  211. select.style.outline = "none";
  212. div.appendChild(select);
  213. var option = document.createElement("option");
  214. option.value = "3";
  215. option.text = "Graphics: normal";
  216. select.appendChild(option);
  217. var option = document.createElement("option");
  218. option.value = "2";
  219. option.text = "Graphics: optimized";
  220. select.appendChild(option);
  221. var option = document.createElement("option");
  222. option.value = "1";
  223. option.text = "Graphics: low";
  224. select.appendChild(option);
  225. // Menu footer
  226. sltMenu.innerHTML += '<a href="http://ogario.ovh" target="_blank" style="color: #56ac81;">Visit ogario.ovh</a> | ';
  227. sltMenu.innerHTML += '<a href="https://www.youtube.com/channel/UCaWiPNJWnhzYDrBQoXokn6w" target="_blank" style="color: #56ac81;">YT Channel</a>';
  228. // Get IP input
  229. inpIP = document.getElementById("server-ip");
  230. // Get nick
  231. var nick = document.getElementById("nick");
  232. nick.addEventListener("input", getNick, false);
  233. // Force connect
  234. var connectBtn = document.getElementById("connect-btn");
  235. connectBtn.onclick = forceConnect;
  236. // Get servers list
  237. getServersList();
  238. // Set graphic mode
  239. var selectGraph = document.getElementById("select-graph");
  240. if (renderMode == 1) {
  241. selectGraph.selectedIndex = 2;
  242. } else if (renderMode == 2) {
  243. selectGraph.selectedIndex = 1;
  244. } else {
  245. selectGraph.selectedIndex = 0;
  246. normalMode = true;
  247. }
  248. selectGraph.onchange = function() {
  249. var mode = selectGraph.value;
  250. if (mode) {
  251. renderMode = mode;
  252. localStorage.setItem("rendermode", renderMode);
  253. }
  254. };
  255. resizeView();
  256. } else {
  257. setTimeout(setMenu, 100);
  258. }
  259. }
  260. // Load settings
  261. function loadSettings() {
  262. if (w.localStorage.getItem("nick") != null) {
  263. var nick = w.localStorage.getItem("nick");
  264. document.getElementById("nick").value = nick;
  265. }
  266. if (w.localStorage.getItem("rendermode") != null) {
  267. var mode = parseInt(w.localStorage.getItem("rendermode"));
  268. if (mode >= 1 && mode <= 3) {
  269. renderMode = mode;
  270. }
  271. }
  272. }
  273. // Get nick
  274. function getNick() {
  275. var nick = document.getElementById("nick").value;
  276. w.localStorage.setItem("nick", nick);
  277. }
  278. // Connection status
  279. function connectionStatus() {
  280. if (!w.connecting || retry == 10) {
  281. w.forcing = false;
  282. retry = 0;
  283. return;
  284. }
  285. retry++;
  286. setTimeout(connectionStatus, 1000);
  287. }
  288. // Force connect
  289. function forceConnect() {
  290. if (inpIP.value.length == 0 || !w.connect) {
  291. return;
  292. }
  293. w.forcing = true;
  294. if (!w.bso) {
  295. w.bso = {};
  296. }
  297. var srv = inpIP.value.trim().split(":");
  298. w.bso.ip = srv[0];
  299. w.bso.po = srv[1];
  300. w.connect();
  301. setTimeout(connectionStatus, 1000);
  302. }
  303. // Get servers list
  304. function getServersList() {
  305. if (w.sos && w.sos.length > 0) {
  306. var selectSrv = document.getElementById("select-srv");
  307. for (var i = 0; i < sos.length; i++) {
  308. var srv = sos[i];
  309. var option = document.createElement("option");
  310. option.value = srv.ip + ":" + srv.po;
  311. option.text = (i + 1) + ". " + option.value;
  312. selectSrv.appendChild(option);
  313. }
  314. selectSrv.onchange = function() {
  315. var srv = selectSrv.value;
  316. inpIP.value = srv;
  317. };
  318. } else {
  319. setTimeout(getServersList, 100);
  320. }
  321. }
  322. // Resize view
  323. function resizeView() {
  324. if (w.resize) {
  325. w.lww = 0; // Reset width (force resize)
  326. w.wsu = 0; // Clear ad space
  327. w.resize();
  328. var wh = Math.ceil(w.innerHeight);
  329. if (wh < 800) {
  330. var login = document.getElementById("login");
  331. w.lgbsc = wh / 800;
  332. login.style.top = - (Math.round(wh * (1 - w.lgbsc) * 1E5) / 1E5) + "px";
  333. if (w.trf) {
  334. w.trf(login, "scale(" + w.lgbsc + "," + w.lgbsc + ")");
  335. }
  336. }
  337. } else {
  338. setTimeout(resizeView, 100);
  339. }
  340. }
  341. // Set leaderboard
  342. function setLeaderboard() {
  343. if (w.lbh) {
  344. w.lbh.textContent = "MOD: SLITio by szymy";
  345. w.lbh.style.fontSize = "20px";
  346. } else {
  347. setTimeout(setLeaderboard, 100);
  348. }
  349. }
  350. // Set normal mode
  351. function setNormalMode() {
  352. normalMode = true;
  353. w.ggbg = true;
  354. if (!w.bgp2 && bgImage) {
  355. w.bgp2 = bgImage;
  356. }
  357. w.render_mode = 2;
  358. }
  359. // Set graphics
  360. function setGraphics() {
  361. if (renderMode == 3) {
  362. if (!normalMode) {
  363. setNormalMode();
  364. }
  365. return;
  366. }
  367. if (normalMode) {
  368. normalMode = false;
  369. }
  370. if (w.want_quality && w.want_quality != 0) {
  371. w.want_quality = 0;
  372. w.localStorage.setItem("qual", "0");
  373. w.grqi.src = "/s/lowquality.png";
  374. }
  375. if (w.ggbg && w.gbgmc) {
  376. w.ggbg = false;
  377. }
  378. if (w.bgp2) {
  379. bgImage = w.bgp2;
  380. w.bgp2 = null;
  381. }
  382. if (w.high_quality) {
  383. w.high_quality = false;
  384. }
  385. if (w.gla && w.gla != 0) {
  386. w.gla = 0;
  387. }
  388. if (w.render_mode && w.render_mode != renderMode) {
  389. w.render_mode = renderMode;
  390. }
  391. }
  392. // Show FPS
  393. function showFPS() {
  394. if (w.playing && fpsHUD && w.fps && w.lrd_mtm) {
  395. if (Date.now() - w.lrd_mtm > 970) {
  396. fpsHUD.textContent = "FPS: " + w.fps;
  397. }
  398. }
  399. setTimeout(showFPS, 30);
  400. }
  401. // Update loop
  402. function updateLoop() {
  403. setGraphics();
  404. if (w.playing) {
  405. if (positionHUD) {
  406. positionHUD.textContent = "X: " + (~~w.view_xx || 0) + " Y: " + (~~w.view_yy || 0);
  407. }
  408. if (inpIP && w.bso && currentIP != w.bso.ip + ":" + w.bso.po) {
  409. currentIP = w.bso.ip + ":" + w.bso.po;
  410. inpIP.value = currentIP;
  411. if (ipHUD) {
  412. ipHUD.textContent = "Server: " + currentIP;
  413. }
  414. }
  415. } else {
  416. positionHUD.textContent = "";
  417. fpsHUD.textContent = "";
  418. }
  419. setTimeout(updateLoop, 1000);
  420. }
  421. // Change skin
  422. function changeSkin() {
  423. if (w.playing && w.snake != null) {
  424. var skin = w.snake.rcv;
  425. skin++;
  426. if (skin > w.max_skin_cv) {
  427. skin = 0;
  428. }
  429. w.setSkin(w.snake, skin);
  430. }
  431. }
  432. // Rotate skin
  433. function rotateSkin() {
  434. if (!rotate) {
  435. return;
  436. }
  437. changeSkin();
  438. setTimeout(rotateSkin, 1000);
  439. }
  440. // Quit to menu
  441. function quit() {
  442. if (w.playing) {
  443. w.want_close_socket = true;
  444. w.dead_mtm = 1;
  445. if (w.ws) {
  446. w.ws.close();
  447. w.ws = null;
  448. }
  449. w.playing = w.connected = false;
  450. w.resetGame();
  451. w.play_btn.setEnabled(true);
  452. }
  453. }
  454. // Init
  455. init();
  456. })(window);
Add Comment
Please, Sign In to add comment