Siege Incoming Counter

Counts incoming troops to sieges sorted by type of attack

  1. // ==UserScript==
  2. // @name Siege Incoming Counter
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Counts incoming troops to sieges sorted by type of attack
  6. // @author acv-98
  7. // @match https://*.grepolis.com/game/*
  8. // @run-at document-end
  9. // @icon https://wiki.en.grepolis.com/images/f/f9/Town_fight.png
  10. // @grant none
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14.  
  15. (function() {
  16. 'use strict';
  17. function addIncomings() {
  18. $('.report_side_defender').each(function () {
  19. $(this).find('h4').html(
  20. "Movements of troops: " +
  21. "<img src='https://gpen.innogamescdn.com/images/game/unit_overview/attack_sea.png' style='vertical-align: middle; margin-right: 5px;' />" +
  22. $(this).find('.attack_sea').length +
  23. "<img src='https://gpen.innogamescdn.com/images/game/unit_overview/attack_land.png' style='vertical-align: middle; margin-left: 10px; margin-right: 5px;' />" +
  24. $(this).find('.attack_land').length +
  25. "<img src='https://gpen.innogamescdn.com/images/game/unit_overview/support.png' style='vertical-align: middle; margin-left: 10px; margin-right: 5px;' />" +
  26. $(this).find('.support').length
  27. );
  28. });
  29. }
  30.  
  31. function waitForKeyElements (
  32. selectorTxt, /* Required: The jQuery selector string that
  33. specifies the desired element(s).
  34. */
  35. actionFunction, /* Required: The code to run when elements are
  36. found. It is passed a jNode to the matched
  37. element.
  38. */
  39. bWaitOnce, /* Optional: If false, will continue to scan for
  40. new elements even after the first match is
  41. found.
  42. */
  43. iframeSelector /* Optional: If set, identifies the iframe to
  44. search.
  45. */
  46. ) {
  47. var targetNodes, btargetsFound;
  48. if (typeof iframeSelector == "undefined")
  49. targetNodes = $(selectorTxt);
  50. else
  51. targetNodes = $(iframeSelector).contents ()
  52. .find (selectorTxt);
  53. if (targetNodes && targetNodes.length > 0) {
  54. btargetsFound = true;
  55. /*--- Found target node(s). Go through each and act if they
  56. are new.
  57. */
  58. targetNodes.each ( function () {
  59. var jThis = $(this);
  60. var alreadyFound = jThis.data ('alreadyFound') || false;
  61. if (!alreadyFound) {
  62. //--- Call the payload function.
  63. var cancelFound = actionFunction (jThis);
  64. if (cancelFound)
  65. btargetsFound = false;
  66. else
  67. jThis.data ('alreadyFound', true);
  68. }
  69. } );
  70. }
  71. else {
  72. btargetsFound = false;
  73. }
  74. //--- Get the timer-control variable for this selector.
  75. var controlObj = waitForKeyElements.controlObj || {};
  76. var controlKey = selectorTxt.replace (/[^\w]/g, "_");
  77. var timeControl = controlObj [controlKey];
  78. //--- Now set or clear the timer as appropriate.
  79. if (btargetsFound && bWaitOnce && timeControl) {
  80. //--- The only condition where we need to clear the timer.
  81. clearInterval (timeControl);
  82. delete controlObj [controlKey]
  83. }
  84. else {
  85. //--- Set a timer, if needed.
  86. if ( ! timeControl) {
  87. timeControl = setInterval ( function () {
  88. waitForKeyElements ( selectorTxt,
  89. actionFunction,
  90. bWaitOnce,
  91. iframeSelector
  92. );
  93. },
  94. 300
  95. );
  96. controlObj [controlKey] = timeControl;
  97. }
  98. }
  99. waitForKeyElements.controlObj = controlObj;
  100. }
  101.  
  102. waitForKeyElements (
  103. ".report_side_defender",
  104. addIncomings
  105. );
  106.  
  107. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址