Torn: Finishing Hits

Show finishing hits on items page

As of 2020-09-15 13:44:07 UTC. See the latest version.

// ==UserScript==
// @name         Torn: Finishing Hits
// @namespace    http://tampermonkey.net/
// @version      1.1.1
// @description  Show finishing hits on items page
// @author       Untouchable [1360035]
// @match        https://www.torn.com/item.php
// @grant        none
// ==/UserScript==

const colors = true;

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: #aeaeae;
}

` );

(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 => {

          let ps = data.personalstats;

          let hr = '#mainContainer > div.content-wrapper.m-left20.left.summer > div.main-items-cont-wrap > hr';

          $(hr).after(
              `
                 <div id="finishing-hits-title" class="title-black title-toggle" role="heading" aria-level="5">
                 <div class="arrow-999 right"></div>
                 Finishing Hits
                 <div class="clear"></div>
                 </div>

                 <table id="finishing_hits">
                   <tr>
                     <td class="` + getStatus(ps.heahits) + `">Heavy Artillery: </td>
                     <td class="` + getStatus(ps.heahits) + `">${nwc(ps.heahits)}</td>
                     <td class="` + getStatus(ps.machits) + `">Machine Guns: </td>
                     <td class="` + getStatus(ps.machits) + `">${nwc(ps.machits)}</td>
                     <td class="` + getStatus(ps.rifhits) + `">Rifles: </td>
                     <td class="` + getStatus(ps.rifhits) + `">${nwc(ps.rifhits)}</td>
                   </tr>
                   <tr>
                     <td class="` + getStatus(ps.smghits) + `">Sub Machine Guns: </td>
                     <td class="` + getStatus(ps.smghits) + `">${nwc(ps.smghits)}</td>
                     <td class="` + getStatus(ps.shohits) + `">Shotguns: </td>
                     <td class="` + getStatus(ps.shohits) + `">${nwc(ps.shohits)}</td>
                     <td class="` + getStatus(ps.pishits) + `">Pistols: </td>
                     <td class="` + getStatus(ps.pishits) + `">${nwc(ps.pishits)}</td>
                   </tr>
                   <tr>
                     <td class="` + getStatus(ps.grehits) + `">Temporary Weapons: </td>
                     <td class="` + getStatus(ps.grehits) + `">${nwc(ps.grehits)}</td>
                     <td class="` + getStatus(ps.piehits) + `">Piercing Weapons: </td>
                     <td class="` + getStatus(ps.piehits) + `">${nwc(ps.piehits)}</td>
                     <td class="` + getStatus(ps.slahits) + `">Slashing Weapons: </td>
                     <td class="` + getStatus(ps.slahits) + `">${nwc(ps.slahits)}</td>
                   </tr>
                   <tr>
                     <td class="` + getStatus(ps.axehits) + `">Clubbing Weapons: </td>
                     <td class="` + getStatus(ps.axehits) + `">${nwc(ps.axehits)}</td>
                     <td class="` + getStatus(ps.chahits) + `">Mechanical Weapons: </td>
                     <td class="` + getStatus(ps.chahits) + `">${nwc(ps.chahits)}</td>
                     <td class="` + getStatus(ps.h2hhits) + `">Hand-to-Hand: </td>
                     <td class="` + getStatus(ps.h2hhits) + `">${nwc(ps.h2hhits)}</td>
                   </tr>
                 </table>
                 <br>
              `
          );

    });

})();


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 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";
  }
}