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.

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

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