armory xanax usage

description

当前为 2019-12-03 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴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)
})