[GC] - Kadoatery Feeds Logging (Discord Webhook)

Checks if feeding a kad was successful and, if it is, logs the results to pass through a Discord webhook.

当前为 2024-02-17 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name [GC] - Kadoatery Feeds Logging (Discord Webhook)
  3. // @namespace https://greasyfork.org/en/users/1225524-kaitlin
  4. // @match https://www.grundos.cafe/games/kadoatery/*
  5. // @require https://update.greasyfork.org/scripts/485575/1317118/%5BGC%5D%20-%20Kadoatery%20Details%20Helper.js
  6. // @version 1.0
  7. // @grant GM_getValue
  8. // @grant GM_setValue
  9. // @grant GM_addStyle
  10. // @license MIT
  11. // @author Cupkait
  12. // @icon https://i.imgur.com/4Hm2e6z.png
  13. // @description Checks if feeding a kad was successful and, if it is, logs the results to pass through a Discord webhook.
  14. // @description Enter/register webhooks from the kadoatery, under the left side bar.
  15. // @description Current set to send a message for every 100th kad + every relic received. Future update will make the 100th easily changeable.
  16. // ==/UserScript==
  17.  
  18. const webHooks = GM_getValue("webHooks", []);
  19. var kadHome = $("#kad_grid");
  20.  
  21.  
  22.  
  23.  
  24.  
  25. const errorPage = $(".errorpage");
  26. if (errorPage.length > 0) {
  27. const errorText = errorPage.text();
  28.  
  29. if (errorText.includes("has already been fed")) {
  30. console.log("Too slow, someone else got to that kad first.");
  31. } else if (errorText.includes("wait a bit")) {
  32. console.log("You already fed a kad, try again later.");
  33. }
  34. } else if (kadHome.length === 1) {
  35.  
  36. console.log("Home Page, not feeding yet.")
  37. } else {
  38. const details = GrabKadoatieDetails();
  39.  
  40. let reltrueParams = {
  41. username: "Kadoatery Logs",
  42. embeds: [
  43. {
  44. title: `${details.kadName} shared a special snack with ${details.userName}...`,
  45. description: `*... oh wow, a Happy Anniversary Negg!*`,
  46. color: `${details.barColor}`,
  47. author: {
  48. name: `${details.kadBlurb}`,
  49. },
  50. footer: {
  51. text: `${details.userName} has now fed ${details.kadCount} kadoaties in all`,
  52. },
  53. thumbnail: {
  54. url: `${details.kadImage}`,
  55. },
  56. },
  57. ],
  58. avatar_url: "https://i.imgur.com/4Hm2e6z.png",
  59. attachments: []
  60. };
  61.  
  62. let relfalseParams = {
  63. username: "Kadoatery Logs",
  64. embeds: [
  65. {
  66. title: `${details.userName} has fed ${details.kadCount} kadoaties in all!`,
  67. description: `What an achievement!`,
  68. color: `${details.barColor}`,
  69. author: {
  70. name: `${details.kadBlurb}`,
  71. },
  72. thumbnail: {
  73. url: `${details.kadImage}`,
  74. },
  75. },
  76. ],
  77. avatar_url: "https://i.imgur.com/4Hm2e6z.png",
  78. attachments: []
  79. };
  80.  
  81. webHooks.forEach((webHook) => {
  82. let paramsToSend;
  83.  
  84. if (details.relicStatus) {
  85. paramsToSend = reltrueParams;
  86. } else if (details.kadCount % 100 === 0) {
  87. paramsToSend = relfalseParams;
  88. } else {
  89. console.log("Fed but not sent.");
  90. return;
  91. }
  92.  
  93. sendMessage(paramsToSend, webHook);
  94. });
  95.  
  96. function sendMessage(params, webHook) {
  97. console.log("Webhook triggered.");
  98.  
  99. const request = new XMLHttpRequest();
  100. request.open("POST", webHook);
  101. request.setRequestHeader("Content-type", "application/json");
  102. request.send(JSON.stringify(params));
  103. }
  104. }
  105.  
  106. const wrapperContainer = document.createElement("div");
  107. wrapperContainer.id = "wrapContainer";
  108.  
  109. const wrapperSettings = document.createElement("button");
  110. wrapperSettings.textContent = "Kad Webhook Settings";
  111. wrapperSettings.id = "wrapSettings";
  112.  
  113. const wrapperMenu = document.createElement("div");
  114. wrapperMenu.id = "wrapMenu";
  115.  
  116. const firstButton = document.createElement("button");
  117. wrapperMenu.appendChild(firstButton);
  118. firstButton.textContent = "Add a Webhook";
  119. firstButton.id = "menubutton";
  120. $(firstButton).on("click", addWebhook);
  121.  
  122. function createWrapper() {
  123. wrapperContainer.appendChild(wrapperSettings);
  124. wrapperContainer.appendChild(wrapperMenu);
  125. $("#sb_edge").append(wrapperContainer);
  126.  
  127. $(wrapperSettings).on("click", function () {
  128. $(wrapperMenu).fadeToggle(150);
  129. });
  130. return wrapperContainer;
  131. return wrapperMenu;
  132. }
  133. GM_addStyle(`#wrapMenu {
  134. display:none;
  135. border-radius: 15px 15px 15px 0px;
  136. border-bottom: 3px solid;
  137. position: absolute;
  138. width: 200px;
  139. height: 250px;
  140. bottom: 0%;
  141. left: 100%;
  142. margin: -3px;
  143. padding: 10px;
  144. background-color: #d2d0cc;
  145. box-shadow: 5px 0 5px rgba(0, 0, 0, 0.5);
  146. }
  147. #wrapContainer {
  148. position: relative;
  149. border-bottom: 3px solid;
  150. padding: 5px 10px 5px 0px;
  151. height: 30px;
  152. width: 100%;
  153. top: 0px;
  154. left: 0px;
  155. background-color: #d2d0cc;
  156. box-shadow: 5px 0 5px rgba(0, 0, 0, 0.5);
  157. }
  158. #wrapSettings {
  159. position:relative;
  160. font-size:12px;
  161. font-weight:bold;
  162. font-family:courier;
  163. padding:0px;
  164. width:100%;
  165. height: auto;
  166. border: 1px solid rgb(204, 204, 204);
  167. cursor: pointer;
  168. background-color: transparent;
  169. }
  170. #menubutton {
  171. height:35px;
  172. width:98%;
  173. margin: 5px 3px;
  174. background-color:transparent;
  175. border-radius:5px;
  176. box-shadow: 5px 0 5px rgba(0, 0, 0, 0.5);
  177. }
  178. `);
  179. createWrapper();
  180.  
  181.  
  182.  
  183. function addWebhook() {
  184. var newWebhook = prompt(
  185. "Paste one webhook URL to add to your script.\n\nIf you want to add multiple, do one at a time."
  186. );
  187. if (newWebhook) {
  188. var webHooks = GM_getValue("webHooks", []);
  189. webHooks.push(newWebhook);
  190. GM_setValue("webHooks", webHooks);
  191. }
  192. }
  193.  
  194.  
  195.