TC Inventory Abroad

description

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         TC Inventory Abroad
// @namespace    namespace
// @version      0.1
// @description  description
// @author       tos
// @match       *.torn.com/index.php*
// @grant        none
// ==/UserScript==

const api_key = 'APIKEY'

const travel_market_wrap = document.querySelector('.travel-agency-market')

if (travel_market_wrap) {
  document.querySelector('.items-list-title .circulation-b').innerText = 'Inventory'
  show_inventory()
}

async function show_inventory() {
  const inventory = await fetch(`https://api.torn.com/user/?selections=inventory&key=${api_key}`).then(r => r.json())
  document.querySelectorAll('.users-list li').forEach( (item) => {
    try {
      const item_id = item.querySelector('img').src.split('items/')[1].split('/')[0]
      const circ = item.querySelector('.circulation').childNodes[2]
      circ.textContent = '0'
      inventory.inventory.forEach((i) => {
        if (item_id == i.ID) circ.textContent = i.quantity
      })
    }
    catch(err) {
      console.warn('TC Inventory Abroad ERROR:', err)
    }
  })
}