!!GC - Kings Logger

12/15/2023, 6:55:38 PM

Acest script nu ar trebui instalat direct. Aceasta este o bibliotecă pentru alte scripturi care este inclusă prin directiva meta a // @require https://update.greasyfork.org/scripts/483077/1301360/%21%21GC%20-%20Kings%20Logger.js

// ==UserScript==
// @name        !!GC - Kings Logger
// @namespace   Grundo's Cafe
// @match       https://www.grundos.cafe/medieval/wiseking/
// @match       https://www.grundos.cafe/medieval/grumpyoldking/
// @grant       none
// @version     .1
// @author      Cupkait
// @description 12/15/2023, 6:55:38 PM
// ==/UserScript==

function logInventory() {
  const userName = /user=(.*?)"/g.exec(document.body.innerHTML)[1];

  function getInventory() {
    return fetch("https://www.grundos.cafe/inventory/")
      .then(response => {
        if (!response.ok) {
          throw new Error(`Network response was not ok: ${response.statusText}`);
        }
        return response.text();
      });
  }

  let getAvatar;

  function avatarCheck() {
    const avatarContainer = document.querySelector('div#page_event');

    if (
      !avatarContainer.innerText.includes("Skeith - King Hagan") &&
      !avatarContainer.innerText.includes("Hagan - Blah Blah") &&
      !avatarContainer.innerText.includes("King of Brightvale") &&
      !avatarContainer.innerText.includes("Brightvale Pride") &&
      !avatarContainer.innerText.includes("Blumaroo Court Jester") &&
      !avatarContainer.innerText.includes("Skarl - Moody")
    ) {
      getAvatar = '';
      console.log("No avatar detected.");
    } else {
      console.log("Avatar detected.");
      if (avatarContainer.innerText.includes("Skeith - King Hagan")) {
        getAvatar = 'Skeith - King Hagan';
      } else if (avatarContainer.innerText.includes("Hagan - Blah Blah")) {
        getAvatar = 'Hagan - Blah Blah';
      } else if (avatarContainer.innerText.includes("King of Brightvale")) {
        getAvatar = 'King of Brightvale';
      } else if (avatarContainer.innerText.includes("Brightvale Pride")) {
        getAvatar = 'Brightvale Pride';
      } else if (avatarContainer.innerText.includes("Blumaroo Court Jester")) {
        getAvatar = 'Blumaroo Court Jester';
      } else if (avatarContainer.innerText.includes("Skarl - Moody")) {
        getAvatar = 'Skarl - Moody';
      }
      console.log(getAvatar);
    }
  }

  const kingText = document.querySelector('div#page_content > main');
  const welcomeText = kingText.children[1].innerText;
  const fullText = $("main");

  if (welcomeText.startsWith('King Hagan listens')) {
    let getJoke = fullText.find("em").text().match(/"([^"]+)"/)[1].slice(0, -1);
    let getScore = fullText.find("strong").eq(0).text();
    let getItem = fullText.find("strong").eq(1).text();
    let getReaction = fullText.find("h4").eq(0).text();
    console.log(getReaction);
    avatarCheck();
    getInventory()
      .then(html => {
        const tempElement = document.createElement('div');
        tempElement.innerHTML = html;
        const fullInvent = tempElement.querySelector('#page_content > main > div > div.inventory');
        const itemList = Array.from(fullInvent.innerHTML.matchAll(/<span>(.*?)<\/span>/g), m => m[1]);

        let logResponse = `https://docs.google.com/forms/d/e/1FAIpQLScg6DKdRK4CooB0-eFIOJwrn_SiYu6yrX318u0avdjFlhLw0g/formResponse?usp=pp_url&entry.887213950=${userName}&entry.282164107=${getScore}&entry.757151679=${getAvatar}&entry.990142109=${getItem}&entry.356783646=${getJoke}&entry.2040047231=${itemList}&entry.274581123=${getReaction}`;
        fetch(logResponse);
      });
  } else if (welcomeText.startsWith('King Skarl listens')) {
    let getScore = fullText.find("strong").eq(1).text();
    let getItem = fullText.find("strong").eq(2).text();
    let getQuestion = fullText.find("p").eq(1).text();
    let getAnswer = fullText.find("p").eq(2).text();
    let getReaction = fullText.find("h4").eq(0).text();

    console.log("Score:", getScore, "Prize:", getItem)
    console.log(getQuestion)
    console.log(getAnswer)
    avatarCheck()
    getInventory()
      .then(html => {
        const tempElement = document.createElement('div');
        tempElement.innerHTML = html;
        const fullInvent = tempElement.querySelector('#page_content > main > div > div.inventory');
        const itemList = Array.from(fullInvent.innerHTML.matchAll(/<span>(.*?)<\/span>/g), m => m[1]);

        let logResponse = `https://docs.google.com/forms/d/e/1FAIpQLScKV9bdZPm_CH9HbwTTe_L9SrC_TUmsx7Zs2q2hENm1w6xHfQ/formResponse?usp=pp_url&entry.887213950=${userName}&entry.1276971140=${getAvatar}&entry.461702494=${getScore}&entry.1317968997=${getItem}&entry.356783646=${getQuestion}&entry.977451939=${getAnswer}&entry.2040047231=${itemList}&entry.2140734508=${getReaction}`;
        fetch(logResponse);
      });
  } else if (!welcomeText.includes('listens')) {
    console.log("Nothing to see here, you haven't told a joke yet.");
  }
}