Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
113
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 ataki test
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description try to take over the world!
  6. // @author You
  7. // @match https://www.youtube.com/results?search_query=offset+w+informatyce
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. /*
  12. * Created by philno
  13. * 27.07.2017
  14. *
  15. * Will try to send unit movements / commands at the specified time.
  16. * The script does NOT check if you need to relog. No guarantees for accuracy.
  17. * You want to send the attack via place, not in the map popup!
  18. * You need to be on the confirm screen (script will only click 'OK' to send the movement/command).
  19. * Script in action: https://streamable.com/pkheg
  20. */
  21.  
  22. var sendAt;
  23. var baseInterval;
  24. var precInterval;
  25. var utc_diff = server_utc_diff * 1000;
  26. var counter = -1;
  27. var offset = 20;
  28.  
  29. function main() {
  30. let now = getNow();
  31. console.log(now);
  32.  
  33. let date = new Date(Date.now() + utc_diff);
  34. date = date.toISOString().replace('T', ' ').replace('Z', '');
  35. sendAt = prompt('Send movement at (YYYY-MM-DD hh:mm:ss.SSS):', date);
  36. if (sendAt == null || sendAt.length < 7) {
  37. return;
  38. }
  39. // make sure date is parsed as UTC.
  40. let sendAtString = sendAt;
  41. sendAt += 'Z';
  42. sendAt = new Date(new Date(sendAt).getTime() - Timing.offset_to_server - (offset / 2));
  43. console.log(sendAt);
  44.  
  45.  
  46. let millis = sendAt - now;
  47. console.log('Will be sent in (minutes): ' + (millis / 1000 / 60));
  48. baseInterval = setInterval(timeBase, 2000);
  49.  
  50. if (baseInterval) {
  51. var fragment = createElem('<h3>Movement will be sent at ' + sendAtString + ' </h3><a id="workingIndicator"></a>');
  52. document.getElementById('content_value').appendChild(fragment);
  53. }
  54. }
  55. main();
  56.  
  57. function timeBase() {
  58. let now = getNow();
  59. let diff = sendAt - now;
  60.  
  61. if (diff <= 6000) {
  62. // enter high precision mode.
  63. clearInterval(baseInterval);
  64. document.getElementById('workingIndicator').innerHTML = 'High precision mode active.';
  65. precInterval = setInterval(timeAccurate, offset);
  66. return;
  67. }
  68.  
  69. if (document.getElementById('workingIndicator')) {
  70. if (counter == 0) {
  71. document.getElementById('workingIndicator').innerHTML = '.';
  72. } else if (counter == 1) {
  73. document.getElementById('workingIndicator').innerHTML = '..';
  74. } else if (counter >= 2) {
  75. document.getElementById('workingIndicator').innerHTML = '...';
  76. counter = -1;
  77. }
  78. counter++;
  79. }
  80. }
  81.  
  82. function timeAccurate() {
  83. let now = getNow();
  84. let diff = sendAt - now;
  85.  
  86. if (diff <= 0) {
  87. sendMovement();
  88. clearInterval(precInterval);
  89. }
  90. }
  91.  
  92. function sendMovement() {
  93. document.getElementById('troop_confirm_go').click();
  94. }
  95.  
  96. function getNow() {
  97. return new Date(Timing.getCurrentServerTime() + utc_diff);
  98. }
  99.  
  100. function createElem(htmlStr) {
  101. var frag = document.createDocumentFragment(),
  102. temp = document.createElement('div');
  103. temp.innerHTML = htmlStr;
  104. while (temp.firstChild) {
  105. frag.appendChild(temp.firstChild);
  106. }
  107. return frag;
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement