[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 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        [GC] - Kadoatery Feeds 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/1317118/%5BGC%5D%20-%20Kadoatery%20Details%20Helper.js
// @version     1.0
// @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. 
// @description Enter/register webhooks from the kadoatery, under the left side bar.
// @description Current set to send a message for every 100th kad + every relic received. Future update will make the 100th easily changeable.
// ==/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.push(newWebhook);
    GM_setValue("webHooks", webHooks);
  }
}