armory xanax usage

description

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==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)
})