Torn Extensions - Torn Attack Stats

Get some information on the attack page.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το 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 Extensions - Torn Attack Stats
// @namespace    https://www.torn.com/profiles.php?XID=1918010#/
// @version      1.3
// @description  Get some information on the attack page.
// @author       Mathias
// @match        https://www.torn.com/loader.php*
// @grant        none
// ==/UserScript==

(function attack() {
    'use strict';

    let api = "API HERE";
    let url = window.location.href;
    if(url.includes("sid=attack"))
    {
        url = new URL(url);
        let attackId = url.searchParams.get("user2ID");
        console.log(`https://api.torn.com/user/${attackId}?selections=profile,personalstats&key=${api}`);
        fetch(`https://api.torn.com/user/${attackId}?selections=profile,personalstats&key=${api}`)
		.then(function(response) {
			if (response.status !== 200) {
				console.log(`fetch error ${response.status}`);
				return;
			}
			response.json().then(function(data) {
                let joinBtn = $("button:contains(\"Start fight\"), button:contains(\"Join fight\")").closest("button");
				if($(joinBtn).length) {
					$(joinBtn).after(`<div id='attackInfo'>
					<br />Attacks: <font color='green'>[W] ${parseInt(data.personalstats.attackswon) || 0}</font> <font color='red'>[L] ${parseInt(data.personalstats.attackslost) || 0}</font>
					<br />Defends: <font color='green'>[W] ${parseInt(data.personalstats.defendswon) || 0}</font> <font color='red'>[L] ${parseInt(data.personalstats.defendslost) || 0}</font>
					<br />Drugs: ${parseInt(data.personalstats.drugsused) || 0} used (${parseInt(data.personalstats.xantaken) || 0} xan)
					<br />Consumables: ${parseInt(data.personalstats.consumablesused) || 0} used
					<br />Refills: ${parseInt(data.personalstats.refills) || 0} used
                    <br />Networth: $${data.personalstats.networth.toLocaleString("en")}
					<br />Last action: ${data.last_action.relative}
					<br />Faction: <a href='https://www.torn.com/factions.php?step=profile&ID=${data.faction.faction_id}'>${data.faction.faction_name}</a>
					</div>`);
				}
			}).catch((err) => { console.log(err); });
		}).catch(function(err) {
			console.log(`fetch error ${err}`);
		});
    }
})();