MouseHunt - Hween 2021 Trick/Treat map colour coder

Color codes mice on trick/treat maps according to type

当前为 2021-10-14 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name MouseHunt - Hween 2021 Trick/Treat map colour coder
  3. // @author in59te
  4. // @namespace https://greasyfork.org/en/users/739524-in59te
  5. // @version 1.0
  6. // @description Color codes mice on trick/treat maps according to type
  7. // @match http://www.mousehuntgame.com/*
  8. // @match https://www.mousehuntgame.com/*
  9. // ==/UserScript==
  10.  
  11. const standardMice = [
  12. "Grey Recluse",
  13. "Cobweb",
  14. "Teenage Vampire",
  15. "Zombot Unipire",
  16. "Candy Cat",
  17. "Candy Goblin",
  18. "Shortcut",
  19. "Tricky Witch",
  20. "Sugar Rush"
  21. ];
  22. const jackoMice = [
  23. "Spirit Light",
  24. "Gourdborg",
  25. "Pumpkin Hoarder",
  26. "Trick",
  27. "Treat",
  28. "Wild Chainsaw",
  29. "Maize Harvester"
  30. ];
  31. const boneMice = [
  32. "Creepy Marionette",
  33. "Dire Lycan",
  34. "Grave Robber",
  35. "Hollowhead",
  36. "Mousataur Priestess",
  37. "Sandmouse",
  38. "Titanic Brain-Taker",
  39. "Tomb Exhumer"
  40. ];
  41. const pgMice = [
  42. "Admiral Arrrgh",
  43. "Captain Cannonball",
  44. "Ghost Pirate Queen",
  45. "Gourd Ghoul",
  46. "Scorned Pirate",
  47. "Spectral Butler",
  48. "Spectral Swashbuckler"
  49. ];
  50. const screamMice = [
  51. "Baba Gaga",
  52. "Bonbon Gummy Goblin",
  53. "Hollowed",
  54. "Hollowed Minion",
  55. "Swamp Thang"
  56. ];
  57.  
  58.  
  59.  
  60. function colorize() {
  61. let stdColor = "#fff935"; // yellow
  62. let stdCount = 0;
  63. let boneColor = "ffffff"; // white
  64. let boneCount = 0;
  65. let screamColor = "#5ae031"; // green
  66. let screamCount = 0;
  67. let pgColor = "#5d9fce"; // blue
  68. let pgCount = 0;
  69. let jackoColor = "#f9a645"; // orange
  70. let jackoCount = 0;
  71. const greyColor = "#949494";
  72.  
  73. const isChecked =
  74. localStorage.getItem("highlightPref") === "uncaught-only" ? true : false;
  75. const isCheckedStr = isChecked ? "checked" : "";
  76.  
  77. if (
  78. document.querySelectorAll(".treasureMapView-goals-group-goal").length === 0
  79. ) {
  80. return;
  81. }
  82.  
  83. document.querySelectorAll(".treasureMapView-goals-group-goal").forEach(el => {
  84. el.querySelector("span").style = "color: black; font-size: 11px;";
  85.  
  86. const mouseName = el.querySelector(".treasureMapView-goals-group-goal-name")
  87. .textContent;
  88.  
  89. if (standardMice.indexOf(mouseName) > -1) {
  90. el.style.backgroundColor = stdColor;
  91. if (el.className.indexOf(" complete ") < 0) {
  92. stdCount++;
  93. } else {
  94. if (isChecked) el.style.backgroundColor = "white";
  95. }
  96. } else if (jackoMice.indexOf(mouseName) > -1) {
  97. el.style.backgroundColor = jackoColor;
  98. if (el.className.indexOf(" complete ") < 0) {
  99. jackoCount++;
  100. } else {
  101. if (isChecked) el.style.backgroundColor = "white";
  102. }
  103. } else if (boneMice.indexOf(mouseName) > -1) {
  104. el.style.backgroundColor = boneColor;
  105. if (el.className.indexOf(" complete ") < 0) {
  106. boneCount++;
  107. } else {
  108. if (isChecked) el.style.backgroundColor = "white";
  109. }
  110. } else if (screamMice.indexOf(mouseName) > -1) {
  111. el.style.backgroundColor = screamColor;
  112. if (el.className.indexOf(" complete ") < 0) {
  113. screamCount++;
  114. } else {
  115. if (isChecked) el.style.backgroundColor = "white";
  116. }
  117. } else if (pgMice.indexOf(mouseName) > -1) {
  118. el.style.backgroundColor = pgColor;
  119. if (el.className.indexOf(" complete ") < 0) {
  120. pgCount++;
  121. } else {
  122. if (isChecked) el.style.backgroundColor = "white";
  123. }
  124. }
  125. });
  126.  
  127. stdColor = stdCount > 0 ? stdColor : greyColor;
  128. jackoColor = jackoCount > 0 ? jackoColor : greyColor;
  129. boneColor = boneCount > 0 ? boneColor : greyColor;
  130. pgColor = pgCount > 0 ? pgColor : greyColor;
  131. screamColor = screamCount > 0 ? screamColor : greyColor;
  132.  
  133. // Remove existing GWH Map related elements before proceeding
  134. document.querySelectorAll(".tsitu-gwh-map").forEach(el => el.remove());
  135.  
  136. const masterDiv = document.createElement("div");
  137. masterDiv.className = "tsitu-gwh-map";
  138. masterDiv.style =
  139. "display: inline-flex; margin-bottom: 10px; width: 100%; text-align: center; line-height: 1.5; overflow: hidden";
  140. const spanStyle =
  141. "; width: auto; padding: 5px; font-weight: bold; font-size: 12.75px; text-shadow: 0px 0px 11px white";
  142.  
  143. const stdSpan = document.createElement("span");
  144. stdSpan.style = "background-color: " + stdColor + spanStyle;
  145. stdSpan.innerHTML = "Std<br>" + stdCount;
  146.  
  147. const jackoSpan = document.createElement("span");
  148. jackoSpan.style = "background-color: " + jackoColor + spanStyle;
  149. jackoSpan.innerHTML = "Jack<br>" + jackoCount;
  150.  
  151. const boneSpan = document.createElement("span");
  152. boneSpan.style = "background-color: " + boneColor + spanStyle;
  153. boneSpan.innerHTML = "Bone<br>" + boneCount;
  154.  
  155. const pgSpan = document.createElement("span");
  156. pgSpan.style = "background-color: " + pgColor + spanStyle;
  157. pgSpan.innerHTML = "PG<br>" + pgCount;
  158.  
  159. const screamSpan = document.createElement("span");
  160. screamSpan.style = "background-color: " + screamColor + spanStyle;
  161. screamSpan.innerHTML = "Scream<br>" + screamCount;
  162.  
  163. // Highlight uncaught only feature
  164. const highlightLabel = document.createElement("label");
  165. highlightLabel.htmlFor = "tsitu-highlight-box";
  166. highlightLabel.innerText = "Highlight uncaught mice only";
  167.  
  168. const highlightBox = document.createElement("input");
  169. highlightBox.type = "checkbox";
  170. highlightBox.name = "tsitu-highlight-box";
  171. highlightBox.style.verticalAlign = "middle";
  172. highlightBox.checked = isChecked;
  173. highlightBox.addEventListener("click", function () {
  174. if (highlightBox.checked) {
  175. localStorage.setItem("highlightPref", "uncaught-only");
  176. } else {
  177. localStorage.setItem("highlightPref", "all");
  178. }
  179. colorize();
  180. });
  181.  
  182. const highlightDiv = document.createElement("div");
  183. highlightDiv.className = "tsitu-gwh-map";
  184. highlightDiv.style = "float: right; position: relative; z-index: 1";
  185. highlightDiv.appendChild(highlightBox);
  186. highlightDiv.appendChild(highlightLabel);
  187.  
  188. // Assemble masterDiv
  189. masterDiv.appendChild(stdSpan);
  190. masterDiv.appendChild(jackoSpan);
  191. masterDiv.appendChild(boneSpan);
  192. masterDiv.appendChild(pgSpan);
  193. masterDiv.appendChild(screamSpan);
  194.  
  195. // Inject into DOM
  196. const insertEl = document.querySelector(
  197. ".treasureMapView-leftBlock .treasureMapView-block-content"
  198. );
  199. if (
  200. insertEl &&
  201. document.querySelector(
  202. ".treasureMapRootView-header-navigation-item.tasks.active" // On "Active Maps"
  203. )
  204. ) {
  205. insertEl.insertAdjacentElement("afterbegin", highlightDiv);
  206. insertEl.insertAdjacentElement("afterbegin", masterDiv);
  207. }
  208.  
  209. // "Goals" button
  210. document.querySelector("[data-type='show_goals']").onclick = function () {
  211. colorize();
  212. };
  213. }
  214.  
  215. // Listen to XHRs, opening a map always at least triggers board.php
  216. const originalOpen = XMLHttpRequest.prototype.open;
  217. XMLHttpRequest.prototype.open = function () {
  218. this.addEventListener("load", function () {
  219. const chestEl = document.querySelector(
  220. ".treasureMapView-mapMenu-rewardName"
  221. );
  222.  
  223. if (chestEl) {
  224. const chestName = chestEl.textContent;
  225. if (
  226. chestName &&
  227. ((chestName.indexOf("Halloween Treat Treasure Chest") >= 0) ||
  228. (chestName.indexOf("Halloween Trick Treasure Chest") >= 0))
  229. ) {
  230. colorize();
  231. }
  232. }
  233. });
  234. originalOpen.apply(this, arguments);
  235. };