Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2020
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Unbenanntes Skript 854154
  3. // @version 1
  4. // @include https://de*.die-staemme.de/*game.php?village=*&screen=info_village&id=*
  5. // @grant GM.openInTab
  6. // ==/UserScript==
  7.  
  8.  
  9. // create button
  10. var btn = document.createElement('button');
  11. with(btn) {
  12. setAttribute('value', 'click me!');
  13. setAttribute('type', 'button');
  14. setAttribute('style', 'width: 20px; height: 20px;');
  15. }
  16.  
  17. btn.addEventListener("click", openSendTroopsTab);
  18.  
  19. // append btn
  20. document.getElementById('template_form').appendChild(btn);
  21.  
  22.  
  23. function sleep(ms) {
  24. return new Promise(resolve => setTimeout(resolve, ms));
  25. }
  26.  
  27.  
  28. async function openSendTroopsTab(){
  29. var tabsToOpen = 4;
  30.  
  31. var link = document.getElementById('send_troops').href;
  32. // var newTab = GM.openInTab(link, true);
  33.  
  34. // create all windows and add them to array
  35. var allWindows = []
  36. for(let i = 0; i < tabsToOpen; i++) {
  37. setTimeout(function() {
  38. var newWindow = window.open(link);
  39. allWindows.push(newWindow)
  40. }, 50);
  41. }
  42.  
  43. // wait for windows to finish loading
  44. await sleep(400);
  45.  
  46. // for each window
  47. for(let i = 0; i < tabsToOpen; i++){
  48. let currentWindow = allWindows[i];
  49.  
  50. // set troop values
  51. currentWindow.document.getElementById('unit_input_spear').value = 1;
  52.  
  53. // click attack button
  54. currentWindow.document.getElementById('target_attack').click();
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement