Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  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.1
  6. // @date 2018-05-20
  7. // @namespace FunnyPocketBook
  8. // @include https://*/game.php?village=*&screen=place&try=confirm
  9. // ==/UserScript==
  10.  
  11. let inputMs;
  12. let input;
  13. let delay;
  14. const showArrTimeTr = document.createElement("tr"); // Create button called btn as a link because any button causes the attack to launch
  15. const showArrTimeTd = document.createElement("td");
  16. const pEle = document.getElementById("troop_confirm_go"); // Button comes after this element
  17. const btn = document.createElement("a"); // Create button called btn as a link because any button causes the attack to launch
  18. btn.setAttribute("id", "arrTime"); // Set ID of btn
  19. btn.setAttribute("class", "btn"); // Set ID of btn
  20. btn.setAttribute("style", "cursor:pointer;"); // Set cursor to pointer
  21. pEle.parentNode.insertBefore(btn, pEle.nextElementSibling); // Place btn after pEle
  22. const t = document.createTextNode("Ustaw czas dotarcia"); // btn has this text
  23. btn.appendChild(t); // Append text to btn
  24.  
  25. btn.onclick = function() {
  26. "use strict";
  27. let time = document.getElementsByClassName("relative_time")[0].textContent.slice(-8);
  28. let lalau = document.getElementById("date_arrival");
  29. input = prompt("Please enter desired arrival time", time);
  30. inputMs = parseInt(prompt("Please enter approximate milliseconds", "800"));
  31. delay = parseInt(delayTime) + parseInt(inputMs);
  32. showArrTimeTr.appendChild(showArrTimeTd);
  33. lalau.parentNode.parentNode.insertBefore(showArrTimeTr, lalau.parentNode[1]);
  34. showArrTimeTd.innerHTML = "Set arrival: ~" + input + ":" + inputMs;
  35. showArrTimeTd.setAttribute("colspan", "2");
  36. showArrTimeTd.setAttribute("id", "showArrTime");
  37. };
  38.  
  39. let delayTime = parseInt(localStorage.delayTime);
  40. if(delayTime == null) {
  41. delayTime = 0;
  42. localStorage.delayTime = JSON.stringify(delayTime);
  43. }
  44.  
  45. // Create okay button to save delay
  46. const delayTr = document.createElement("tr");
  47. const delayTd1 = document.createElement("td");
  48. const delayTd2 = document.createElement("td");
  49. const parent1 = document.querySelector("#date_arrival"); // Cell of relative_time
  50. delayTr.appendChild(delayTd1);
  51. delayTr.appendChild(delayTd2);
  52. parent1.parentNode.parentNode.insertBefore(delayTr, parent1.parentNode[1]); // Insert tablerow as last cell
  53. delayTd1.innerHTML = "Offset";
  54. delayTd2.innerHTML = "<input id = 'delayInput' value = " + delayTime + " style = 'width: 50%'></input> <a id = 'delayButton' class = 'btn'>OK</a>";
  55.  
  56. //debugger;
  57. $("#delayButton").click(function() {
  58. delayTime = parseInt($("#delayInput").val());
  59. localStorage.delayTime = JSON.stringify(delayTime);
  60. delay = parseInt(delayTime) + parseInt(inputMs); // setTimeout time
  61. if(delay < 0) {
  62. delay = 0;
  63. }
  64. })
  65.  
  66. let arrival;
  67. setInterval(function retime() {
  68. "use strict";
  69. arrival = document.getElementsByClassName("relative_time")[0].textContent;
  70. if(arrival.slice(-8) === input) {
  71. setTimeout(function() {document.getElementById("troop_confirm_go").click();}, delay);
  72. }
  73. }, 1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement