Torn:BattleStat%

Adds Battlestat % to the main page in the Battle Stats Box

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name          Torn:BattleStat%
// @version       1.3
// @author        Cypher [2641265], Kwack [2190604]
// @description   Adds Battlestat % to the main page in the Battle Stats Box
// @match         https://www.torn.com/index.php
// @icon          https://www.google.com/s2/favicons?sz=64&domain=torn.com
// @namespace https://greasyfork.org/users/1228211
// ==/UserScript==

//Finds the Battlestats Box on main page
const headerElem = Array.from(document.getElementsByTagName("h5")).filter(
  (el) => el.innerText === "Battle Stats"
)[0];
//Creates const for BattleStats box
const container = headerElem.parentElement.parentElement;
//Creates integer const rom the total battle stats
const totalStats = parseInt(
  container
    .querySelector(
      ".bottom-round>.cont-gray.battle.bottom-round>.info-cont-wrap>.last>.desc"
    )
    .innerText.replaceAll(",", "")
);
//Loads all nodes for stats
const rows = container.querySelectorAll(
  ".bottom-round>.cont-gray.battle.bottom-round>.info-cont-wrap>li"
);
//For loop to apply the stat% to stat line.
for (row of rows) {
  const array = row.innerText.split(" ");
  const basestat = array[1];
  const stat = parseInt(basestat.replaceAll(",", ""));
  const percentageElement = ((stat * 100) / totalStats).toFixed(2) + "%";
  row.querySelector(".divider>.label").innerHTML +=
    ": </span> <span style=color:#039AFF>" + percentageElement + "</span>";
}