Torn Addiction Script

Torn Addiction Warning

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         Torn Addiction Script
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Torn Addiction Warning
// @author       Chriserino[2685070]
// @license MIT
// @match        https://www.torn.com/index.php
// @grant        GM_setValue
// @grant        GM_getValue
// ==/UserScript==
let key = GM_getValue("tornApiKey");
let userID = GM_getValue("tornUserID");
let company = [];
let addiction = "";

//Do after loading page
(function() {
    // Set GM Values if not set
    if(key == null || key == ""){
        let apiPrompt = prompt("First Time Setup. \nPlease enter your API Key (located on the preferences page under API Key.)");
        GM_setValue("tornApiKey", apiPrompt); //Saves API Key
    }


    if (userID == null || userID == ""){
        let script = document.getElementsByTagName('script');
        for (let i = 0; i < script.length; i++){
            if (script[i].hasAttributes()){
                let att = script[i].attributes;
                let output = "";
                for ( let j = 0; j < att.length; j++){
                    if (att[j].name == "uid") {
                        output = `${att[j].name} -> ${att[j].value}`;
                        GM_setValue("tornUserID", att[j].value);
                    }
                }
                console.log(output);
            }
        }
    }

    let tornAPI = "https://api.torn.com/company/?selections=employees&key=" + key;

    $.getJSON( tornAPI, function(json){
        try{
            company = json;
        } catch (err) {
            alert("There has been an error while fetching your data. Try resetting your API Key.");
            console.log("err | " + err);
        }
        let count = Object.keys(company.company_employees).length;
        addiction = company.company_employees[userID].effectiveness.addiction;
        if (addiction < 0){$( ".content-title" ).before(`<div style="color: red"><b>Warning! Addiction: ${addiction}</b></div>`);}
        //else {$( ".content-title" ).before(`<div style="color: green"><b>Addiction: ${addiction}</b></div>`);}
    });

    })();