Dog Tag Hunter

Shows Attacks won and lost since the start of DogTag Competition

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला 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         Dog Tag Hunter
// @namespace    namespace
// @version      1.2
// @description  Shows Attacks won and lost since the start of DogTag Competition 
// @author       Llyfr
// @match        https://www.torn.com/profiles.php*
// @license      MIT
// @grant        none
// ==/UserScript==



(function() {
    'use strict';

    let API = ""
    
    const time_start = 1652702400 // start of the competition 
    const time_end = 1653566400 // end of the competition 
    const unixTime = Math.floor(Date.now() / 1000); // Get Current time

    // If the API is empty, inform user and quit
    if(API == "") 
    {
        document.getElementsByClassName("title-black top-round")[1].innerText = `Missing API Key, Please enter it in the code`
        return;
    }

    // If the competition didn't started yet, it closes program. No need to waste API calls :)
    if(time_start > unixTime || time_end < unixTime)
    {
        return;
    }

    //Gets the profile ID from url 
    let url = window.location.href
    let id = url.slice(url.indexOf("ID=") + 3)
 

    var request = new XMLHttpRequest();
    request.open('GET', `https://api.torn.com/user/${id}?selections=personalstats&stat=attackswon,defendslost&key=${API}`)
    request.send();
    request.onload = ()=>
    {
        let data_now = JSON.parse(request.responseText).personalstats;

            request.open('GET', `https://api.torn.com/user/${id}?selections=personalstats&stat=attackswon,defendslost&timestamp=${time_start}&key=${API}`);
            request.send()
    
            request.onload = ()=> 
            {
                let data_old = JSON.parse(request.responseText).personalstats
                let attacks = data_now.attackswon - data_old.attackswon
                let defends = data_now.defendslost - data_old.defendslost
    
                // console.log(data_now,data_old) // For Debug
    
                document.getElementsByClassName("title-black top-round")[1].innerText = `Wins: ${attacks} | Defeats: ${defends}`
            }   
}
})();