ReActif

Slither MOD

Nov 22nd, 2017
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         SLITio by szymy
  3. // @namespace    slitio.szymy
  4. // @version      0.1.18
  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.18",
  17.         renderMode  = 2, // 3 - normal, 2 - optimized, 1 - simple (mobile)
  18.         normalMode  = false,
  19.         gameFPS     = null,
  20.         positionHUD = null,
  21.         ipHUD       = null,
  22.         scoreHUD    = null,
  23.         fpsHUD      = null,
  24.         styleHUD    = "color: #FFF; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; font-size: 14px; position: fixed; opacity: 0.35; z-index: 7;",
  25.         inpNick     = null,
  26.         currentIP   = null,
  27.         retry       = 0,
  28.         bgImage     = null,
  29.         rotate      = false,
  30.         highScore   = 0;
  31.  
  32.     // INITIALISATION
  33.     function init() {
  34.         // Append DIV
  35.         appendDiv("position-hud", "nsi", styleHUD + "right: 30; bottom: 120px;");
  36.         appendDiv("ip-hud", "nsi", styleHUD + "right: 30; bottom: 150px;");
  37.         appendDiv("score-hud", "nsi", styleHUD + "right: 30; bottom: 170px;");
  38.         appendDiv("fps-hud", "nsi", styleHUD + "right: 30; bottom: 190px;");
  39.  
  40.         // Get UI
  41.         positionHUD = document.getElementById("position-hud");
  42.         ipHUD       = document.getElementById("ip-hud");
  43.         scoreHUD    = document.getElementById("score-hud");
  44.         fpsHUD      = document.getElementById("fps-hud");
  45.  
  46.         // Add Zoom
  47.         if (/firefox/i.test(navigator.userAgent)) {
  48.             document.addEventListener("DOMMouseScroll", zoom, false);
  49.         } else {
  50.             document.body.onmousewheel = zoom;
  51.         }
  52.  
  53.         // Keys
  54.         w.addEventListener("keydown", function(e) {
  55.             switch(e.keyCode) {
  56.  
  57.                 // Esc - Quick Respawn
  58.                 case 27: quickResp();
  59.                     break;
  60.  
  61.                 // A - Auto Skin Rotator
  62.                 case 65:
  63.                     rotate = !rotate;
  64.                     rotateSkin();
  65.                     break;
  66.  
  67.                 // Q - Quit To Menu
  68.                 case 81: quit();
  69.                     break;
  70.  
  71.                 // S - Change Skin
  72.                 case 83: changeSkin();
  73.                     break;
  74.  
  75.                 // Z - Reset Zoom
  76.                 case 90: resetZoom();
  77.                     break;
  78.             }
  79.         }, false);
  80.  
  81.         // Hijack Console Log
  82.         /*
  83.         if (w.console) {
  84.             w.console.logOld = console.log;
  85.             w.console.log    = getConsoleLog;
  86.         }
  87.         */
  88.  
  89.         // Settings
  90.         setMenu();
  91.         setLeaderboard();
  92.         setGraphics();
  93.         updateLoop();
  94.         showFPS();
  95.     }
  96.  
  97.     // APPEND DIV
  98.     function appendDiv(id, className, style) {
  99.         var div = document.createElement("div");
  100.         if (id) {
  101.             div.id = id;
  102.         }
  103.         if (className) {
  104.             div.className = className;
  105.         }
  106.         if (style) {
  107.             div.style = style;
  108.         }
  109.         document.body.appendChild(div);
  110.     }
  111.  
  112.     // ZOOM
  113.     function zoom(e) {
  114.         if (!w.gsc || !w.playing) {
  115.             return;
  116.         }
  117.         w.gsc *= Math.pow(0.9, e.wheelDelta / -120 || e.detail / 2 || 0);
  118.     }
  119.  
  120.     // RESET ZOOM
  121.     function resetZoom() {
  122.         w.gsc = 0.9;
  123.     }
  124.  
  125.     // GET CONSOLE LOG
  126.     function getConsoleLog(log) {
  127.         //w.console.logOld(log);
  128.         if (log.indexOf("FPS") != -1) {
  129.             gameFPS = log;
  130.         }
  131.     }
  132.  
  133.     // SET MENU
  134.     function setMenu() {
  135.         var login = document.getElementById("login");
  136.         if (login) {
  137.  
  138.             // Unblock skins
  139.             w.localStorage.setItem("edttsg", "1");
  140.  
  141.             // Load settings
  142.             loadSettings();
  143.  
  144.             // Keys Info
  145.             var div = document.createElement("div");
  146.             div.style.width = "300px";
  147.             div.style.color = "#56ac81";
  148.             div.style.fontFamily = "'Lucida Sans Unicode', 'Lucida Grande', sans-serif";
  149.             div.style.fontSize = "12px";
  150.             div.style.textAlign = "center";
  151.             div.style.opacity = "0.5";
  152.             div.style.margin = "0 auto";
  153.             div.style.padding = "10px 0";
  154.             div.innerHTML = "[ESC] - Quick resp | [Q] - Quit to menu<br/>[A] - Auto skin rotator | [S] - Change skin<br/>[Z] - Reset zoom | [Space] - Boost";
  155.             login.appendChild(div);
  156.  
  157.             // Menu Container
  158.             var sltMenu = document.createElement("div");
  159.             sltMenu.style.width = "260px";
  160.             sltMenu.style.color = "#8058D0";
  161.             sltMenu.style.backgroundColor = "#1e262e";
  162.             sltMenu.style.borderRadius = "29px";
  163.             sltMenu.style.fontFamily = "'Lucida Sans Unicode', 'Lucida Grande', sans-serif";
  164.             sltMenu.style.fontSize = "14px";
  165.             sltMenu.style.textAlign = "center";
  166.             sltMenu.style.margin = "0 auto 100px auto";
  167.             sltMenu.style.padding = "10px 14px";
  168.             sltMenu.innerHTML = "MOD: <strong>SLITio by szymy</strong> | <strong>" + modVersion + "</strong>";
  169.             login.appendChild(sltMenu);
  170.  
  171.             // IP Input Container
  172.             var div = document.createElement("div");
  173.             div.style.color = "#8058D0";
  174.             div.style.backgroundColor = "#4C447C";
  175.             div.style.borderRadius = "29px";
  176.             div.style.margin = "10 auto";
  177.             div.style.padding = "8px";
  178.             sltMenu.appendChild(div);
  179.  
  180.             // IP Input
  181.             var input = document.createElement("input");
  182.             input.id = "server-ip";
  183.             input.type = "text";
  184.             input.placeholder = "Server address (IP:port)";
  185.             input.style.height = "24px";
  186.             input.style.display = "inline-block";
  187.             input.style.background = "none";
  188.             input.style.color = "#e0e0ff";
  189.             input.style.border = "none";
  190.             input.style.outline = "none";
  191.             div.appendChild(input);
  192.  
  193.             // Connect (Play) Button
  194.             var button = document.createElement("input");
  195.             button.id = "connect-btn";
  196.             button.type = "button";
  197.             button.value = "Play";
  198.             button.style.height = "24px";
  199.             button.style.display = "inline-block";
  200.             button.style.borderRadius = "12px";
  201.             button.style.color = "#FFF";
  202.             button.style.backgroundColor = "#56ac81";
  203.             button.style.border = "none";
  204.             button.style.outline = "none";
  205.             button.style.cursor = "pointer";
  206.             button.style.padding = "0 20px";
  207.             div.appendChild(button);
  208.  
  209.             // Select Server Container
  210.             var div = document.createElement("div");
  211.             div.style.backgroundColor = "#919191";
  212.             div.style.borderRadius = "29px";
  213.             div.style.margin = "10 auto";
  214.             div.style.padding = "8px";
  215.             sltMenu.appendChild(div);
  216.  
  217.             // Select Server
  218.             var select = document.createElement("select");
  219.             select.id = "select-srv";
  220.             select.style.background = "none";
  221.             select.style.border = "none";
  222.             select.style.outline = "none";
  223.  
  224.             var option = document.createElement("option");
  225.             option.value = "";
  226.             option.text = "-- Select a server --";
  227.             select.appendChild(option);
  228.             div.appendChild(select);
  229.  
  230.             // Select Graph Container
  231.             var div = document.createElement("div");
  232.             div.style.backgroundColor = "#A5A5A5";
  233.             div.style.borderRadius = "29px";
  234.             div.style.margin = "10 auto";
  235.             div.style.padding = "8px";
  236.             sltMenu.appendChild(div);
  237.  
  238.             // Select Graph
  239.             var select = document.createElement("select");
  240.             select.id = "select-graph";
  241.             select.style.background = "none";
  242.             select.style.border = "none";
  243.             select.style.outline = "none";
  244.             div.appendChild(select);
  245.  
  246.             var option = document.createElement("option");
  247.             option.value = "3";
  248.             option.text = "Graphics: normal";
  249.             select.appendChild(option);
  250.  
  251.             var option = document.createElement("option");
  252.             option.value = "2";
  253.             option.text = "Graphics: optimized";
  254.             select.appendChild(option);
  255.  
  256.             var option = document.createElement("option");
  257.             option.value = "1";
  258.             option.text = "Graphics: low";
  259.             select.appendChild(option);
  260.  
  261.             // Menu Footer
  262.             sltMenu.innerHTML += '<a href="http://ogario.ovh" target="_blank" style="color: #56ac81;">Visit ogario.ovh</a> | ';
  263.             sltMenu.innerHTML += '<a href="https://www.youtube.com/channel/UCaWiPNJWnhzYDrBQoXokn6w" target="_blank" style="color: #56ac81;">YT Channel</a>';
  264.  
  265.             // Get Ip Input
  266.             inpIP = document.getElementById("server-ip");
  267.  
  268.             // Get Nick
  269.             var nick = document.getElementById("nick");
  270.             nick.addEventListener("input", getNick, false);
  271.  
  272.             // Force Connect
  273.             var connectBtn = document.getElementById("connect-btn");
  274.             connectBtn.onclick = forceConnect;
  275.  
  276.             // Get Servers List
  277.             getServersList();
  278.  
  279.             // Set Graphic Mode
  280.             var selectGraph = document.getElementById("select-graph");
  281.             if (renderMode == 1) {
  282.                 selectGraph.selectedIndex = 2;
  283.             } else if (renderMode == 2) {
  284.                 selectGraph.selectedIndex = 1;
  285.             } else {
  286.                 selectGraph.selectedIndex = 0;
  287.                 normalMode = true;
  288.             }
  289.             selectGraph.onchange = function() {
  290.                 var mode = selectGraph.value;
  291.                 if (mode) {
  292.                     renderMode = mode;
  293.                     w.localStorage.setItem("rendermode", renderMode);
  294.                 }
  295.             };
  296.             resizeView();
  297.         } else {
  298.             setTimeout(setMenu, 100);
  299.         }
  300.     }
  301.  
  302.     // LOAD SETTINGS
  303.     function loadSettings() {
  304.         if (w.localStorage.getItem("nick") != null) {
  305.             var nick = w.localStorage.getItem("nick");
  306.             document.getElementById("nick").value = nick;
  307.         }
  308.  
  309.         if (w.localStorage.getItem("rendermode") != null) {
  310.             var mode = parseInt(w.localStorage.getItem("rendermode"));
  311.             if (mode >= 1 && mode <= 3) {
  312.                 renderMode = mode;
  313.             }
  314.         }
  315.  
  316.         if (w.localStorage.getItem("highscore") != null) {
  317.             var score = parseFloat(w.localStorage.getItem("highscore"));
  318.             if (score > 0) {
  319.                 highScore = score;
  320.             }
  321.         }
  322.     }
  323.  
  324.     // GET NICK
  325.     function getNick() {
  326.         var nick = document.getElementById("nick").value;
  327.         w.localStorage.setItem("nick", nick);
  328.     }
  329.  
  330.     // CONNECTION STATUS
  331.     function connectionStatus() {
  332.         if (!w.connecting || retry == 10) {
  333.             w.forcing = false;
  334.             retry = 0;
  335.             return;
  336.         }
  337.         retry++;
  338.         setTimeout(connectionStatus, 1000);
  339.     }
  340.  
  341.     // FORCE CONNECT
  342.     function forceConnect() {
  343.         if (inpIP.value.length == 0 || !w.connect) {
  344.             return;
  345.         }
  346.         w.forcing = true;
  347.  
  348.         if (!w.bso) {
  349.             w.bso = {};
  350.         }
  351.  
  352.         var srv = inpIP.value.trim().split(":");
  353.         w.bso.ip = srv[0];
  354.         w.bso.po = srv[1];
  355.         w.connect();
  356.         setTimeout(connectionStatus, 1000);
  357.     }
  358.  
  359.     // GET SERVERS LIST
  360.     function getServersList() {
  361.         if (w.sos && w.sos.length > 0) {
  362.             var selectSrv = document.getElementById("select-srv");
  363.             for (var i = 0; i < sos.length; i++) {
  364.                 var srv = sos[i];
  365.                 var option = document.createElement("option");
  366.                 option.value = srv.ip + ":" + srv.po;
  367.                 option.text = (i + 1) + ". " + option.value;
  368.                 selectSrv.appendChild(option);
  369.             }
  370.             selectSrv.onchange = function() {
  371.                 var srv = selectSrv.value;
  372.                 inpIP.value = srv;
  373.             };
  374.         } else {
  375.             setTimeout(getServersList, 100);
  376.         }
  377.     }
  378.  
  379.     // RESIZE VIEW
  380.     function resizeView() {
  381.         if (w.resize) {
  382.             w.lww = 0; // Reset width (Force Resize)
  383.             w.wsu = 0; // Clear Ad Space
  384.             w.resize();
  385.             var wh = Math.ceil(w.innerHeight);
  386.  
  387.             if (wh < 800) {
  388.                 var login = document.getElementById("login");
  389.                 w.lgbsc = wh / 800;
  390.                 login.style.top = - (Math.round(wh * (1 - w.lgbsc) * 1E5) / 1E5) + "px";
  391.                 if (w.trf) {
  392.                     w.trf(login, "scale(" + w.lgbsc + "," + w.lgbsc + ")");
  393.                 }
  394.             }
  395.         } else {
  396.             setTimeout(resizeView, 100);
  397.         }
  398.     }
  399.  
  400.     // SET LEADERBOARD
  401.     function setLeaderboard() {
  402.         if (w.lbh) {
  403.             w.lbh.textContent = "MOD: SLITio by szymy";
  404.             w.lbh.style.fontSize = "20px";
  405.         } else {
  406.             setTimeout(setLeaderboard, 100);
  407.         }
  408.     }
  409.  
  410.     // SET NORMAL MODE
  411.     function setNormalMode() {
  412.         normalMode = true;
  413.         w.ggbg = true;
  414.         if (!w.bgp2 && bgImage) {
  415.             w.bgp2 = bgImage;
  416.         }
  417.         w.render_mode = 2;
  418.     }
  419.  
  420.     // SET GRAPHICS
  421.     function setGraphics() {
  422.         if (renderMode == 3) {
  423.             if (!normalMode) {
  424.                 setNormalMode();
  425.             }
  426.             return;
  427.         }
  428.  
  429.         if (normalMode) {
  430.             normalMode = false;
  431.         }
  432.  
  433.         if (w.want_quality && w.want_quality != 0) {
  434.             w.want_quality = 0;
  435.             w.localStorage.setItem("qual", "0");
  436.             w.grqi.src = "/s/lowquality.png";
  437.         }
  438.  
  439.         if (w.ggbg && w.gbgmc) {
  440.             w.ggbg = false;
  441.         }
  442.  
  443.         if (w.bgp2) {
  444.             bgImage = w.bgp2;
  445.             w.bgp2 = null;
  446.         }
  447.  
  448.         if (w.high_quality) {
  449.             w.high_quality = false;
  450.         }
  451.  
  452.         if (w.gla && w.gla != 0) {
  453.             w.gla = 0;
  454.         }
  455.  
  456.         if (w.render_mode && w.render_mode != renderMode) {
  457.             w.render_mode = renderMode;
  458.         }
  459.     }
  460.  
  461.     // QUICK RESPAWN
  462.     function quickResp() {
  463.         w.dead_mtm = 0;
  464.         w.login_fr = 0;
  465.         forceConnect();
  466.     }
  467.  
  468.     // QUIT TO MENU
  469.     function quit() {
  470.         if (w.playing && w.resetGame) {
  471.             w.want_close_socket = true;
  472.             w.dead_mtm = 0;
  473.             if (w.play_btn) {
  474.                 w.play_btn.setEnabled(true);
  475.             }
  476.             w.resetGame();
  477.         }
  478.     }
  479.  
  480.     // CHANGE SKIN
  481.     function changeSkin() {
  482.         if (w.playing && w.snake != null) {
  483.             var skin = w.snake.rcv,
  484.                 max = w.max_skin_cv || 25;
  485.             skin++;
  486.             if (skin > max) {
  487.                 skin = 0;
  488.             }
  489.             w.setSkin(w.snake, skin);
  490.         }
  491.     }
  492.  
  493.     // ROTATE SKIN
  494.     function rotateSkin() {
  495.         if (!rotate) {
  496.             return;
  497.         }
  498.         changeSkin();
  499.         setTimeout(rotateSkin, 500);
  500.     }
  501.  
  502.     // SET HIGH SCORE
  503.     function setHighScore() {
  504.         if (!w.snake || !w.fpsls || !w.fmlts) {
  505.             return;
  506.         }
  507.  
  508.         var currentScore = Math.floor(150 * (w.fpsls[w.snake.sct] + w.snake.fam / w.fmlts[w.snake.sct] - 1) - 50) / 10;
  509.         if (currentScore > highScore) {
  510.             highScore = currentScore;
  511.             w.localStorage.setItem("highscore", highScore);
  512.         }
  513.  
  514.         if (scoreHUD && highScore > 0) {
  515.             scoreHUD.textContent = "Best score: " + highScore;
  516.         }
  517.     }
  518.  
  519.     // SHOW FPS
  520.     function showFPS() {
  521.         if (w.playing && fpsHUD && w.fps && w.lrd_mtm) {
  522.             if (Date.now() - w.lrd_mtm > 970) {
  523.                 fpsHUD.textContent = "FPS: " + w.fps;
  524.             }
  525.         }
  526.         setTimeout(showFPS, 30);
  527.     }
  528.  
  529.     // UPDATE LOOP
  530.     function updateLoop() {
  531.         setGraphics();
  532.         setHighScore();
  533.         if (w.playing) {
  534.             if (positionHUD) {
  535.                 positionHUD.textContent = "X: " + (~~w.view_xx || 0) + " Y: " + (~~w.view_yy || 0);
  536.             }
  537.  
  538.             if (inpIP && w.bso && currentIP != w.bso.ip + ":" + w.bso.po) {
  539.                 currentIP = w.bso.ip + ":" + w.bso.po;
  540.                 inpIP.value = currentIP;
  541.                 if (ipHUD) {
  542.                     ipHUD.textContent = "Server: " + currentIP;
  543.                 }
  544.             }
  545.         } else {
  546.             positionHUD.textContent = "";
  547.             fpsHUD.textContent = "";
  548.         }
  549.         setTimeout(updateLoop, 1000);
  550.     }
  551.  
  552.     // START
  553.     init();
  554.  
  555. })(window);
Add Comment
Please, Sign In to add comment