TheresMoreHelp

Helper for TheresMoreGame

目前为 2022-12-20 提交的版本。查看 最新版本

// ==UserScript==
// @name        TheresMoreHelp
// @namespace   TheresMoreGame.com
// @match       https://www.theresmoregame.com/play/
// @grant       none
// @version     1.0
// @description Helper for TheresMoreGame
// @license     MIT
// ==/UserScript==

window.addEventListener('DOMContentLoaded', function () {
  ;(async () => {
    const formatTime = (timeToFormat) => {
      const timeValues = {
        seconds: 0,
        minutes: 0,
        hours: 0,
        days: 0,
      }

      let timeShort = ''
      let timeLong = ''

      timeValues.seconds = timeToFormat % 60
      timeToFormat = (timeToFormat - (timeToFormat % 60)) / 60
      timeValues.minutes = timeToFormat % 60
      timeToFormat = (timeToFormat - (timeToFormat % 60)) / 60
      timeValues.hours = timeToFormat % 24
      timeToFormat = (timeToFormat - (timeToFormat % 24)) / 24
      timeValues.days = timeToFormat

      if (timeValues.days) {
        timeShort += `${timeValues.days}d `
        timeLong += `${timeValues.days} days `
      }
      if (timeValues.hours) {
        timeShort += `${timeValues.hours}h `
        timeLong += `${timeValues.hours} hrs `
      }
      if (timeValues.minutes) {
        timeShort += `${timeValues.minutes}m `
        timeLong += `${timeValues.minutes} min `
      }
      if (timeValues.seconds) {
        timeShort += `${timeValues.seconds}s `
        timeLong += `${timeValues.seconds} sec `
      }

      timeShort = timeShort.trim()
      timeLong = timeLong.trim()

      return {
        timeShort,
        timeLong,
        timeValues,
      }
    }

    const findResource = (resourceName = 'Gold') => {
      let resourceFound = false
      let resourceToFind = { name: resourceName, current: 0, max: 0, speed: 0, ttf: null, ttz: null }
      const resources = document.querySelectorAll('#root div > div > div > table > tbody > tr > td:nth-child(1) > span')
      resources.forEach((resource) => {
        if (resource.textContent.includes(resourceName)) {
          resourceFound = true
          const values = resource.parentNode.parentNode.childNodes[1].textContent.split('/').map((x) =>
            Number(
              x
                .replace(/[^0-9\-,\.]/g, '')
                .replace(',', '.')
                .trim()
            )
          )
          resourceToFind.current = values[0]
          resourceToFind.max = values[1]

          resourceToFind.speed = Number(
            resource.parentNode.parentNode.childNodes[2].textContent
              .replace(/[^0-9\-,\.]/g, '')
              .replace(',', '.')
              .trim()
          )

          resourceToFind.ttf =
            resourceToFind.speed > 0 && resourceToFind.max !== resourceToFind.current
              ? formatTime(Math.ceil((resourceToFind.max - resourceToFind.current) / resourceToFind.speed))
              : null
          resourceToFind.ttz =
            resourceToFind.speed < 0 && resourceToFind.current ? formatTime(Math.ceil(resourceToFind.current / (resourceToFind.speed * -1))) : null
        }
      })

      return resourceFound ? resourceToFind : null
    }

    const calculateTTF = () => {
      const resourceTrNodes = document.querySelectorAll('#root > div > div:not(#maintabs-container) > div > div > div > table:not(.hidden) > tbody > tr')
      resourceTrNodes.forEach((row) => {
        const cells = row.querySelectorAll('td')
        const resourceName = cells[0].textContent.trim()
        const resource = findResource(resourceName)
        let ttf = ''

        if (resource && resource.current < resource.max && resource.speed) {
          ttf = resource.ttf ? resource.ttf.timeLong : resource.ttz.timeLong
        }

        if (!cells[3]) {
          const ttfElement = document.createElement('td')
          ttfElement.className = 'px-3 3xl:px-5 py-3 lg:py-2 3xl:py-3 whitespace-nowrap w-1/3 text-right'
          ttfElement.textContent = ttf
          row.appendChild(ttfElement)
        } else {
          cells[3].textContent = ttf
        }
      })
    }

    const calculateTippyTTF = () => {
      let potentialResourcesToFillTable = document.querySelectorAll('div.tippy-box > div.tippy-content > div > div > table')
      if (potentialResourcesToFillTable.length) {
        potentialResourcesToFillTable = potentialResourcesToFillTable[0]
        const rows = potentialResourcesToFillTable.querySelectorAll('tr')
        rows.forEach((row) => {
          const cells = row.querySelectorAll('td')
          const resourceName = cells[0].textContent.trim()

          const resource = findResource(resourceName)
          if (resource) {
            let ttf = '✅'

            const target = Number(
              cells[1].textContent
                .split(' ')
                .shift()
                .replace(/[^0-9\-,\.]/g, '')
                .replace(',', '.')
                .trim()
            )

            if (target > resource.max || resource.speed <= 0) {
              ttf = 'never'
            } else if (target > resource.current) {
              ttf = formatTime(Math.ceil((target - resource.current) / resource.speed)).timeShort
            }

            if (!cells[2]) {
              const ttfElement = document.createElement('td')
              ttfElement.className = 'px-4 3xl:py-1 text-right'
              ttfElement.textContent = ttf
              row.appendChild(ttfElement)
            } else {
              cells[2].textContent = ttf
            }
          }
        })
      }
    }

    const performRoutineTasks = () => {
      calculateTTF()
    }

    const performFastTasks = () => {
      calculateTippyTTF()
    }

    this.setInterval(performRoutineTasks, 1000)
    this.setInterval(performFastTasks, 100)
  })()
})

QingJ © 2025

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