[GC] - Underwater Map Prizes (Discord Webhook)

Userscript that allows you to send your Underwater Map prize results to Discord

  1. // ==UserScript==
  2. // @name [GC] - Underwater Map Prizes (Discord Webhook)
  3. // @namespace https://gf.qytechs.cn/en/users/1225524-kaitlin
  4. // @match https://www.grundos.cafe/games/treasurehunt/redeemmap*
  5. // @match https://www.grundos.cafe/games/treasurehunt/?type=underwater
  6. // @license MIT
  7. // @grant GM_getValue
  8. // @grant GM_setValue
  9. // @grant GM_registerMenuCommand
  10. // @version 1.1
  11. // @author Cupkait
  12. // @require https://update.gf.qytechs.cn/scripts/485703/1319674/%5BGC%5D%20-%20Map%20Prizes%20Helper.js
  13.  
  14. // @description Userscript that allows you to send your Underwater Map prize results to Discord
  15. // @description via a webhook. Multiple webhooks are supported. If you are in a Discord server
  16. // @description and want to use this but aren't sure how, feel free to reach out! NM: Cupkait, Discord DM: kaitlin.
  17. // ==/UserScript==
  18.  
  19. // It is not recommended to change the WebHook values below. Instead, click the
  20. // menu item that shows up below this script to have it added in the right place!
  21. const webHooks = GM_getValue("webHooks", []);
  22.  
  23. GM_registerMenuCommand("Add Webhook", () => {
  24. var newWebhook = prompt("Paste one webhook URL to add to your script.\n\nIf you want to add multiple, do the one at a time.");
  25. if (newWebhook) {
  26. webHooks.push(newWebhook);
  27. GM_setValue("webHooks", webHooks);
  28. }
  29. });
  30.  
  31. const userNameMatch = /user=(.*?)"/g.exec(document.body.innerHTML);
  32. const userName = userNameMatch ? userNameMatch[1] : "A Lucky Neopian";
  33.  
  34. const itemInfo = getItemsArray();
  35. const prizeImages = $("div.center img");
  36. const imageInfo = prizeImages
  37. .map(function () {
  38. const fileName = new URL($(this).attr("src")).pathname.split("/").pop();
  39. const correspondingItem = itemInfo.find(
  40. (item) => item.fileName.toLowerCase() === fileName.toLowerCase()
  41. );
  42. return correspondingItem
  43. ? {
  44. fileName,
  45. fullImgUrl: correspondingItem.fullImgUrl,
  46. itemName: correspondingItem.itemName,
  47. itemTag: correspondingItem.itemTag,
  48. }
  49. : null;
  50. })
  51. .get();
  52.  
  53. const filteredImageInfo = imageInfo.filter((item) => item !== null);
  54. const aquaticFoodCount = filteredImageInfo.filter(
  55. (item) => item.itemTag && item.itemTag.toLowerCase() === "aquaticfood"
  56. ).length;
  57. const relicPrize = filteredImageInfo.find(
  58. (item) => item.itemTag && item.itemTag.toLowerCase() === "relic"
  59. );
  60. const relicName = relicPrize ? relicPrize.itemName : null;
  61.  
  62. const specialItem = filteredImageInfo.find(
  63. (item) => item.itemTag && item.itemTag.toLowerCase() === "special"
  64. );
  65. const brushItem = filteredImageInfo.find(
  66. (item) => item.itemTag && item.itemTag.toLowerCase() === "paintbrush"
  67. );
  68.  
  69. const specialItemName = specialItem ? specialItem.itemName : null;
  70. const specialItemImage = specialItem ? specialItem.fullImgUrl : null;
  71. const brushItemName = brushItem ? brushItem.itemName : null;
  72. const brushItemImage = brushItem ? brushItem.fullImgUrl : null;
  73.  
  74. const pointsNumber = parseInt(
  75. $("div.center p").eq(2).text().replace(/\D/g, ""),
  76. 10
  77. );
  78.  
  79. const colorMapping = {
  80. "Flask of Rainbow Fountain Water": "9295088",
  81. "Mysterious Swirly Potion": "16671195",
  82. "Irritable Genie-in-a-Bottle": "40341",
  83. };
  84.  
  85. const barColor = colorMapping[specialItemName] || "#FFFFFF"; // Default to white if not found
  86.  
  87. console.log(barColor);
  88.  
  89. const brushfalseParams = {
  90. username: "Underwater Map Prize Tracker",
  91. embeds: [
  92. {
  93. title: `${userName} just gambled on an Underwater Map!`,
  94. description: `They received ${aquaticFoodCount} random Aquatic foods, a ${relicName}, and a ${specialItemName}!`,
  95. color: barColor,
  96. footer: {
  97. text: `... and they're ${pointsNumber.toLocaleString()} neopoints richer!`,
  98. },
  99. thumbnail: {
  100. url: specialItemImage,
  101. },
  102. },
  103. ],
  104. };
  105.  
  106. const brushtrueParams = {
  107. username: "Underwater Map Prize Tracker",
  108. embeds: [
  109. {
  110. title: `${userName} just gambled on an Underwater Map!`,
  111. description: `They received a ${brushItemName}, a ${specialItemName}, a ${relicName}, and ${aquaticFoodCount} random Aquatic Foods!`,
  112. color: barColor,
  113. footer: {
  114. text: `... and they're ${pointsNumber.toLocaleString()} neopoints richer!`,
  115. },
  116. thumbnail: {
  117. url: brushItemImage,
  118. },
  119. },
  120. ],
  121. };
  122.  
  123. webHooks.forEach((webHook) => {
  124. if (aquaticFoodCount === 6) {
  125. sendMessage(brushtrueParams, webHook);
  126. } else if (aquaticFoodCount === 7) {
  127. sendMessage(brushfalseParams, webHook);
  128. } else {
  129. console.log("Map home page, not turned in.");
  130. }
  131. });
  132.  
  133. function sendMessage(params, webhook) {
  134. console.log("Webhook triggered.");
  135.  
  136. const request = new XMLHttpRequest();
  137. request.open("POST", webhook);
  138. request.setRequestHeader("Content-type", "application/json");
  139. request.send(JSON.stringify(params));
  140. }
  141.  
  142. function addWebhook() {
  143. var newWebhook = prompt(
  144. "Paste one webhook URL to add to your script.\n\nIf you want to add multiple, do one at a time."
  145. );
  146. if (newWebhook) {
  147. var webHooks = GM_getValue("webHooks", []);
  148. webHooks.push(newWebhook);
  149. GM_setValue("webHooks", webHooks);
  150. }
  151. }
  152. if (
  153. window.location.href ===
  154. "https://www.grundos.cafe/games/treasurehunt/?type=underwater"
  155. ) {
  156. const buttonArea = document.querySelector(".text-center");
  157. const buttonWrapper = document.createElement("div"); // Create a new div element
  158. var addButton = document.createElement("button");
  159. addButton.style.height = "35px"
  160. addButton.style.backgroundColor = "Navy"
  161. addButton.style.color = "White"
  162. addButton.textContent = "Add a webhook URL for Underwater Map Logging";
  163. addButton.addEventListener("click", addWebhook);
  164. buttonWrapper.appendChild(addButton); // Append the button to the div
  165. buttonArea.appendChild(buttonWrapper); // Append the div to the buttonArea
  166. }
  167.  
  168.  
  169.  

QingJ © 2025

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