Torn Addiction Script

Torn Addiction Warning

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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

    })();