Wonders Score Counters

Counts the wonders score for each alliance by additionning the level of each wonders.

  1. // ==UserScript==
  2. // @name Wonders Score Counters
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description Counts the wonders score for each alliance by additionning the level of each wonders.
  6. // @author Draub
  7. // @match https://*.grepolis.com/game/*
  8. // @run-at document-end
  9. // @icon https://www.prod.antoinebouard.com/wondersscorecounters/wonders.png
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13.  
  14. (function() {
  15. 'use strict';
  16. function countWondersScore() {
  17. // Tableau des points par niveau de merveilles
  18. const levelWondersScore = new Array(0,1,3,6,10,15,21,28,36,45,55);
  19. // Selection de l'écran des merveilles
  20. const wonderdiv = document.getElementsByClassName("world_wonders_info");
  21. // Sélection du tableau
  22. const table = wonderdiv[0].querySelector('table');
  23.  
  24. /// Sélection de l'entête du tableau
  25. const headerRow = table.querySelector('thead tr');
  26.  
  27. // Création d'une nouvelle cellule d'entête pour la colonne "Score"
  28. const scoreHeader = document.createElement('th');
  29. scoreHeader.textContent = 'Score';
  30.  
  31. // Ajout de la classe "header_data" à la nouvelle cellule d'entête
  32. scoreHeader.classList.add('header_data');
  33.  
  34. // Ajout de la nouvelle cellule d'entête à la fin de l'entête
  35. headerRow.appendChild(scoreHeader);
  36.  
  37.  
  38. // Sélection de toutes les lignes du tableau, sauf la première (entête)
  39. const rows = table.querySelectorAll('tbody tr');
  40.  
  41. // Boucle sur chaque ligne du tableau
  42. rows.forEach(row => {
  43. // Récupération de la valeur de data-rank pour chaque ligne
  44. const rank = parseInt(row.getAttribute('data-rank'));
  45.  
  46. // Sélection de toutes les colonnes de la ligne ayant l'attribut data-level
  47. const columnsWithDataLevel = row.querySelectorAll('td[data-level]');
  48.  
  49. // Initialisation de la somme à 0
  50. let sum = 0;
  51.  
  52. // Boucle sur chaque colonne avec data-level pour additionner leur valeur
  53. columnsWithDataLevel.forEach(column => {
  54. // Récupération de la valeur de data-level et conversion en entier
  55. const level = parseInt(column.getAttribute('data-level'));
  56.  
  57. // Ajout de la valeur de data-level à la somme
  58. sum += levelWondersScore[level];
  59. });
  60.  
  61. // Création d'une nouvelle colonne pour afficher le score
  62. const scoreColumn = document.createElement('td');
  63. scoreColumn.textContent = sum; // Ajout du score calculé dans la colonne
  64.  
  65. // Ajout de la classe "score" à la nouvelle colonne
  66. scoreColumn.classList.add('score');
  67.  
  68. // Ajout de la nouvelle colonne à la fin de la ligne actuelle
  69. row.appendChild(scoreColumn);
  70. });
  71. }
  72.  
  73. function waitForKeyElements (
  74. selectorTxt, /* Required: The jQuery selector string that
  75. specifies the desired element(s).
  76. */
  77. actionFunction, /* Required: The code to run when elements are
  78. found. It is passed a jNode to the matched
  79. element.
  80. */
  81. bWaitOnce, /* Optional: If false, will continue to scan for
  82. new elements even after the first match is
  83. found.
  84. */
  85. iframeSelector /* Optional: If set, identifies the iframe to
  86. search.
  87. */
  88. ) {
  89. var targetNodes, btargetsFound;
  90.  
  91. if (typeof iframeSelector == "undefined")
  92. targetNodes = $(selectorTxt);
  93. else
  94. targetNodes = $(iframeSelector).contents ()
  95. .find (selectorTxt);
  96.  
  97. if (targetNodes && targetNodes.length > 0) {
  98. btargetsFound = true;
  99. /*--- Found target node(s). Go through each and act if they
  100. are new.
  101. */
  102. targetNodes.each ( function () {
  103. var jThis = $(this);
  104. var alreadyFound = jThis.data ('alreadyFound') || false;
  105.  
  106. if (!alreadyFound) {
  107. //--- Call the payload function.
  108. var cancelFound = actionFunction (jThis);
  109. if (cancelFound)
  110. btargetsFound = false;
  111. else
  112. jThis.data ('alreadyFound', true);
  113. }
  114. } );
  115. }
  116. else {
  117. btargetsFound = false;
  118. }
  119.  
  120. //--- Get the timer-control variable for this selector.
  121. var controlObj = waitForKeyElements.controlObj || {};
  122. var controlKey = selectorTxt.replace (/[^\w]/g, "_");
  123. var timeControl = controlObj [controlKey];
  124.  
  125. //--- Now set or clear the timer as appropriate.
  126. if (btargetsFound && bWaitOnce && timeControl) {
  127. //--- The only condition where we need to clear the timer.
  128. clearInterval (timeControl);
  129. delete controlObj [controlKey]
  130. }
  131. else {
  132. //--- Set a timer, if needed.
  133. if ( ! timeControl) {
  134. timeControl = setInterval ( function () {
  135. waitForKeyElements ( selectorTxt,
  136. actionFunction,
  137. bWaitOnce,
  138. iframeSelector
  139. );
  140. },
  141. 300
  142. );
  143. controlObj [controlKey] = timeControl;
  144. }
  145. }
  146. waitForKeyElements.controlObj = controlObj;
  147. }
  148.  
  149. waitForKeyElements (
  150. ".world_wonders_info",
  151. countWondersScore
  152. );
  153.  
  154. })();

QingJ © 2025

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