[GC] - Kadoatery Feed Logging (Discord Webhook)

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

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