gooboo 煤渣购买建议

煤渣活动的生产者购买建议

当前为 2025-01-15 提交的版本,查看 最新版本

// ==UserScript==
// @name         gooboo 煤渣购买建议
// @namespace    http://tampermonkey.net/
// @version      1.0.0
// @description  煤渣活动的生产者购买建议
// @author       baicy
// @match        *://*/gooboo/
// @match        *://gooboo.g8hh.com.cn/
// @match        *://gooboo.tkfm.online/
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @license      MIT
// ==/UserScript==

(function () {
  "use strict"

  let found = false
  let inventory = null
  const db = document.getElementsByClassName("primary")[0].__vue__.$store.state

  setInterval(() => {
    const cinder = document.querySelector(".cinders-inventory")
    if (cinder) {
      if (!found) {
        found = true
        inventory = cinder
        console.log("抵达煤渣现场...停止继续寻找")
        addInfo()
      }
    } else {
      found = false
    }
  }, 2000)

  setInterval(() => {
    for (const p in producers) {
      cinder[p]
    }
    getBest()
  }, 2000)

  const producers = {
    firefly: "萤火虫",
    glowshroom: "发光蘑菇",
    glowfish: "发光鱼",
    lantern: "灯",
    campfire: "营火",
    coral: "珊瑚",
    jellyfish: "海蜇",
    nightbloom: "夜花",
    neonlight: "霓虹灯",
    sun: "太阳",
  }
  const productions = {}
  const cinder = new Proxy(db.upgrade.item, {
    get(target, key) {
      const val = target[`event_${key}`]
      if (val.requirement()) {
        if (!productions[key]) {
          productions[key] = { level: val.level }
        } else {
          if (productions[key].level !== val.level) {
            productions[key].level = val.level
            console.log(producers[key], "升级")
            getSingleInfo(key)
          }
        }
      }
      return val
    },
  })

  function capitalize(string) {
    return string.charAt(0).toUpperCase() + string.slice(1)
  }

  const infoStyles = [
    "background: white;",
    "color: black;",
    "display: flex;",
    "flex-direction: column;",
    "justify-content: space-between;",
    "padding: 10px 20px;",
  ]
  function addInfo() {
    const infoDiv = document.createElement("div")
    infoDiv.id = "cinder_info"
    infoDiv.style = infoStyles.join("")
    for (const p in producers) {
      const span = getSingleInfo(p)
      if (span) {
        infoDiv.appendChild(span)
      }
    }
    inventory.insertBefore(infoDiv, inventory.childNodes[1])
  }
  function getSingleInfo(p) {
    const producer = db.upgrade.item[`event_${p}`]
    let val = 0
    if (producer.requirement()) {
      const price = producer.price(producer.level).event_light
      const mult = document.getElementsByClassName("primary")[0].__vue__.$store.state.mult.items[`cindersProduction${capitalize(p)}`]
      const gain = mult.baseCache * mult.multCache
      val = gain / price
      productions[p].ratio = val
      let producerSpan = document.querySelector(`#cinder_info_${p}`)
      if (!producerSpan) {
        producerSpan = document.createElement("span")
        producerSpan.innerHTML = `${
          producers[p]
        }:<span id="cinder_info_${p}">${val.toExponential(4)}</span>`
        return producerSpan
      } else {
        producerSpan.innerHTML = val.toExponential(4)
      }
    }
    return null
  }
  function getBest() {
    let max = 0
    let producer = Object.keys(producers)[0]
    for (const p in productions) {
      if (productions[p].ratio > max) {
        max = productions[p].ratio
        producer = p
      }
    }
    const infoPanel = document.querySelector("#cinder_info")
    if (infoPanel) {
      infoPanel.childNodes.forEach((info) => {
        info.style = ""
      })
      document.querySelector(`#cinder_info_${producer}`).parentNode.style =
        "color:red"
    }
  }
})()