MouseHunt - GWH Golem Reward Tracker

Tool to track and export GWH golem reward data for analysis

目前为 2019-12-22 提交的版本。查看 最新版本

// ==UserScript==
// @name         MouseHunt - GWH Golem Reward Tracker
// @author       Tran Situ (tsitu)
// @namespace    https://gf.qytechs.cn/en/users/232363-tsitu
// @version      0.1 (beta)
// @description  Tool to track and export GWH golem reward data for analysis
// @match        http://www.mousehuntgame.com/*
// @match        https://www.mousehuntgame.com/*
// ==/UserScript==

(function() {
  const originalOpen = XMLHttpRequest.prototype.open;
  XMLHttpRequest.prototype.open = function() {
    this.addEventListener("load", function() {
      if (
        this.responseURL.indexOf(
          "mousehuntgame.com/managers/ajax/events/winter_hunt.php"
        ) >= 0
      ) {
        try {
          const data = JSON.parse(this.responseText);
          if (data) parse(data);
        } catch (error) {
          console.log("Failed to process server response");
          console.error(error.stack);
        }
      }
    });
    originalOpen.apply(this, arguments);
  };

  function parse(data) {
    const msgs = data.messageData.message_model.messages;
    if (msgs && msgs.length > 0) {
      for (let msg of msgs) {
        const content = msg.messageData.content;
        if (content) {
          const title = content.title;
          if (title.indexOf("Snow Golem reward") >= 0) {
            const location = title.split("from the ")[1].split("!")[0];
            const userID = msg.messageData.stream_publish_data.params.user_id;
            // const level = title
            //   .split("claimed a Level ")[1]
            //   .split(" Snow Golem")[0];
            // const journalID =
            //   msg.messageData.stream_publish_data.params.journal_id;
            // msg.messageDate;
            // parseInt(level);

            const dataObj =
              JSON.parse(localStorage.getItem("tsitu-gwh-golem-data")) || {};
            if (dataObj[userID] === undefined) {
              dataObj[userID] = {};
            }
            if (dataObj[userID][location] === undefined) {
              dataObj[userID][location] = {};
            }

            const body = content.body;
            const dom = new DOMParser();
            const doc = dom.parseFromString(body, "text/html");
            const itemDiv = doc.querySelector(
              ".winterHunt2019-claimRewardPopup-content"
            );

            itemDiv
              .querySelectorAll(".winterHunt2019-claimRewardPopup-item")
              .forEach(el => {
                const rarityEl = el.querySelector(
                  ".winterHunt2019-claimRewardPopup-item-rarity"
                );
                const qtyEl = el.querySelector(".quantity");
                const itemEl = el.querySelector(
                  ".winterHunt2019-claimRewardPopup-item-name"
                );
                if (rarityEl && qtyEl && itemEl) {
                  let rarity = rarityEl.textContent;
                  rarity = rarity == "Magical Hat" ? "Hat" : rarity;
                  rarity = rarity.charAt(0).toUpperCase() + rarity.slice(1);
                  const quantity = parseInt(qtyEl.textContent);
                  const item = itemEl.textContent;

                  // Fixed qty rolls -> Avg/Raw = % Chance
                  // e.g. total qty is 20 in 40 rolls, 20/40 = 0.5 avg / 5 per roll = 10% chance
                  if (dataObj[userID][location][rarity] === undefined) {
                    dataObj[userID][location][rarity] = {};
                    dataObj[userID][location][rarity].count = 1;
                    dataObj[userID][location][rarity][item] = quantity;
                  } else {
                    if (dataObj[userID][location][rarity][item] === undefined) {
                      dataObj[userID][location][rarity][item] = quantity;
                    } else {
                      dataObj[userID][location][rarity][item] += quantity;
                    }
                    dataObj[userID][location][rarity].count += 1;
                  }
                }
              });

            localStorage.setItem(
              "tsitu-gwh-golem-data",
              JSON.stringify(dataObj)
            );
          }
        }
      }
    }
  }

  const pastebinButton = document.createElement("button");
  pastebinButton.style.marginLeft = "15px";
  pastebinButton.innerText = "Export Golem Data to a public Pastebin";
  pastebinButton.addEventListener("click", function() {
    if (
      window.confirm(
        "Are you sure?\n\nPlease refrain from using this too often or you may be rate-limited by Pastebin or the CORS proxy used."
      )
    ) {
      const text = localStorage.getItem("tsitu-gwh-golem-data");
      if (text && text.length > 2) {
        const pasteName = `Golem Data [${Date(Date.now()).toLocaleString()}]`;

        const xhr = new XMLHttpRequest();
        xhr.open(
          "POST",
          "https://cors-anywhere.herokuapp.com/https://pastebin.com/api/api_post.php",
          true
        );
        xhr.setRequestHeader(
          "Content-type",
          "application/x-www-form-urlencoded"
        );
        xhr.onload = function() {
          const data = xhr.responseText;
          if (data.indexOf("pastebin.com") >= 0) {
            const newWindow = window.open("");
            newWindow.location = data;
          }
        };
        xhr.onerror = function() {
          console.error(xhr.statusText);
        };
        xhr.send(
          `api_option=paste&api_paste_private=0&api_paste_name=${pasteName}&api_paste_expire_date=1M&api_paste_format=json&api_dev_key=a5931177b5ae56acb744ff1734c89b5b&api_paste_code=${text}`
        );
      }
    }
  });

  const targetEl = document.querySelector("#hudLocationContent");
  if (targetEl) targetEl.insertAdjacentElement("afterend", pastebinButton);
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址