// ==UserScript==
// @name Torn: War Machine Helper
// @namespace http://tampermonkey.net/
// @version 1.3.2
// @description Show finishing hits on items page
// @author Untouchable [1360035]
// @match https://www.torn.com/item.php
// @grant none
// @downloadURL none
// ==/UserScript==
const colors = true; // Grey out completed categories
const open_by_default = true; // Open tab by default
let active;
if(open_by_default){
active = "active";
}
GM_addStyle ( `
table {
table-layout:fixed;
width:100%;
}
#finishing_hits > tbody > tr > td {
padding:5px
}
/*
table, td {
border: 1px solid black;
border-collapse: collapse;
} */
td {
width: 16.6%
}
.incomplete {
}
.complete {
color: #d3d3d3;
}
` );
(function() {
'use strict';
let apiKey = localStorage.getItem('uapikey');
if(apiKey === null) {
apiKey = '';
while(apiKey !== null && apiKey.length != 16) {
apiKey = prompt("Please enter a valid Torn API key");
}
if(apiKey !== null && apiKey.length == 16) {
localStorage.setItem('uapikey', apiKey);
}
}
fetch('https://api.torn.com/user/?selections=personalstats&key=' + apiKey)
.then(response => response.json())
.then(data => {
console.log(data);
let ps = data.personalstats;
let seasons = ['summer','winter','spring','autumn'], season = '', hr = '';
seasons.forEach((sn) => {
if ($(`#mainContainer > div.content-wrapper.m-left20.left.${sn} > div.main-items-cont-wrap > hr`)[0] != undefined) {
hr = `#mainContainer > div.content-wrapper.m-left20.left.${sn} > div.main-items-cont-wrap > hr`;
}
});
let hits_req = getHitsReq(data.personalstats);
$(hr).after(
`
War Machine - ${hits_req}
Heavy Artillery: |
${nwc(ps.heahits)} |
Machine Guns: |
${nwc(ps.machits)} |
Rifles: |
${nwc(ps.rifhits)} |
Sub Machine Guns: |
${nwc(ps.smghits)} |
Shotguns: |
${nwc(ps.shohits)} |
Pistols: |
${nwc(ps.pishits)} |
Temporary Weapons: |
${nwc(ps.grehits)} |
Piercing Weapons: |
${nwc(ps.piehits)} |
Slashing Weapons: |
${nwc(ps.slahits)} |
Clubbing Weapons: |
${nwc(ps.axehits)} |
Mechanical Weapons: |
${nwc(ps.chahits)} |
Hand-to-Hand: |
${nwc(ps.h2hhits)} |
`
);
});
})();
//////////////////////////////////////////////////////////////////////////////////////////
function GM_addStyle (cssStr) {
var D = document;
var newNode = D.createElement ('style');
newNode.textContent = cssStr;
var targ = D.getElementsByTagName ('head')[0] || D.body || D.documentElement;
targ.appendChild (newNode);
}
//////////////////////////////////////////////////////////////////////////////////////////
function getHitsReq(stats) {
let hitsReq = 0;
let categories = 0;
if(stats.heahits < 1000){
hitsReq = hitsReq + (1000 - stats.heahits);
categories++;
}
if(stats.machits < 1000){
hitsReq = hitsReq + (1000 - stats.machits);
categories++;
}
if(stats.rifhits < 1000){
hitsReq = hitsReq + (1000 - stats.rifhits);
categories++;
}
if(stats.smghits < 1000){
hitsReq = hitsReq + (1000 - stats.smghits);
categories++;
}
if(stats.shohits < 1000){
hitsReq = hitsReq + (1000 - stats.shohits);
categories++;
}
if(stats.pishits < 1000){
hitsReq = hitsReq + (1000 - stats.pishits);
categories++;
}
if(stats.grehits < 1000){
hitsReq = hitsReq + (1000 - stats.grehits);
categories++;
}
if(stats.piehits < 1000){
hitsReq = hitsReq + (1000 - stats.piehits);
categories++;
}
if(stats.slahits < 1000){
hitsReq = hitsReq + (1000 - stats.slahits);
categories++;
}
if(stats.axehits < 1000){
hitsReq = hitsReq + (1000 - stats.axehits);
categories++;
}
if(stats.chahits < 1000){
hitsReq = hitsReq + (1000 - stats.chahits);
categories++;
}
if(stats.h2hhits < 1000){
hitsReq = hitsReq + (1000 - stats.h2hhits);
categories++;
}
let ret = nwc(hitsReq) + " hits required in " + categories + " categories";
return ret;
}
//////////////////////////////////////////////////////////////////////////////////////////
function nwc(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
//////////////////////////////////////////////////////////////////////////////////////////
function getStatus(hits){
if(!colors) {
return "";
}
if(hits >= 1000){
return "complete";
} else {
return "incomplete";
}
}
//////////////////////////////////////////////////////////////////////////////////////////