// ==UserScript==
// @name Toradorable Alis.io
// @version 1.2.12
// @description A Toradorable skin changer supporting multiple animations and variable image display times, Minimizes chat lag by using a custom skin updating function, and Adds in auto/instant-respawn. Includes a UI. To use, press "C" in game to cycle between different animations.
// @author Toradorable
// @match http://alis.io/*
// @grant none
// @namespace http://tampermonkey.net/
// @require https://greasyfork.org/scripts/24894-toradorable-animator/code/Toradorable%20Animator.js
// @require https://greasyfork.org/scripts/24844-toradorable-animation-for-toradorable-skin-changer/code/Toradorable%20Animation%20for%20Toradorable%20Skin%20Changer.js
// ==/UserScript==
// To use, press "C" in game to cycle between different animations. Animation being used is displayed on the right sidebar.
// 1st press turns animation on, 2nd press turns it off and selects the next animation,
// 3rd press turns the animation on and so on.
// NOTE: Anything after two slashes ("//") or inbetween a "/*" and a "*/" are comments, they do nothing and can be safely removed
// This is my Toradorable skinchanger script with most hackery removed.
// If my full script were posted, Taiga would get ticked off from all the trolling and within 2-3 minutes I would be beaten to a pulp.
/* NOTE: To Add more animations, appended to the list below.
* The first element in the skin array is the display time in milliseconds. 1000 milliseconds = 1 second,
* Second element is the url to display.
* Format:
{ name: "Replace With Name Of Your Animation", // This will be displayed in the sidebar to the right of the screen
skin: [
HowLongToShowFirstImageInMilliseconds, "replace/with/url/for/1st.img",
HowLongToShowSeccondImageInMilliseconds, "url/for/2nd.img",
etcetera, "etcetera",
]}
* Look in the skinList for examples.
*/
// Skin Lists
if ((typeof animator !== 'object')) {
alert("animator object does not exist. be sure to add " +
"//@require https://greasyfork.org/scripts/24894-toradorable-animator/code/Toradorable%20Animator.js\n" +
"To your script");
}
var autoJoinGameContainer = document.createElement("div");
autoJoinGameContainer.class="checkbox";
var autoJoinGameLabel = document.getElementsByClassName("checkbox")[0].children[0].cloneNode(true);
document.getElementById('home').insertBefore(autoJoinGameContainer,document.getElementById("skin_row"));
autoJoinGameLabel.children[0].id="autoJoinGame";
autoJoinGameContainer.appendChild(autoJoinGameLabel);
autoJoinGameContainer.innerHTML = autoJoinGameContainer.innerHTML + ' Auto Join Game';
var autoJoinGame = document.getElementById('autoJoinGame');
autoJoinGame.checked=true;
window.animator=animator;
/* Add Animation Example
animator.addAnimation({
title: "Name Of Your Animation",
// Optional Default display time, used when/if a frame does not have a time specified.
defaultDisplayTime: 1000,
frames: [
//time: Optional display time for this frame in milliseconds,
//url: "http://Link/To/Your/Image.png",
//nick: "Optional Nick to use if applicable. Most sites do not allow you to change your nick in game."
{time: 500, url: "https://s22.postimg.org/jha3867up/image.png", nick: "To"},
{time: 500, url: "https://s22.postimg.org/jrhlrimgx/image.png", nick: "Ra"},
{time: 500, url: "https://s22.postimg.org/6xjjy691d/image.png", nick: "Do"},
{time: 500, url: "https://s22.postimg.org/idpyw7n7l/Ra2.png", nick: "Ra"},
{time: 500, url: "https://s22.postimg.org/inxhfk1tt/exclam.png", nick: "!"},
{time: 2000, url: "https://s18.postimg.org/tl8xraeux/Taiga_square.png", nick: "Toradora!"}
]
})
*
* Example of importing a skinList,
animator.importSkinList(
// First argument is a skin list array.
// Below is iWubbz's candy skinList as found on
// https://greasyfork.org/en/scripts/23677-iwubbz-candy-skin-changer/code
["http://i.imgur.com/1JQqUzR.png",
"http://i.imgur.com/VKcEy4k.png",
"http://i.imgur.com/FKsf0PC.png",
"http://i.imgur.com/zg6Oxzo.png",
"http://i.imgur.com/EPawa6H.png",
"http://i.imgur.com/NyKl8tG.png"
],
// Second argument is optional. However, I recomend setting title at the least.
//defaultDisplayTime is 1000 (1 second) by default.
//All frames will be displayed for defaultDisplayTime milliseconds.
//Use animator.addAnimation if you want different display times per frame.
{title: "iWubbz's Candy", defaultDisplayTime: 5000}
);
* ^^ Importing skin lists is as easy as stealing candy from iWubbz. ^^
*/
// Initialize UI After adding all animations
animator.site.initilaizeUI();
// Activation Status
var skinChangerWanted = false;
// Auto Join Games when Dead
//var autoJoinGame = true;
/*
* Setup Hotkeys
* FIXME: hot key saving realy does not work... It seems like it works on one part, but new values do not discard old values, causeing conflicts.
*/
var hotKeyTable = document.getElementById("hotkey_table");
var hotkeyMappingREV={};
var tmphotkeyMapping=JSON.parse(getLocalStorage("hotkeyMapping"));
for (var prop in tmphotkeyMapping) {
hotkeyMappingREV[tmphotkeyMapping[prop]]=prop;
}
function AddHotKey(hk) {
var hkdefault = {
id: "hk_change_my_hotkey_id",
defaultHotkey: "",
key: null,
description: "Change My Description",
keyDown: null,
keyUp: null,
type: "NORMAL"
};
hk = Object.assign(hkdefault,hk);
if (! hk.key || hk.key === null) hk.key = hotkeyMappingREV[hk.id];
if (! hk.key || hk.key === null) hk.key = hk.defaultHotkey;
var hk_element = hotKeyTable.lastChild.cloneNode(true);
hk_element.children[0].dataset.hotkeyid = hk.id;
hk_element.children[0].innerHTML=hk.key;
hk_element.children[1].innerHTML=hk.description;
hk_element.children[2].innerHTML="/";
console.log("Adding Hotkey: " + hk);
hotKeyTable.appendChild(hk_element);
hotkeyConfig[hk.id]= {
defaultHotkey: hk.defaultHotkey,
name: hk.description,
keyDown: hk.keyDown,
type: hk.type
};
hotkeyMapping[hk.key] = hk.id;
return hk_element;
}
/*
var hk_AutoStealNearbySkin = AddHotKey({
id: "hk_AutoStealNearbySkin",
defaultHotkey: "M",
description: "Start/Stop Auto-Stealing Nearby Skin",
keyDown: function() { }
});
*/
var hk_ReconnectToServer = AddHotKey({
id: "hk_ReconnectToServer",
defaultHotkey: "L",
description: "Reconnect to Server",
keyDown: function() {
connect(myApp.getCurrentPartyCode());
RefreshSkinIn(1200);
}
});
function NextSkin() {
skinidx++;
if(skinidx >= skinList.length) {skinidx = 0;}
SkinListBox.selectedIndex =skinidx;
}
function PrevSkin() {
skinidx--;
if(skinidx < 0) {skinidx = skinList.length - 1;}
SkinListBox.selectedIndex =skinidx;
}
var haveUsedSkin=false;
var hk_CycleSkinRotator = AddHotKey({
id: "hk_CycleSkinRotator",
defaultHotkey: "C",
description: "Cycle Skin Rotator",
keyDown: function() {
if (animator.isPlaying) {
animator.pauseAnimation();
animator.nextAnimation();
//LagOnce();
} else {
animator.playAnimation();
}
//UpdateTargetBox();
}
});
//myApp.refreshHotkeySettingPage();
//myApp.restoreSetting();
myApp.setUpHotKeyConfigPage();
/*********************
* Generic Functions *
*********************/
function isNumeric(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
function Print(msg) {
console.log(msg);
}
/******************
* Global Overrides
******************/
//Function override. Allow sending messages when dead
myApp["onDead"] = function() {
isJoinedGame = false;
$(".btn-spectate")["prop"]("disabled", false);
$("#nick")["prop"]("disabled", false);
$(".nav")["show"]();
// Auto Respawn
if (autoJoinGame.checked) setNick(document.getElementById('nick').value);
// Below forces you out of chat when dead.
// I hated when I lost the message I was typing because someone ate me when I sent it,
// So I disabled it.
// conn["leaveRoom"](myApp["getRoom"]());
}
/*****************
** Custom Hot Keys
******************/
const keycodes={
backspace:8, tab:9, enter:13,
shift:16, ctrl:17, alt:18,
pause_break:19, capslock:20, escape:27,
space:32, pageup:33, pagedown:34,
end:35, home:36, leftarrow:37,
uparrow:38, rightarrow:39, downarrow:40,
insert:45, delete:46,
0:48, 1:49, 2:50, 3:51,
4:52, 5:53, 6:54, 7:55,
8:56, 9:57, a:65, b:66,
c:67, d:68, e:69, f:70,
g:71, h:72, i:73, j:74,
k:75, l:76, m:77, n:78,
o:79, p:80, q:81, r:82,
s:83, t:84, u:85, v:86,
w:87, x:88, y:89, z:90,
multiply: 106, add: 107, subtract: 109,
decimalpoint: 110, divide: 111,
f1: 112, f2: 113, f3: 114,
f4: 115, f5: 116, f6: 117,
f7: 118, f8: 119, f9: 120,
f10: 121, f11: 122, f12: 123,
numlock: 144, scrolllock: 145,
semicolon: 186, equalsign: 187,
comma: 188, dash: 189, period: 190,
forwardslash: 191, graveaccent: 192,
openbracket: 219, backslash: 220,
closebraket: 221, singlequote: 222
};
window.addEventListener('keydown', keydown);
function keydown(e) {
var chatArea=$("#chatboxArea2");
var chatIsFocused=$("#input_box2").is(':focus') || $("#LieAsElm").is(':focus') || $("#StealSkinElm").is(':focus');
/*if(e.keyCode === keycodes.c && !(chatIsFocused)) {
if (skinChangerWanted && !skinChanger) {
RefreshSkin(0,true);
//LagOnce();
} else if(skinChangerWanted) {
skinChangerWanted=false;
skinChanger=false;
} else {
skinChangerWanted=true;
skinChanger=true;
skinidx++;
if(skinidx >= skinList.length) {skinidx = 0;}
AutoChangeSkin();
}
}
else */ if(e.keyCode === 27) {
animator.pauseAnimation();
//temporary workaround to StealSkin/FakeSkin/ HotKey "M" Problem
$("#overlays")["show"]();
}
else if(e.keyCode === keycodes.add && !(chatIsFocused)) {
//naservers();
animator.speedMultiplier += 0.5;
} else if(e.keyCode === keycodes.subtract && !(chatIsFocused)) {
//naservers();
animator.speedMultiplier -= 0.5;
} else if(e.keyCode === keycodes[0] && !(chatIsFocused)) {
//naservers();
animator.speedMultiplier = 1;
}
/*else if(e.keyCode === keycodes.l && !(chatIsFocused)) {
//naservers();
connect(myApp.getCurrentPartyCode());
}*/
/*else if((e.keyCode === keycodes.space || e.keyCode === keycodes.t) && !IsDoingFireork && !($("#chatboxArea2").is(":focus"))) {
fireworkidx=0;
Firework();
}*/
}
// FIXME Im not sure what I was doing here
function HasRestarted() {
if (testHasRestarted >=5) {
testHasRestarted=0;
} else {
testHasRestarted++;
return false;
}
var myCell;
try {
if(typeof getCell != 'function') throw "GetCell is NotAFunc";
myCell=getCell();
if(myCell === undefined) throw "GetCell Returned null";
if(myCell[0] === undefined) throw "CellDataEmpty";
if(myCell[0].x === undefined) throw "Cell has no X";
FailCount=0;
}
catch(err) {
console.log(err," ",FailCount);
myCell=null;
FailCount++;
}
finally {
if (FailCount >= 5) return true;
else if (FailCount !== 0) return false;
myCell=myCell[0];
}
if (LastXY[0] != myCell.x || LastXY[1] != myCell.y) {
LastXY=[myCell.x,myCell.y];
return false;
}
var LB = getLB();
if (LB.length != 9) return false;
for (var i=0; i < 8; i++) { // Leaderboard 1-8 should be named RESTART
if (LB[i].name != "RESTART") return false;
}
// Leaderboard 9 should be named ALIS.IO
if (LB[8].name != "ALIS.IO") return false;
return true;
}
/*************************
* Skin Changing Functions
*************************/
/*
* Change Your Skin
*/
function ChangeSkinTo(skin=CurrentSkin,displaylocal=true) {
document.getElementById('skinurl').value = skin;
//setNick(document.getElementById('nick').value);
socket.emit("playerUpdated", {
"action": "update",
"displayName": playerDetailsByIdentifier[nodeList[0][1] + nodeList[0][6]].displayName,
"socketRoom": playerDetailsByIdentifier[nodeList[0][1] + nodeList[0][6]].socketRoom,
"identifier": playerDetailsByIdentifier[nodeList[0][1] + nodeList[0][6]].identifier,
"url": skin,
"nick": playerDetailsByIdentifier[nodeList[0][1] + nodeList[0][6]].nick,
"team": playerDetailsByIdentifier[nodeList[0][1] + nodeList[0][6]].team,
"token": playerDetailsByIdentifier[nodeList[0][1] + nodeList[0][6]].token
});
nodeList[0][5]=skin;
if (displaylocal) {
playerDetailsByIdentifier[nodeList[0][1] + nodeList[0][6]].url=skin;
}
CurrentSkin=skin;
}
// Skin updates are sent whenever...
// action: "join", The Player pushes play
// action: "join", setNick is called
// action: "update", A different player joins the game (to let them download the skin)
// Method for overloading global functions directly (functions in objects dont need this)
function addJS_Node (text, s_URL, funcToRun, runOnLoad) {
var D = document;
var scriptNode = D.createElement ('script');
if (runOnLoad) {
scriptNode.addEventListener ("load", runOnLoad, false);
}
scriptNode.type = "text/javascript";
if (text) scriptNode.textContent = text;
if (s_URL) scriptNode.src = s_URL;
if (funcToRun) scriptNode.textContent = '(' + funcToRun.toString() + ')()';
var targ = D.getElementsByTagName ('head')[0] || D.body || D.documentElement;
targ.appendChild (scriptNode);
}