Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2014
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.54 KB | None | 0 0
  1. /**
  2. * Created by polish on 16.10.14.
  3. */
  4. var attackNames = ["clean", "noble_0", "noble_1", "noble_2"];
  5. var attackFrames = [];
  6. var newWindow;
  7. var cleanUnits = {
  8. "unit_input_spear": 0,
  9. "unit_input_sword": 0,
  10. "unit_input_axe": 200,
  11. "unit_input_archer": 0,
  12. "unit_input_spy": 0,
  13. "unit_input_light": 0,
  14. "unit_input_marcher": 0,
  15. "unit_input_heavy": 0,
  16. "unit_input_ram": 0,
  17. "unit_input_catapult": 0,
  18. "unit_input_knight": 0,
  19. "unit_input_snob": 1
  20. };
  21. var nobleUnits = {
  22. "unit_input_spear": 0,
  23. "unit_input_sword": 0,
  24. "unit_input_axe": 200,
  25. "unit_input_archer": 0,
  26. "unit_input_spy": 0,
  27. "unit_input_light": 0,
  28. "unit_input_marcher": 0,
  29. "unit_input_heavy": 0,
  30. "unit_input_ram": 0,
  31. "unit_input_catapult": 0,
  32. "unit_input_knight": 0,
  33. "unit_input_snob": 1
  34. };
  35.  
  36. Element.prototype.remove = function () {
  37. this.parentElement.removeChild(this);
  38. };
  39.  
  40. NodeList.prototype.remove = HTMLCollection.prototype.remove = function () {
  41. for (var i = 0, len = this.length; i < len; i++) {
  42. if (this[i] && this[i].parentElement) {
  43. this[i].parentElement.removeChild(this[i]);
  44. }
  45. }
  46. };
  47.  
  48.  
  49. function onFramesLoaded(frame) {
  50. }
  51.  
  52. function hideFrame(frameName) {
  53. frameName.style.visibility = frameName.style.visibility == "hidden" ? "" : "hidden";
  54. }
  55.  
  56. function confirmAttack(frameName) {
  57. var frameDoc = frameName.contentWindow.document;
  58. frameDoc.getElementById("target_attack").click();
  59. }
  60.  
  61. function sendAttack(frameName) {
  62. console.log(new Date().getUTCMilliseconds());
  63. var frameDoc = frameName.contentWindow.document;
  64. frameDoc.getElementById("troop_confirm_go").click();
  65.  
  66. }
  67.  
  68. function setTroops(frameName) {
  69. var frameDoc = frameName.contentWindow.document;
  70. var units;
  71. if (frameName.id == "clean") {
  72. units = cleanUnits;
  73. } else {
  74. units = nobleUnits;
  75. }
  76. for (var m in units) {
  77. frameDoc.getElementById(m).value = units[m];
  78. }
  79. }
  80.  
  81. function setAllTroops() {
  82. attackNames.map(function (frameName) {
  83. setTroops(getFrameForName(frameName));
  84. });
  85. }
  86.  
  87. function confirmAllAttacks() {
  88. attackNames.map(function (frameName) {
  89. confirmAttack(getFrameForName(frameName));
  90. });
  91. }
  92.  
  93. function sendAllAttacks() {
  94. if (new Date().getUTCMilliseconds() > 100 && new Date().getUTCMilliseconds() < 150) {
  95. attackNames.map(function (frameName) {
  96. sendAttack(getFrameForName(frameName));
  97. });
  98. }
  99. }
  100.  
  101. function getFrameForName(frameName) {
  102. return document.getElementById(frameName);
  103. }
  104.  
  105. function getURLParameter(name) {
  106. return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search) || [, ""])[1].replace(/\+/g, '%20')) || null
  107. }
  108.  
  109. function run() {
  110. newWindow = window.open('about:blank', 'Synchro by Polish', 'width=800,height=730,scrollbars=yes');
  111. var doc = newWindow.document;
  112. doc.url = 'D';
  113. doc.open();
  114. doc.write('<html>');
  115. doc.write('<title> Synchro by Polish </title>');
  116. doc.write('<body>');
  117. var target = getURLParameter("target");
  118. var village = getURLParameter("village");
  119. attackNames.map(function (frameName) {
  120. doc.write("" +
  121. "<button onclick='setAllTroops(" + frameName + ");' class='setAllTroops_'>Set all troops</button>" +
  122. "<button onclick='confirmAllAttacks(" + frameName + ");' class='confirmAllAttacks_'>Confirm all attacks</button>" +
  123. "<button onclick='sendAllAttacks(" + frameName + ");' class='sendAllAttacks_'>Send all attacks</button>" +
  124. "<div> " +
  125. "<h1>" + frameName + "</h1>" +
  126. "<button onclick='hideFrame(" + frameName + ");' class='toggle_'" + frameName + ">Show/Hide</button>" +
  127. "<button onclick='setTroops(" + frameName + ");' class='setTroops_'" + frameName + ">Set troops</button>" +
  128. "<button onclick='confirmAttack(" + frameName + ");' class='confirmAttack_'" + frameName + ">Confirm</button>" +
  129. "<button onclick='sendAttack(" + frameName + ");' class='sendAttack_'" + frameName + ">Send attack</button>" +
  130. "" +
  131. "</div>")
  132. doc.write(
  133. '<iframe id=' + frameName + ' src="http://pl86.plemiona.pl/game.php?village=' + village + '&screen=place&target=' + target + '" width="100%" height="25%">' +
  134. '</iframe>'
  135. );
  136. });
  137. doc.write('</body>');
  138. doc.write('</html>');
  139. doc.close();
  140.  
  141. attackNames.map(function (item) {
  142. hideFrame(doc.getElementById(item));
  143. });
  144.  
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement