Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name SLITio by szymy
- // @namespace slitio.szymy
- // @version 0.1.18
- // @description slither.io MOD
- // @author szymy
- // @match http://slither.io/*
- // @updateURL http://ogario.ovh/slitio/download/SLITio.user.js
- // @run-at document-body
- // @grant none
- // ==/UserScript==
- // Source: http://slitio.ogario.ovh
- (function(w) {
- var modVersion = "v0.1.18",
- renderMode = 2, // 3 - normal, 2 - optimized, 1 - simple (mobile)
- normalMode = false,
- gameFPS = null,
- positionHUD = null,
- ipHUD = null,
- scoreHUD = null,
- fpsHUD = null,
- styleHUD = "color: #FFF; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; font-size: 14px; position: fixed; opacity: 0.35; z-index: 7;",
- inpNick = null,
- currentIP = null,
- retry = 0,
- bgImage = null,
- rotate = false,
- highScore = 0;
- // INITIALISATION
- function init() {
- // Append DIV
- appendDiv("position-hud", "nsi", styleHUD + "right: 30; bottom: 120px;");
- appendDiv("ip-hud", "nsi", styleHUD + "right: 30; bottom: 150px;");
- appendDiv("score-hud", "nsi", styleHUD + "right: 30; bottom: 170px;");
- appendDiv("fps-hud", "nsi", styleHUD + "right: 30; bottom: 190px;");
- // Get UI
- positionHUD = document.getElementById("position-hud");
- ipHUD = document.getElementById("ip-hud");
- scoreHUD = document.getElementById("score-hud");
- fpsHUD = document.getElementById("fps-hud");
- // Add Zoom
- if (/firefox/i.test(navigator.userAgent)) {
- document.addEventListener("DOMMouseScroll", zoom, false);
- } else {
- document.body.onmousewheel = zoom;
- }
- // Keys
- w.addEventListener("keydown", function(e) {
- switch(e.keyCode) {
- // Esc - Quick Respawn
- case 27: quickResp();
- break;
- // A - Auto Skin Rotator
- case 65:
- rotate = !rotate;
- rotateSkin();
- break;
- // Q - Quit To Menu
- case 81: quit();
- break;
- // S - Change Skin
- case 83: changeSkin();
- break;
- // Z - Reset Zoom
- case 90: resetZoom();
- break;
- }
- }, false);
- // Hijack Console Log
- /*
- if (w.console) {
- w.console.logOld = console.log;
- w.console.log = getConsoleLog;
- }
- */
- // Settings
- setMenu();
- setLeaderboard();
- setGraphics();
- updateLoop();
- showFPS();
- }
- // APPEND DIV
- function appendDiv(id, className, style) {
- var div = document.createElement("div");
- if (id) {
- div.id = id;
- }
- if (className) {
- div.className = className;
- }
- if (style) {
- div.style = style;
- }
- document.body.appendChild(div);
- }
- // ZOOM
- function zoom(e) {
- if (!w.gsc || !w.playing) {
- return;
- }
- w.gsc *= Math.pow(0.9, e.wheelDelta / -120 || e.detail / 2 || 0);
- }
- // RESET ZOOM
- function resetZoom() {
- w.gsc = 0.9;
- }
- // GET CONSOLE LOG
- function getConsoleLog(log) {
- //w.console.logOld(log);
- if (log.indexOf("FPS") != -1) {
- gameFPS = log;
- }
- }
- // SET MENU
- function setMenu() {
- var login = document.getElementById("login");
- if (login) {
- // Unblock skins
- w.localStorage.setItem("edttsg", "1");
- // Load settings
- loadSettings();
- // Keys Info
- var div = document.createElement("div");
- div.style.width = "300px";
- div.style.color = "#56ac81";
- div.style.fontFamily = "'Lucida Sans Unicode', 'Lucida Grande', sans-serif";
- div.style.fontSize = "12px";
- div.style.textAlign = "center";
- div.style.opacity = "0.5";
- div.style.margin = "0 auto";
- div.style.padding = "10px 0";
- div.innerHTML = "[ESC] - Quick resp | [Q] - Quit to menu<br/>[A] - Auto skin rotator | [S] - Change skin<br/>[Z] - Reset zoom | [Space] - Boost";
- login.appendChild(div);
- // Menu Container
- var sltMenu = document.createElement("div");
- sltMenu.style.width = "260px";
- sltMenu.style.color = "#8058D0";
- sltMenu.style.backgroundColor = "#1e262e";
- sltMenu.style.borderRadius = "29px";
- sltMenu.style.fontFamily = "'Lucida Sans Unicode', 'Lucida Grande', sans-serif";
- sltMenu.style.fontSize = "14px";
- sltMenu.style.textAlign = "center";
- sltMenu.style.margin = "0 auto 100px auto";
- sltMenu.style.padding = "10px 14px";
- sltMenu.innerHTML = "MOD: <strong>SLITio by szymy</strong> | <strong>" + modVersion + "</strong>";
- login.appendChild(sltMenu);
- // IP Input Container
- var div = document.createElement("div");
- div.style.color = "#8058D0";
- div.style.backgroundColor = "#4C447C";
- div.style.borderRadius = "29px";
- div.style.margin = "10 auto";
- div.style.padding = "8px";
- sltMenu.appendChild(div);
- // IP Input
- var input = document.createElement("input");
- input.id = "server-ip";
- input.type = "text";
- input.placeholder = "Server address (IP:port)";
- input.style.height = "24px";
- input.style.display = "inline-block";
- input.style.background = "none";
- input.style.color = "#e0e0ff";
- input.style.border = "none";
- input.style.outline = "none";
- div.appendChild(input);
- // Connect (Play) Button
- var button = document.createElement("input");
- button.id = "connect-btn";
- button.type = "button";
- button.value = "Play";
- button.style.height = "24px";
- button.style.display = "inline-block";
- button.style.borderRadius = "12px";
- button.style.color = "#FFF";
- button.style.backgroundColor = "#56ac81";
- button.style.border = "none";
- button.style.outline = "none";
- button.style.cursor = "pointer";
- button.style.padding = "0 20px";
- div.appendChild(button);
- // Select Server Container
- var div = document.createElement("div");
- div.style.backgroundColor = "#919191";
- div.style.borderRadius = "29px";
- div.style.margin = "10 auto";
- div.style.padding = "8px";
- sltMenu.appendChild(div);
- // Select Server
- var select = document.createElement("select");
- select.id = "select-srv";
- select.style.background = "none";
- select.style.border = "none";
- select.style.outline = "none";
- var option = document.createElement("option");
- option.value = "";
- option.text = "-- Select a server --";
- select.appendChild(option);
- div.appendChild(select);
- // Select Graph Container
- var div = document.createElement("div");
- div.style.backgroundColor = "#A5A5A5";
- div.style.borderRadius = "29px";
- div.style.margin = "10 auto";
- div.style.padding = "8px";
- sltMenu.appendChild(div);
- // Select Graph
- var select = document.createElement("select");
- select.id = "select-graph";
- select.style.background = "none";
- select.style.border = "none";
- select.style.outline = "none";
- div.appendChild(select);
- var option = document.createElement("option");
- option.value = "3";
- option.text = "Graphics: normal";
- select.appendChild(option);
- var option = document.createElement("option");
- option.value = "2";
- option.text = "Graphics: optimized";
- select.appendChild(option);
- var option = document.createElement("option");
- option.value = "1";
- option.text = "Graphics: low";
- select.appendChild(option);
- // Menu Footer
- sltMenu.innerHTML += '<a href="http://ogario.ovh" target="_blank" style="color: #56ac81;">Visit ogario.ovh</a> | ';
- sltMenu.innerHTML += '<a href="https://www.youtube.com/channel/UCaWiPNJWnhzYDrBQoXokn6w" target="_blank" style="color: #56ac81;">YT Channel</a>';
- // Get Ip Input
- inpIP = document.getElementById("server-ip");
- // Get Nick
- var nick = document.getElementById("nick");
- nick.addEventListener("input", getNick, false);
- // Force Connect
- var connectBtn = document.getElementById("connect-btn");
- connectBtn.onclick = forceConnect;
- // Get Servers List
- getServersList();
- // Set Graphic Mode
- var selectGraph = document.getElementById("select-graph");
- if (renderMode == 1) {
- selectGraph.selectedIndex = 2;
- } else if (renderMode == 2) {
- selectGraph.selectedIndex = 1;
- } else {
- selectGraph.selectedIndex = 0;
- normalMode = true;
- }
- selectGraph.onchange = function() {
- var mode = selectGraph.value;
- if (mode) {
- renderMode = mode;
- w.localStorage.setItem("rendermode", renderMode);
- }
- };
- resizeView();
- } else {
- setTimeout(setMenu, 100);
- }
- }
- // LOAD SETTINGS
- function loadSettings() {
- if (w.localStorage.getItem("nick") != null) {
- var nick = w.localStorage.getItem("nick");
- document.getElementById("nick").value = nick;
- }
- if (w.localStorage.getItem("rendermode") != null) {
- var mode = parseInt(w.localStorage.getItem("rendermode"));
- if (mode >= 1 && mode <= 3) {
- renderMode = mode;
- }
- }
- if (w.localStorage.getItem("highscore") != null) {
- var score = parseFloat(w.localStorage.getItem("highscore"));
- if (score > 0) {
- highScore = score;
- }
- }
- }
- // GET NICK
- function getNick() {
- var nick = document.getElementById("nick").value;
- w.localStorage.setItem("nick", nick);
- }
- // CONNECTION STATUS
- function connectionStatus() {
- if (!w.connecting || retry == 10) {
- w.forcing = false;
- retry = 0;
- return;
- }
- retry++;
- setTimeout(connectionStatus, 1000);
- }
- // FORCE CONNECT
- function forceConnect() {
- if (inpIP.value.length == 0 || !w.connect) {
- return;
- }
- w.forcing = true;
- if (!w.bso) {
- w.bso = {};
- }
- var srv = inpIP.value.trim().split(":");
- w.bso.ip = srv[0];
- w.bso.po = srv[1];
- w.connect();
- setTimeout(connectionStatus, 1000);
- }
- // GET SERVERS LIST
- function getServersList() {
- if (w.sos && w.sos.length > 0) {
- var selectSrv = document.getElementById("select-srv");
- for (var i = 0; i < sos.length; i++) {
- var srv = sos[i];
- var option = document.createElement("option");
- option.value = srv.ip + ":" + srv.po;
- option.text = (i + 1) + ". " + option.value;
- selectSrv.appendChild(option);
- }
- selectSrv.onchange = function() {
- var srv = selectSrv.value;
- inpIP.value = srv;
- };
- } else {
- setTimeout(getServersList, 100);
- }
- }
- // RESIZE VIEW
- function resizeView() {
- if (w.resize) {
- w.lww = 0; // Reset width (Force Resize)
- w.wsu = 0; // Clear Ad Space
- w.resize();
- var wh = Math.ceil(w.innerHeight);
- if (wh < 800) {
- var login = document.getElementById("login");
- w.lgbsc = wh / 800;
- login.style.top = - (Math.round(wh * (1 - w.lgbsc) * 1E5) / 1E5) + "px";
- if (w.trf) {
- w.trf(login, "scale(" + w.lgbsc + "," + w.lgbsc + ")");
- }
- }
- } else {
- setTimeout(resizeView, 100);
- }
- }
- // SET LEADERBOARD
- function setLeaderboard() {
- if (w.lbh) {
- w.lbh.textContent = "MOD: SLITio by szymy";
- w.lbh.style.fontSize = "20px";
- } else {
- setTimeout(setLeaderboard, 100);
- }
- }
- // SET NORMAL MODE
- function setNormalMode() {
- normalMode = true;
- w.ggbg = true;
- if (!w.bgp2 && bgImage) {
- w.bgp2 = bgImage;
- }
- w.render_mode = 2;
- }
- // SET GRAPHICS
- function setGraphics() {
- if (renderMode == 3) {
- if (!normalMode) {
- setNormalMode();
- }
- return;
- }
- if (normalMode) {
- normalMode = false;
- }
- if (w.want_quality && w.want_quality != 0) {
- w.want_quality = 0;
- w.localStorage.setItem("qual", "0");
- w.grqi.src = "/s/lowquality.png";
- }
- if (w.ggbg && w.gbgmc) {
- w.ggbg = false;
- }
- if (w.bgp2) {
- bgImage = w.bgp2;
- w.bgp2 = null;
- }
- if (w.high_quality) {
- w.high_quality = false;
- }
- if (w.gla && w.gla != 0) {
- w.gla = 0;
- }
- if (w.render_mode && w.render_mode != renderMode) {
- w.render_mode = renderMode;
- }
- }
- // QUICK RESPAWN
- function quickResp() {
- w.dead_mtm = 0;
- w.login_fr = 0;
- forceConnect();
- }
- // QUIT TO MENU
- function quit() {
- if (w.playing && w.resetGame) {
- w.want_close_socket = true;
- w.dead_mtm = 0;
- if (w.play_btn) {
- w.play_btn.setEnabled(true);
- }
- w.resetGame();
- }
- }
- // CHANGE SKIN
- function changeSkin() {
- if (w.playing && w.snake != null) {
- var skin = w.snake.rcv,
- max = w.max_skin_cv || 25;
- skin++;
- if (skin > max) {
- skin = 0;
- }
- w.setSkin(w.snake, skin);
- }
- }
- // ROTATE SKIN
- function rotateSkin() {
- if (!rotate) {
- return;
- }
- changeSkin();
- setTimeout(rotateSkin, 500);
- }
- // SET HIGH SCORE
- function setHighScore() {
- if (!w.snake || !w.fpsls || !w.fmlts) {
- return;
- }
- var currentScore = Math.floor(150 * (w.fpsls[w.snake.sct] + w.snake.fam / w.fmlts[w.snake.sct] - 1) - 50) / 10;
- if (currentScore > highScore) {
- highScore = currentScore;
- w.localStorage.setItem("highscore", highScore);
- }
- if (scoreHUD && highScore > 0) {
- scoreHUD.textContent = "Best score: " + highScore;
- }
- }
- // SHOW FPS
- function showFPS() {
- if (w.playing && fpsHUD && w.fps && w.lrd_mtm) {
- if (Date.now() - w.lrd_mtm > 970) {
- fpsHUD.textContent = "FPS: " + w.fps;
- }
- }
- setTimeout(showFPS, 30);
- }
- // UPDATE LOOP
- function updateLoop() {
- setGraphics();
- setHighScore();
- if (w.playing) {
- if (positionHUD) {
- positionHUD.textContent = "X: " + (~~w.view_xx || 0) + " Y: " + (~~w.view_yy || 0);
- }
- if (inpIP && w.bso && currentIP != w.bso.ip + ":" + w.bso.po) {
- currentIP = w.bso.ip + ":" + w.bso.po;
- inpIP.value = currentIP;
- if (ipHUD) {
- ipHUD.textContent = "Server: " + currentIP;
- }
- }
- } else {
- positionHUD.textContent = "";
- fpsHUD.textContent = "";
- }
- setTimeout(updateLoop, 1000);
- }
- // START
- init();
- })(window);
Add Comment
Please, Sign In to add comment