Tools4Torn

description

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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         Tools4Torn
// @namespace    namespace
// @version      0.5
// @description  description
// @author       Legaci
// @match        *.torn.com/*
// @grant        GM_xmlhttpRequest
// @require      https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js
// ==/UserScript==

GM_xmlhttpRequest ( {
    method:     "POST",
    url:        "https://www.torn.com/sidebarAjaxAction.php?q=getSidebarData",
    onload:     function (response) {
        const data = JSON.parse(response.response);

        const XanaxData = data.statusIcons.icons.drug_cooldown;

        var today = new Date();
        var cooldown = new Date(XanaxData.timerExpiresAt * 1000);
        var diffMs = (cooldown - today); // milliseconds between now
        var diffDays = Math.floor(diffMs / 86400000); // days
        var diffHrs = Math.floor((diffMs % 86400000) / 3600000); // hours
        var diffMins = Math.round(((diffMs % 86400000) % 3600000) / 60000); // minutes

        var box = '<div style="height:30px; display:block;">Xanax Cooldown Ends in: '+diffHrs + ' hours, ' + diffMins + ' minutes </div>';

        $( ".content-title" ).prepend( box );
    }
});