Toradorable Skin Changer

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. To use, press "C" in game to cycle between different animations.

当前为 2016-11-15 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Toradorable Skin Changer
  3. // @version 1.2.10
  4. // @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. To use, press "C" in game to cycle between different animations.
  5.  
  6. // @author Toradorable
  7. // @match http://alis.io/*
  8. // @require https://greasyfork.org/scripts/24858-dancing-cat-animation-for-toradorable-skin-changer/code/Dancing%20Cat%20Animation%20for%20Toradorable%20Skin%20Changer.js
  9. // @grant none
  10. // @namespace http://tampermonkey.net/
  11. // ==/UserScript==
  12.  
  13. // To use, press "C" in game to cycle between different animations. Animation being used is displayed on the right sidebar.
  14.  
  15. // 1st press turns animation on, 2nd press turns it off and selects the next animation,
  16. // 3rd press turns the animation on and so on.
  17.  
  18. // NOTE: Anything after two slashes ("//") or inbetween a "/*" and a "*/" are comments, they do nothing and can be safely removed
  19.  
  20. // This is my Toradorable skinchanger script with most hackery removed.
  21. // 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.
  22.  
  23. /* NOTE: To Add more animations, appended to the list below.
  24. * The first element in the skin array is the display time in milliseconds. 1000 milliseconds = 1 second,
  25. * Second element is the url to display.
  26. * Format:
  27. { name: "Replace With Name Of Your Animation", // This will be displayed in the sidebar to the right of the screen
  28. skin: [
  29. HowLongToShowFirstImageInMilliseconds, "replace/with/url/for/1st.img",
  30. HowLongToShowSeccondImageInMilliseconds, "url/for/2nd.img",
  31. etcetera, "etcetera",
  32. ]}
  33. * Look in the skinList for examples.
  34. */
  35.  
  36. /*
  37. * Skin Variables
  38. */
  39.  
  40. // Skin Lists
  41. var defaultspeed=100;
  42. var skinList = (typeof skinList === 'object') ? skinList : [];
  43. skinList.push({name:"Toradorable",
  44. skin: [
  45. // Display time
  46. // in
  47. // Milliseconds, "Url"
  48. 500, "https://s22.postimg.org/jha3867up/image.png",
  49. 500, "https://s22.postimg.org/jrhlrimgx/image.png",
  50. 500, "https://s22.postimg.org/6xjjy691d/image.png",
  51. 500, "https://s22.postimg.org/idpyw7n7l/Ra2.png",
  52. 500, "https://s22.postimg.org/inxhfk1tt/exclam.png",
  53. 2000, "https://s18.postimg.org/tl8xraeux/Taiga_square.png"
  54. ]}
  55. );
  56. // indexes
  57. var skinidx=0;
  58. var currentskinidx=0;
  59. var lagout_i=0;
  60. // Activation Status
  61. var skinChangerWanted = false;
  62. var skinChanger = false;
  63.  
  64. var FakeSkinWanted=false;
  65. var DoStealSkin=false;
  66. var DoShareSkin=false;
  67. // Auto Join Games when Dead
  68. //var autoJoinGame = true;
  69. window.autoJoinGame=true;
  70. var refreshSkinTimeout;
  71. var defaultspeed=100;
  72. var lagout_speed=30;
  73. var FakeSkinPredictable = false;
  74.  
  75. var LastXY=[0,0];
  76. var testHasRestarted=0;
  77. var FailCount=0;
  78.  
  79. var TargetsLastSkin;
  80. var CurrentSkin;
  81. var SharedSkin;
  82.  
  83. var EVERYONE={};
  84.  
  85. /*
  86. * Setup Custome Web Elements
  87. */
  88.  
  89. var overlays2=document.getElementById("overlays2");
  90. var mipmapNode = document.getElementById("mipmapNode");
  91. var chatboxInput=document.getElementById("input_box2");
  92.  
  93.  
  94. var SkinTargetType = chatboxInput.cloneNode(true);
  95. SkinTargetType.name="Skin Target Type:";
  96. SkinTargetType.id="SkinTargetType";
  97. SkinTargetType.value="Standby"; // Theft, Swap, Push
  98. SkinTargetType.placeholder="Skin Target Type:";
  99. SkinTargetType.style.cssText = document.defaultView.getComputedStyle(chatboxInput, "").cssText;
  100. SkinTargetType.style.width="200px";
  101. SkinTargetType.style.right="9px";
  102. SkinTargetType.style.bottom="250px";
  103. SkinTargetType.style.position="absolute";
  104. overlays2.insertBefore(SkinTargetType, overlays2.lastChild);
  105. //overlays2.insertBefore(StealSkinBox, overlays2.lastChild);
  106.  
  107. var SkinListBox = document.createElement("select"); //StealSkinBox.cloneNode(true);
  108. SkinListBox.name="Selected Skin:";
  109. SkinListBox.id="SelectedSkinElm";
  110. SkinListBox.value=""; // Theft, Swap, Push
  111. SkinListBox.placeholder="No Animation Selected";
  112. SkinListBox.style.cssText = document.defaultView.getComputedStyle(chatboxInput, "").cssText;
  113. SkinListBox.style.width="200px";
  114. SkinListBox.style.right="9px";
  115. SkinListBox.style.bottom="210px";
  116. SkinListBox.style.position="absolute";
  117.  
  118. overlays2.insertBefore(SkinListBox, overlays2.lastChild);
  119.  
  120. for (var i = 0; i < skinList.length; i++) {
  121. var option = document.createElement("option");
  122. //option.style.cssText = document.defaultView.getComputedStyle(chatboxInput, "").cssText;
  123. option.value = i;
  124. option.text = skinList[i].name;
  125. SkinListBox.appendChild(option);
  126. }
  127. SkinListBox.onchange=function(event){ skinidx=event.target.value ; haveUsedSkin=false; };
  128.  
  129.  
  130.  
  131. /*
  132. * Setup Hotkeys
  133. * 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.
  134. */
  135. var hotKeyTable = document.getElementById("hotkey_table");
  136. var hotkeyMappingREV={};
  137. var tmphotkeyMapping=JSON.parse(getLocalStorage("hotkeyMapping"));
  138. for (var prop in tmphotkeyMapping) {
  139. hotkeyMappingREV[tmphotkeyMapping[prop]]=prop;
  140. }
  141.  
  142. function AddHotKey(hk) {
  143. var hkdefault = {
  144. id: "hk_change_my_hotkey_id",
  145. defaultHotkey: "",
  146. key: null,
  147. description: "Change My Description",
  148. keyDown: null,
  149. keyUp: null,
  150. type: "NORMAL"
  151. };
  152. hk = Object.assign(hkdefault,hk);
  153. if (! hk.key || hk.key === null) hk.key = hotkeyMappingREV[hk.id];
  154. if (! hk.key || hk.key === null) hk.key = hk.defaultHotkey;
  155. var hk_element = hotKeyTable.lastChild.cloneNode(true);
  156. hk_element.children[0].dataset.hotkeyid = hk.id;
  157. hk_element.children[0].innerHTML=hk.key;
  158. hk_element.children[1].innerHTML=hk.description;
  159. hk_element.children[2].innerHTML="/";
  160. console.log("Adding Hotkey: " + hk);
  161. hotKeyTable.appendChild(hk_element);
  162. hotkeyConfig[hk.id]= {
  163. defaultHotkey: hk.defaultHotkey,
  164. name: hk.description,
  165. keyDown: hk.keyDown,
  166. type: hk.type
  167. };
  168. hotkeyMapping[hk.key] = hk.id;
  169. return hk_element;
  170. }
  171.  
  172.  
  173.  
  174. function UpdateTargetBox() {
  175. if (skinChanger && DoShareSkin && DoStealSkin) {
  176. SkinTargetType.value="SwappingSkins";
  177. }
  178. else if (DoShareSkin && DoStealSkin) {
  179. SkinTargetType.value="SwappingSkins(NoAnimate)";
  180. }
  181. else if (skinChanger && DoShareSkin) {
  182. SkinTargetType.value="SharingSkin";
  183. }
  184. else if (DoShareSkin) {
  185. SkinTargetType.value="SharingSkin(NoAnimate)";
  186. }
  187. else if (DoStealSkin) {
  188. SkinTargetType.value="StealingSkin";
  189. }
  190. else if (skinChanger) {
  191. SkinTargetType.value="AnimatedSkin";
  192. }
  193. else {
  194. SkinTargetType.value="Standby";
  195. }
  196. }
  197.  
  198. /*
  199. var hk_AutoStealNearbySkin = AddHotKey({
  200. id: "hk_AutoStealNearbySkin",
  201. defaultHotkey: "M",
  202. description: "Start/Stop Auto-Stealing Nearby Skin",
  203. keyDown: function() { }
  204. });
  205. */
  206. var hk_ReconnectToServer = AddHotKey({
  207. id: "hk_ReconnectToServer",
  208. defaultHotkey: "L",
  209. description: "Reconnect to Server",
  210. keyDown: function() {
  211. connect(myApp.getCurrentPartyCode());
  212. RefreshSkinIn(1200);
  213. }
  214. });
  215. function NextSkin() {
  216. skinidx++;
  217. if(skinidx >= skinList.length) {skinidx = 0;}
  218. SkinListBox.selectedIndex =skinidx;
  219. }
  220. function PrevSkin() {
  221. skinidx--;
  222. if(skinidx < 0) {skinidx = skinList.length - 1;}
  223. SkinListBox.selectedIndex =skinidx;
  224. }
  225. var haveUsedSkin=false;
  226. var hk_CycleSkinRotator = AddHotKey({
  227. id: "hk_CycleSkinRotator",
  228. defaultHotkey: "C",
  229. description: "Cycle Skin Rotator",
  230. keyDown: function() {
  231. if (skinChangerWanted && !skinChanger) {
  232. RefreshSkin(0,true);
  233. //LagOnce();
  234. } else if(skinChangerWanted) {
  235. skinChangerWanted=false;
  236. skinChanger=false;
  237. if (haveUsedSkin) NextSkin();
  238. } else {
  239. skinChangerWanted=true;
  240. skinChanger=true;
  241. //if (haveUsedSkin) NextSkin();
  242. AutoChangeSkin();
  243. }
  244. UpdateTargetBox();
  245. }
  246. });
  247. //myApp.refreshHotkeySettingPage();
  248.  
  249. //myApp.restoreSetting();
  250.  
  251. myApp.setUpHotKeyConfigPage();
  252.  
  253. /*********************
  254. * Generic Functions *
  255. *********************/
  256.  
  257.  
  258. function isNumeric(n) {
  259. return !isNaN(parseFloat(n)) && isFinite(n);
  260. }
  261.  
  262. function Print(msg) {
  263. console.log(msg);
  264. }
  265.  
  266.  
  267. /******************
  268. * Global Overrides
  269. ******************/
  270. //Function override. Allow sending messages when dead
  271. myApp["onDead"] = function() {
  272. isJoinedGame = false;
  273. $(".btn-spectate")["prop"]("disabled", false);
  274. $("#nick")["prop"]("disabled", false);
  275. $(".nav")["show"]();
  276. // Auto Respawn
  277. if (window.autoJoinGame) setNick(document.getElementById('nick').value);
  278. //conn["leaveRoom"](myApp["getRoom"]())
  279. }
  280.  
  281.  
  282. /*****************
  283. ** Custom Hot Keys
  284. ******************/
  285.  
  286. const keycodes={
  287. backspace:8, tab:9, enter:13,
  288. shift:16, ctrl:17, alt:18,
  289. pause_break:19, capslock:20, escape:27,
  290. space:32, pageup:33, pagedown:34,
  291. end:35, home:36, leftarrow:37,
  292. uparrow:38, rightarrow:39, downarrow:40,
  293. insert:45, delete:46,
  294. 0:48, 1:49, 2:50, 3:51,
  295. 4:52, 5:53, 6:54, 7:55,
  296. 8:56, 9:57, a:65, b:66,
  297. c:67, d:68, e:69, f:70,
  298. g:71, h:72, i:73, j:74,
  299. k:75, l:76, m:77, n:78,
  300. o:79, p:80, q:81, r:82,
  301. s:83, t:84, u:85, v:86,
  302. w:87, x:88, y:89, z:90
  303. };
  304.  
  305. window.addEventListener('keydown', keydown);
  306. function keydown(e) {
  307. var chatArea=$("#chatboxArea2");
  308. var chatIsFocused=$("#input_box2").is(':focus') || $("#LieAsElm").is(':focus') || $("#StealSkinElm").is(':focus');
  309. /*if(e.keyCode === keycodes.c && !(chatIsFocused)) {
  310. if (skinChangerWanted && !skinChanger) {
  311. RefreshSkin(0,true);
  312. //LagOnce();
  313. } else if(skinChangerWanted) {
  314. skinChangerWanted=false;
  315. skinChanger=false;
  316. } else {
  317. skinChangerWanted=true;
  318. skinChanger=true;
  319. skinidx++;
  320. if(skinidx >= skinList.length) {skinidx = 0;}
  321. AutoChangeSkin();
  322. }
  323. }
  324. else */ if(e.keyCode === 27) {
  325. skinChanger = false;
  326. DoStealSkin=false;
  327. amfakedead=false;
  328. DoShareSkin=false;
  329. //temporary workaround to StealSkin/FakeSkin/ HotKey "M" Problem
  330. $("#overlays")["show"]();
  331. }
  332. /*else if(e.keyCode === keycodes.l && !(chatIsFocused)) {
  333. //naservers();
  334. connect(myApp.getCurrentPartyCode());
  335. }*/
  336. else if(e.keyCode === keycodes.q && !(chatIsFocused)) {
  337. Lagloop(50);
  338. }
  339. /*else if(e.keyCode === keycodes.m && !(chatIsFocused)) {
  340. skinChanger=false;
  341. if (FakeSkinWanted && !DoStealSkin) {
  342. RefreshSkin(0,true);
  343. //LagOnce();
  344. } else if(FakeSkinWanted) {
  345. FakeSkinWanted=false;
  346. DoStealSkin=false;
  347. } else {
  348. FakeSkinWanted=true;
  349. DoStealSkin=true;
  350. FakeSkin();
  351. }
  352. }*/
  353. /*else if (e.keyCode === keycodes.n && !chatIsFocused) {
  354. LieAs.value=GetNearestCell()[1];
  355. StealSkinBox.value=GetNearestSkinnedCell()[1];
  356. }*/
  357. /*else if((e.keyCode === keycodes.space || e.keyCode === keycodes.t) && !IsDoingFireork && !($("#chatboxArea2").is(":focus"))) {
  358. fireworkidx=0;
  359. Firework();
  360. }*/
  361. }
  362.  
  363. // FIXME Im not sure what I was doing here
  364. function HasRestarted() {
  365. if (testHasRestarted >=5) {
  366. testHasRestarted=0;
  367. } else {
  368. testHasRestarted++;
  369. return false;
  370. }
  371. var myCell;
  372. try {
  373. if(typeof getCell != 'function') throw "GetCell is NotAFunc";
  374. myCell=getCell();
  375. if(myCell === undefined) throw "GetCell Returned null";
  376. if(myCell[0] === undefined) throw "CellDataEmpty";
  377. if(myCell[0].x === undefined) throw "Cell has no X";
  378. FailCount=0;
  379. }
  380. catch(err) {
  381. console.log(err," ",FailCount);
  382. myCell=null;
  383. FailCount++;
  384. }
  385. finally {
  386. if (FailCount >= 5) return true;
  387. else if (FailCount !== 0) return false;
  388. myCell=myCell[0];
  389. }
  390. if (LastXY[0] != myCell.x || LastXY[1] != myCell.y) {
  391. LastXY=[myCell.x,myCell.y];
  392. return false;
  393. }
  394. var LB = getLB();
  395. if (LB.length != 9) return false;
  396. for (var i=0; i < 8; i++) { // Leaderboard 1-8 should be named RESTART
  397. if (LB[i].name != "RESTART") return false;
  398. }
  399. // Leaderboard 9 should be named ALIS.IO
  400. if (LB[8].name != "ALIS.IO") return false;
  401. return true;
  402. }
  403.  
  404.  
  405. /*************************
  406. * Skin Changing Functions
  407. *************************/
  408.  
  409. /*
  410. * Change Your Skin
  411. */
  412. function ChangeSkinTo(skin=CurrentSkin,displaylocal=true) {
  413. document.getElementById('skinurl').value = skin;
  414. //setNick(document.getElementById('nick').value);
  415. socket.emit("playerUpdated", {
  416. "action": "update",
  417. "displayName": playerDetailsByIdentifier[nodeList[0][1] + nodeList[0][6]].displayName,
  418. "socketRoom": playerDetailsByIdentifier[nodeList[0][1] + nodeList[0][6]].socketRoom,
  419. "identifier": playerDetailsByIdentifier[nodeList[0][1] + nodeList[0][6]].identifier,
  420. "url": skin,
  421. "nick": playerDetailsByIdentifier[nodeList[0][1] + nodeList[0][6]].nick,
  422. "team": playerDetailsByIdentifier[nodeList[0][1] + nodeList[0][6]].team,
  423. "token": playerDetailsByIdentifier[nodeList[0][1] + nodeList[0][6]].token
  424. });
  425. nodeList[0][5]=skin;
  426. if (displaylocal) {
  427. playerDetailsByIdentifier[nodeList[0][1] + nodeList[0][6]].url=skin;
  428. }
  429. CurrentSkin=skin;
  430. }
  431.  
  432.  
  433. // Refresh Skin unctions
  434.  
  435. function RefreshSkinCancel() {
  436. if (refreshSkinTimeout) {
  437. clearTimeout(refreshSkinTimeout);
  438. }
  439. }
  440. function RefreshSkinIn(timeout,FailCount,StartStopped) {
  441. // RefreshSkinCancel();
  442. if (FailCount) {
  443. refreshSkinTimeout = setTimeout( function(){ RefreshSkin(FailCount,StartStopped); }, timeout );
  444. }
  445. else {
  446. refreshSkinTimeout = setTimeout( RefreshSkin, timeout );
  447. }
  448. }
  449.  
  450.  
  451. function RefreshSkin(FailCount=0,StartStopped=false) {
  452. Print("Refreshing Skin");
  453. var hasRestarted=HasRestarted();
  454. if((!isJoinedGame) || hasRestarted ) {
  455. //skinChanger=false;
  456. if (hasRestarted) {
  457. //naservers();
  458. console.log("Leaderboard indicates a restart occured. Reconnecting to server.");
  459. connect(myApp.getCurrentPartyCode());
  460. // If the above stops working, try respawn();
  461. //respawn();
  462. }
  463. console.log("We are dead. Our final score was",getHighestScore()/100,". Respawning.");
  464. RefreshSkinCancel();
  465. refreshSkinTimeout=setTimeout(function(){setNick(document.getElementById('nick').value); RefreshSkin(FailCount+1);}, 1200*(FailCount+1) );
  466. return;
  467. }
  468. /*if(FakeSkinWanted) {
  469. // skinChanger=false;
  470. if(StartStopped) {
  471. DoStealSkin=true;
  472. FakeSkin();
  473. }
  474. // FakeSkin();
  475. }*/
  476. if(skinChangerWanted) {
  477. //DoStealSkin=false;
  478. if(StartStopped && !FakeSkinWanted) {
  479. skinChanger=true;
  480. ChangeSkinTo();
  481. }
  482. AutoChangeSkin(FailCount);
  483. }
  484. else if (StartStopped) {
  485. var curskin=skinList[skinidx].skin;
  486. if(currentskinidx >= curskin.length) {currentskinidx = 0;}
  487. var skinSpeed=curskin[currentskinidx];
  488. ChangeSkinTo(curskin[currentskinidx+1]);
  489. }
  490. UpdateTargetBox();
  491. }
  492.  
  493. function AutoChangeSkin(FailCount=0){
  494. if(skinChanger) {
  495. if(skinidx >= skinList.length) {skinidx = 0;}
  496. haveUsedSkin=true;
  497. var curskin=skinList[skinidx].skin;
  498. if(currentskinidx >= curskin.length) {currentskinidx = 0;}
  499. var skinSpeed=curskin[currentskinidx];
  500. //if(!FakeSkinWanted) {
  501. ChangeSkinTo(curskin[currentskinidx+1]);
  502. //}
  503. /*if (DoShareSkin) {
  504. ShareSkin(curskin[currentskinidx+1]);
  505. }*/
  506. currentskinidx+=2;
  507. if(currentskinidx >= curskin.length) {currentskinidx = 0;}
  508. RefreshSkinIn(skinSpeed);
  509. }
  510. }
  511.  
  512.  
  513. // Skin updates are sent whenever...
  514. // action: "join", The Player pushes play
  515. // action: "join", setNick is called
  516. // action: "update", A different player joins the game (to let them download the skin)
  517. addJS_Node(isNumeric);
  518.  
  519.  
  520.  
  521. // Method for overloading global functions directly (functions in objects dont need this)
  522. function addJS_Node (text, s_URL, funcToRun, runOnLoad) {
  523. var D = document;
  524. var scriptNode = D.createElement ('script');
  525. if (runOnLoad) {
  526. scriptNode.addEventListener ("load", runOnLoad, false);
  527. }
  528. scriptNode.type = "text/javascript";
  529. if (text) scriptNode.textContent = text;
  530. if (s_URL) scriptNode.src = s_URL;
  531. if (funcToRun) scriptNode.textContent = '(' + funcToRun.toString() + ')()';
  532. var targ = D.getElementsByTagName ('head')[0] || D.body || D.documentElement;
  533. targ.appendChild (scriptNode);
  534. }
  535.  
  536.  
  537.