armory xanax usage

description

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         armory xanax usage
// @namespace    namespace
// @version      0.1
// @description  description
// @author       tos
// @match       *.torn.com/*
// @grant        GM_xmlhttpRequest
// ==/UserScript==

const APIKEY = 'API_KEY_HERE'

const torn_api = async (args) => {
  const a = args.split('.')
  if (a.length!==3) throw(`Bad argument in torn_api(args, key): ${args}`)
  return new Promise((resolve, reject) => {
    GM_xmlhttpRequest ( {
      method: "POST",
      url: `https://api.torn.com/${a[0]}/${a[1]}?selections=${a[2]}&key=${APIKEY}`,
      headers: {
        "Content-Type": "application/json"
      },
      onload: (response) => {
          try {
            const resjson = JSON.parse(response.responseText)
            resolve(resjson)
          } catch(err) {
            reject(err)
          }
      },
      onerror: (err) => {
        reject(err)
      }
    })
  })
}

torn_api('faction..armorynewsfull').then((res) => {
  let total_xanax_used = 0
  let members_used_xanax = {}
  let other_news = []
  let oldest_event = null
  for (eid in res.armorynews) {
    const news = res.armorynews[eid].news
    const timestamp = res.armorynews[eid].timestamp
    if (news.includes('Xanax')) {
      if (!oldest_event || timestamp < oldest_event) {
        oldest_event = timestamp
      }
      if (news.includes('used one of')) {
        player_name = news.split('>')[1].split('<')[0]
        if (!(player_name in members_used_xanax)) {
          members_used_xanax[player_name] = 1
        }
        else {
          members_used_xanax[player_name] += 1
        }
        total_xanax_used += 1
      }
      else other_news.push(news)
    }
  }
  console.log('Oldest Event:', (new Date(oldest_event * 1000)).toUTCString())
  console.log('Total Xanax Used:', total_xanax_used)
  console.log('Members Xanax Used:', members_used_xanax)
  console.log('Other Xanax News:', other_news)
})