MouseHunt - Hween 2021 Trick/Treat map colour coder

Color codes mice on trick/treat maps according to type

  1. // ==UserScript==
  2. // @name MouseHunt - Hween 2021 Trick/Treat map colour coder
  3. // @author in59te & Warden Slayer
  4. // @namespace https://greasyfork.org/en/users/739524-in59te
  5. // @version 1.5
  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. // @include https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js
  10. // ==/UserScript==
  11.  
  12. const standardMice = [
  13. "Grey Recluse",
  14. "Cobweb",
  15. "Teenage Vampire",
  16. "Zombot Unipire",
  17. "Candy Cat",
  18. "Candy Goblin",
  19. "Shortcut",
  20. "Tricky Witch",
  21. "Sugar Rush"
  22. ];
  23. const jackoMice = [
  24. "Spirit Light",
  25. "Gourdborg",
  26. "Pumpkin Hoarder",
  27. "Trick",
  28. "Treat",
  29. "Wild Chainsaw",
  30. "Maize Harvester"
  31. ];
  32. const boneMice = [
  33. "Creepy Marionette",
  34. "Dire Lycan",
  35. "Grave Robber",
  36. "Hollowhead",
  37. "Mousataur Priestess",
  38. "Sandmouse",
  39. "Titanic Brain-Taker",
  40. "Tomb Exhumer"
  41. ];
  42. const pgMice = [
  43. "Admiral Arrrgh",
  44. "Captain Cannonball",
  45. "Ghost Pirate Queen",
  46. "Gourd Ghoul",
  47. "Scorned Pirate",
  48. "Spectral Butler",
  49. "Spectral Swashbuckler"
  50. ];
  51. const screamMice = [
  52. "Baba Gaga",
  53. "Bonbon Gummy Globlin",
  54. "Hollowed",
  55. "Hollowed Minion",
  56. "Swamp Thang"
  57. ];
  58.  
  59. const hunterColor = ["#ffffff", "#ffffff", "#ffffff", "#ffffff", "#ffffff"];
  60. var numHunters = 0;
  61. function hunterColorize() {
  62. document.querySelectorAll(".treasureMapRootView-subTab:not(.active)")[0].click(); //swap between Goals and Hunters
  63. let hunters = document.querySelectorAll(".treasureMapView-componentContainer");
  64. const list_of_cheese = [];
  65. for (let i = 0; i < hunters.length; i++) {
  66. list_of_cheese.push(hunters[i].children[2].title);
  67. }
  68. //console.log(list_of_cheese);
  69. numHunters = hunters.length;
  70. document.querySelectorAll(".treasureMapRootView-subTab:not(.active)")[0].click();
  71. for (let i = 0; i < numHunters; i++) {
  72. if (list_of_cheese[i] == "Monterey Jack-O-Lantern") {
  73. hunterColor[i] = "#f9a645";
  74. }
  75. else if (list_of_cheese[i] == "Bonefort Cheese") {
  76. hunterColor[i] = "#bfbfbf";
  77. }
  78. else if (list_of_cheese[i] == "Polter-Geitost") {
  79. hunterColor[i] = "#5d9fce";
  80. }
  81. else if (list_of_cheese[i] == "Scream Cheese") {
  82. hunterColor[i] = "#5ae031";
  83. }
  84. else {
  85. hunterColor[i] = "#fff935";
  86. }
  87. }
  88. //console.log(hunterColor);
  89. }
  90.  
  91. function colorize() {
  92.  
  93. let stdColor = "#fff935"; // yellow
  94. let stdCount = 0;
  95. let boneColor = "#bfbfbf"; // white
  96. let boneCount = 0;
  97. let screamColor = "#5ae031"; // green
  98. let screamCount = 0;
  99. let pgColor = "#5d9fce"; // blue
  100. let pgCount = 0;
  101. let jackoColor = "#f9a645"; // orange
  102. let jackoCount = 0;
  103. const greyColor = "#949494";
  104.  
  105. const isChecked =
  106. localStorage.getItem("highlightPref") === "uncaught-only" ? true : false;
  107. const isCheckedStr = isChecked ? "checked" : "";
  108.  
  109. if (
  110. document.querySelectorAll(".treasureMapView-goals-group-goal").length === 0
  111. ) {
  112. return;
  113. }
  114.  
  115. document.querySelectorAll(".treasureMapView-goals-group-goal").forEach(el => {
  116. el.querySelector("span").style = "color: black; font-size: 11px;";
  117.  
  118. const mouseName = el.querySelector(".treasureMapView-goals-group-goal-name")
  119. .textContent;
  120.  
  121. if (standardMice.indexOf(mouseName) > -1) {
  122. el.style.backgroundColor = stdColor;
  123. if (el.className.indexOf(" complete ") < 0) {
  124. stdCount++;
  125. } else {
  126. if (isChecked) el.style.backgroundColor = "white";
  127. }
  128. } else if (jackoMice.indexOf(mouseName) > -1) {
  129. el.style.backgroundColor = jackoColor;
  130. if (el.className.indexOf(" complete ") < 0) {
  131. jackoCount++;
  132. } else {
  133. if (isChecked) el.style.backgroundColor = "white";
  134. }
  135. } else if (boneMice.indexOf(mouseName) > -1) {
  136. el.style.backgroundColor = boneColor;
  137. if (el.className.indexOf(" complete ") < 0) {
  138. boneCount++;
  139. } else {
  140. if (isChecked) el.style.backgroundColor = "white";
  141. }
  142. } else if (screamMice.indexOf(mouseName) > -1) {
  143. el.style.backgroundColor = screamColor;
  144. if (el.className.indexOf(" complete ") < 0) {
  145. screamCount++;
  146. } else {
  147. if (isChecked) el.style.backgroundColor = "white";
  148. }
  149. } else if (pgMice.indexOf(mouseName) > -1) {
  150. el.style.backgroundColor = pgColor;
  151. if (el.className.indexOf(" complete ") < 0) {
  152. pgCount++;
  153. } else {
  154. if (isChecked) el.style.backgroundColor = "white";
  155. }
  156. }
  157. });
  158.  
  159. stdColor = stdCount > 0 ? stdColor : greyColor;
  160. jackoColor = jackoCount > 0 ? jackoColor : greyColor;
  161. boneColor = boneCount > 0 ? boneColor : greyColor;
  162. pgColor = pgCount > 0 ? pgColor : greyColor;
  163. screamColor = screamCount > 0 ? screamColor : greyColor;
  164.  
  165. // Remove existing GWH Map related elements before proceeding
  166. document.querySelectorAll(".tsitu-gwh-map").forEach(el => el.remove());
  167.  
  168. const masterDiv = document.createElement("div");
  169. masterDiv.className = "tsitu-gwh-map";
  170. masterDiv.style =
  171. "display: inline-flex; margin-bottom: 10px; width: 100%; text-align: center; line-height: 1.5; overflow: hidden";
  172. const spanStyle =
  173. "; width: auto; padding: 5px; font-weight: bold; font-size: 12.75px; text-shadow: 0px 0px 11px white";
  174.  
  175. const stdSpan = document.createElement("span");
  176. stdSpan.classList.add("stdSpan");
  177. stdSpan.style = "background-color: " + stdColor + spanStyle;
  178. stdSpan.innerHTML = "Std<br>" + stdCount;
  179.  
  180. const jackoSpan = document.createElement("span");
  181. jackoSpan.classList.add("jackoSpan");
  182. jackoSpan.style = "background-color: " + jackoColor + spanStyle;
  183. jackoSpan.innerHTML = "Jack<br>" + jackoCount;
  184.  
  185. const boneSpan = document.createElement("span");
  186. boneSpan.classList.add("boneSpan");
  187. boneSpan.style = "background-color: " + boneColor + spanStyle;
  188. boneSpan.innerHTML = "Bone<br>" + boneCount;
  189.  
  190. const pgSpan = document.createElement("span");
  191. pgSpan.classList.add("pgSpan");
  192. pgSpan.style = "background-color: " + pgColor + spanStyle;
  193. pgSpan.innerHTML = "PG<br>" + pgCount;
  194.  
  195. const screamSpan = document.createElement("span");
  196. screamSpan.classList.add("screamSpan");
  197. screamSpan.style = "background-color: " + screamColor + spanStyle;
  198. screamSpan.innerHTML = "Scream<br>" + screamCount;
  199.  
  200. // Highlight uncaught only feature
  201. const highlightLabel = document.createElement("label");
  202. highlightLabel.htmlFor = "tsitu-highlight-box";
  203. highlightLabel.innerText = "Highlight uncaught mice only";
  204.  
  205. const highlightBox = document.createElement("input");
  206. highlightBox.type = "checkbox";
  207. highlightBox.name = "tsitu-highlight-box";
  208. highlightBox.style.verticalAlign = "middle";
  209. highlightBox.checked = isChecked;
  210. highlightBox.addEventListener("click", function () {
  211. if (highlightBox.checked) {
  212. localStorage.setItem("highlightPref", "uncaught-only");
  213. } else {
  214. localStorage.setItem("highlightPref", "all");
  215. }
  216. hunterColorize();
  217. colorize();
  218. });
  219.  
  220. const highlightDiv = document.createElement("div");
  221. highlightDiv.className = "tsitu-gwh-map";
  222. highlightDiv.style = "float: right; position: relative; z-index: 1";
  223. highlightDiv.appendChild(highlightBox);
  224. highlightDiv.appendChild(highlightLabel);
  225.  
  226. // Assemble masterDiv
  227. masterDiv.appendChild(stdSpan);
  228. masterDiv.appendChild(jackoSpan);
  229. masterDiv.appendChild(boneSpan);
  230. masterDiv.appendChild(pgSpan);
  231. masterDiv.appendChild(screamSpan);
  232.  
  233. // Inject into DOM
  234. const insertEl = document.querySelector(
  235. ".treasureMapView-leftBlock .treasureMapView-block-content"
  236. );
  237. if (
  238. insertEl &&
  239. document.querySelector(
  240. ".treasureMapRootView-header-navigation-item.tasks.active" // On "Active Maps"
  241. )
  242. ) {
  243. insertEl.insertAdjacentElement("afterbegin", highlightDiv);
  244. insertEl.insertAdjacentElement("afterbegin", masterDiv);
  245. }
  246.  
  247. var canvas = [];
  248. var div = document.getElementsByClassName("treasureMapView-hunter-wrapper mousehuntTooltipParent");
  249.  
  250. for (var i=0; i<div.length; i++){
  251. canvas[i] = document.createElement('canvas');
  252. canvas[i].id = "hunter-canvas";
  253. canvas[i].style = "; bottom: 0px; left: 0px; position: absolute; width: 15px; height: 15px; background: " + hunterColor[i] + "; border: 1px solid black";
  254. div[i].appendChild(canvas[i]);
  255. }
  256.  
  257. // "Goals" button
  258. document.querySelector("[data-type='show_goals']").onclick = function () {
  259. colorize();
  260. };
  261. }
  262.  
  263. // Listen to XHRs, opening a map always at least triggers board.php
  264. const originalOpen = XMLHttpRequest.prototype.open;
  265. XMLHttpRequest.prototype.open = function () {
  266. this.addEventListener("load", function () {
  267. const chestEl = document.querySelector(
  268. ".treasureMapView-mapMenu-rewardName"
  269. );
  270.  
  271. if (chestEl) {
  272. const chestName = chestEl.textContent;
  273. if (
  274. chestName &&
  275. ((chestName.indexOf("Halloween") >= 0) ||
  276. (chestName.indexOf("Undead") >= 0))
  277. ) {
  278. hunterColorize();
  279. colorize();
  280. }
  281. }
  282. });
  283. originalOpen.apply(this, arguments);
  284. };
  285.  
  286. //Warden added this (waves)
  287. $(document).on('click', '.stdSpan', function() {
  288. hg.utils.TrapControl.setBait(114).go();
  289. });
  290. $(document).on('click', '.jackoSpan', function() {
  291. hg.utils.TrapControl.setBait(3305).go();
  292. });
  293. $(document).on('click', '.boneSpan', function() {
  294. hg.utils.TrapControl.setBait(3306).go();
  295. });
  296. $(document).on('click', '.pgSpan', function() {
  297. hg.utils.TrapControl.setBait(3307).go();
  298. });
  299. $(document).on('click', '.screamSpan', function() {
  300. hg.utils.TrapControl.setBait(3308).go();
  301. });