[BETA]!!GC - Fishing Logger

Beta version of a fishing reward logging script. Features coming soon: Webhooks!

目前为 2023-12-21 提交的版本。查看 最新版本

// ==UserScript==
// @name        [BETA]!!GC - Fishing Logger
// @namespace   Grundo's Cafe
// @match       https://www.grundos.cafe/water/fishing/
// @version     1
// @author      Cupkait
// @license     MIT
// @description Beta version of a fishing reward logging script. Features coming soon: Webhooks!
// ==/UserScript==

// Last updated: Dec 21, 2023 

function getPetData() {
  fetch("/quickref/")
    .then(response => {
      if (!response.ok) {
        throw new Error(`Network response was not ok: ${response.statusText}`);
      }
      return response.text();
    })
    .then(html => {
      const tempElement = document.createElement('div');
      tempElement.innerHTML = html;
      const petList = tempElement.querySelector('#quickref_petlist').children;

      const petArray = {};

      $(petList).each(function () {
        const petrefName = $(this).find('a').eq(0).attr('href').match(/_name=(.*?)$/)[1];
        const petFishingLevel = $(this).find('span').eq(12).text().match(/Fishing : (.*?)$/)[1];
        petArray[petrefName] = petFishingLevel;
      });
      // You can return petArray or perform additional actions as needed
    })
    .catch(error => {
      console.error(error);
      // Handle errors if necessary
    });
}

const fishContent = document.querySelector('div#page_content > main');
const welcomeText = fishContent.children[1].innerText;
const patientText = fishContent.children[2].innerText;
const petCount = document.querySelectorAll('main > div > div');
const petName = document.querySelector('div#userinfo > a').href;

if (welcomeText.startsWith('Welcome to the') || patientText.startsWith('Nothing!')) {
  console.log("Nothing to log here... it looks like no one went fishing.");
} else {
  if (petCount.length === 0) { // One Pet
    const content = $("#page_content");
    const userInfo = $("#userinfo");
    const petName = userInfo.find("a").eq(2).text();
    const userName = /user=(.*?)"/g.exec(document.body.innerHTML)[1];
    const coolDown = content.find("strong").eq(0).text();
    const itemName = fishContent.querySelector("img").alt;
    const itemImage = fishContent.querySelector("strong").text;

    let levelUp = ' ';
    try {
      levelUp = content.find("p").eq(2).text().match(/to (.*?)!/)[1];
    } catch (error) {
      // DO NOTHING
    }
    getPetData();
      let petrefName;
      petrefName = petName;
      let petFishingLevel;

    const logResponse = `https://docs.google.com/forms/d/e/1FAIpQLSdBhJS1NSxHCmy32BqH0DEdQRJci1IVPOWUFcaothsiZjXu-w/formResponse?usp=pp_url&entry.886049257=${userName}&entry.343654154=${petName}&entry.1922136733=${petFishingLevel}&entry.693447328=${levelUp}&entry.881968876=${itemName}&entry.303510013=${coolDown}`;
    fetch(logResponse);
  } else {
    $(".flex.center-items.big-gap").each(function () {
      const petName = $(this).find("strong").eq(0).text();
      const userName = /user=(.*?)"/g.exec(document.body.innerHTML)[1];
      const coolDown = $(this).find("strong").eq(1).text();
      const petImage = $(this).find("img").eq(0).attr("src");
      const itemImage = $(this).find("img").eq(1).attr("src");
      const itemName = $(this).find("p").eq(0).text().match(/ a (.*?)!/)[1];
      let levelUp = '';
      try {
        levelUp = $(this).find("p").eq(1).text().match(/to (.*?)!/)[1];
      } catch (error) {
        // DO NOTHING
      }
      const logResponse = `https://docs.google.com/forms/d/e/1FAIpQLSdBhJS1NSxHCmy32BqH0DEdQRJci1IVPOWUFcaothsiZjXu-w/formResponse?usp=pp_url&entry.886049257=${userName}&entry.343654154=${petName}&entry.1922136733={petLevel}&entry.693447328=${levelUp}&entry.881968876=${itemName}&entry.303510013=${coolDown}`;
      fetch(logResponse);
    });
  }
}





// Option to limit webhook to certain items if all pets are fed at once
// Need to set a pause between webhook triggers so discord isnt rate limited,
// or consider sending multi- pets in a different format entirely.