- // ==UserScript==
- // @name [GC] - Kadoatery Feed Logging (Discord Webhook)
- // @namespace https://greasyfork.org/en/users/1225524-kaitlin
- // @match https://www.grundos.cafe/games/kadoatery/*
- // @require https://update.greasyfork.org/scripts/485575/1330924/%5BGC%5D%20-%20Kadoatery%20Details%20Helper.js
- // @version 1.2
- // @grant GM_getValue
- // @grant GM_setValue
- // @grant GM_addStyle
- // @license MIT
- // @author Cupkait
- // @icon https://i.imgur.com/4Hm2e6z.png
- // @description Checks if feeding a kad was successful and, if it is, logs the results to pass through a Discord webhook.
- // ==/UserScript==
-
- const webHooks = GM_getValue("webHooks", []);
- var kadHome = $("#kad_grid");
-
-
-
-
-
- const errorPage = $(".errorpage");
- if (errorPage.length > 0) {
- const errorText = errorPage.text();
-
- if (errorText.includes("has already been fed")) {
- console.log("Too slow, someone else got to that kad first.");
- } else if (errorText.includes("wait a bit")) {
- console.log("You already fed a kad, try again later.");
- }
- } else if (kadHome.length === 1) {
-
- console.log("Home Page, not feeding yet.")
- } else {
- const details = GrabKadoatieDetails();
-
- let reltrueParams = {
- username: "Kadoatery Logs",
- embeds: [
- {
- title: `${details.kadName} shared a special snack with ${details.userName}...`,
- description: `*... oh wow, a Happy Anniversary Negg!*`,
- color: `${details.barColor}`,
- author: {
- name: `${details.kadBlurb}`,
- },
- footer: {
- text: `${details.userName} has now fed ${details.kadCount} kadoaties in all`,
- },
- thumbnail: {
- url: `${details.kadImage}`,
- },
- },
- ],
- avatar_url: "https://i.imgur.com/4Hm2e6z.png",
- attachments: []
- };
-
- let relfalseParams = {
- username: "Kadoatery Logs",
- embeds: [
- {
- title: `${details.userName} has fed ${details.kadCount} kadoaties in all!`,
- description: `What an achievement!`,
- color: `${details.barColor}`,
- author: {
- name: `${details.kadBlurb}`,
- },
- thumbnail: {
- url: `${details.kadImage}`,
- },
- },
- ],
- avatar_url: "https://i.imgur.com/4Hm2e6z.png",
- attachments: []
- };
-
- webHooks.forEach((webHook) => {
- let paramsToSend;
-
- if (details.relicStatus) {
- paramsToSend = reltrueParams;
- } else if (details.kadCount % 100 === 0) {
- paramsToSend = relfalseParams;
- } else {
- console.log("Fed but not sent.");
- return;
- }
-
- sendMessage(paramsToSend, webHook);
- });
-
- function sendMessage(params, webHook) {
- console.log("Webhook triggered.");
-
- const request = new XMLHttpRequest();
- request.open("POST", webHook);
- request.setRequestHeader("Content-type", "application/json");
- request.send(JSON.stringify(params));
- }
- }
-
- const wrapperContainer = document.createElement("div");
- wrapperContainer.id = "wrapContainer";
-
- const wrapperSettings = document.createElement("button");
- wrapperSettings.textContent = "Kad Webhook Settings";
- wrapperSettings.id = "wrapSettings";
-
- const wrapperMenu = document.createElement("div");
- wrapperMenu.id = "wrapMenu";
-
- const firstButton = document.createElement("button");
- wrapperMenu.appendChild(firstButton);
- firstButton.textContent = "Add a Webhook";
- firstButton.id = "menubutton";
- $(firstButton).on("click", addWebhook);
-
- function createWrapper() {
- wrapperContainer.appendChild(wrapperSettings);
- wrapperContainer.appendChild(wrapperMenu);
- $("#sb_edge").append(wrapperContainer);
-
- $(wrapperSettings).on("click", function () {
- $(wrapperMenu).fadeToggle(150);
- });
- return wrapperContainer;
- return wrapperMenu;
- }
-
- GM_addStyle(`#wrapMenu {
- display:none;
- border-radius: 15px 15px 15px 0px;
- border-bottom: 3px solid;
- position: absolute;
- width: 200px;
- height: 250px;
- bottom: 0%;
- left: 100%;
- margin: -3px;
- padding: 10px;
- background-color: #d2d0cc;
- box-shadow: 5px 0 5px rgba(0, 0, 0, 0.5);
- }
- #wrapContainer {
- position: relative;
- border-bottom: 3px solid;
- padding: 5px 10px 5px 0px;
- height: 30px;
- width: 100%;
- top: 0px;
- left: 0px;
- background-color: #d2d0cc;
- box-shadow: 5px 0 5px rgba(0, 0, 0, 0.5);
- }
- #wrapSettings {
- position:relative;
- font-size:12px;
- font-weight:bold;
- font-family:courier;
- padding:0px;
- width:100%;
- height: auto;
- border: 1px solid rgb(204, 204, 204);
- cursor: pointer;
- background-color: transparent;
- }
- #menubutton {
- height:35px;
- width:98%;
- margin: 5px 3px;
- background-color:transparent;
- border-radius:5px;
- box-shadow: 5px 0 5px rgba(0, 0, 0, 0.5);
- }
- `);
- createWrapper();
-
-
-
- function addWebhook() {
- var newWebhook = prompt(
- "Paste one webhook URL to add to your script.\n\nIf you want to add multiple, do one at a time."
- );
- if (newWebhook) {
- var webHooks = GM_getValue("webHooks", []);
- webHooks = [...new Set(webHooks)];
- if (webHooks.includes(newWebhook)) {
- alert("This webhook is already added.");
- return;
- }
- webHooks.push(newWebhook);
- GM_setValue("webHooks", webHooks);
- }
- }
-