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 यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

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