Raw Source
pwner77x / TORN: Safe Crimes

// ==UserScript==
// @name         TORN: Safe Crimes
// @version      1.0.2
// @author       DeKleineKobini
// @description  Help with doing safe crimes.
// @namespace    dekleinekobini.safecrimes
// @updateURL    https://openuserjs.org/meta/DeKleineKobini/TORN_Safe_Crimes.meta.js
// @downloadURL  https://openuserjs.org/install/DeKleineKobini/TORN_Safe_Crimes.user.js
// @require      https://openuserjs.org/src/libs/DeKleineKobini/DKK_Torn_Utilities.js
// @match        https://www.torn.com/crimes.php*
// @license      MIT
// @grant        none
// ==/UserScript==

var settings = {
    onlySafe: true
};

setDebug(false);

/* --------------------
CODE - EDIT ON OWN RISK
-------------------- */
setPrefixEasy("SC");

const SAFE_CRIMES = {
    searchstreets : ["movie"],
    shoplift: {
        clothesshop: [ "jacket" ]
    }, // special case
    pickpocket: [ "kid", "oldwoman", "businessman" ],
    robsweetshop: [ "thoroughrobbery" ],
    virus: [ "stealthvirus" ],
    assasination: [ "murdermobboss" ],
    arson: [ "warehouse" ],
    kidnapping: [ "napmayor" ],
}

const NERVE_CRIMES = {
    2: 'searchstreets',
    3: 'sellcopiedcds',
    4: 'shoplift',
    5: 'pickpocket',
    6: 'larceny',
    7: 'robsweetshop',
    8: 'transportdrugs',
    9: 'virus',
    10: 'assasination',
    11: 'arson',
    12: 'gta',
    13: 'pawnshop',
    14: 'counterfeiting',
    15: 'kidnapping',
    16: 'armstraffic',
    17: 'bombings',
    18: 'hacking',
}

const MENU_TEXT = {
    'Which item would you like to steal from the clothes shop?': "clothesshop"
}

observeMutations(document, ".specials-cont", true, function(obs){
    applySafeCrimes();

    observeMutations($(".content-wrapper")[0], ".specials-cont", false, function(obs){
        applySafeCrimes();
    });
}, { childList: true, subtree: true });

function applySafeCrimes() {
    let action = $("form[name='crimes']:not([class])").attr("action");
    action = action.substring(action.indexOf("step=") + 5);

    if (action == "docrime") {
        $(".specials-cont > li").each(function() {
            let row = $(this).find("ul");
            let crime = row.find(".choice-container > input").attr("value");
            let safe = SAFE_CRIMES.hasOwnProperty(crime);

            doAction(row, safe);
        });
    } else if (action == "docrime2") {
        debug("No safe crimes here.")
    } else if (action == "docrime3") {
        let nerve = $(".specials-cont-wrap input[name='nervetake']").attr("value")
        let crime = NERVE_CRIMES[nerve];
        let crimesSafe = SAFE_CRIMES[crime];

       $(".specials-cont > li").each(function() {
            let row = $(this).find("ul");
            let subcrime = row.find(".choice-container > input").attr("value");
            let safe = crimesSafe.hasOwnProperty(subcrime);

            doAction(row, safe);
        });
    } else if (action == "docrime4") {
        let nerve = $(".specials-cont-wrap input[name='nervetake']").attr("value")
        let crime = NERVE_CRIMES[nerve];
        let crimesSafe = SAFE_CRIMES[crime];

        if (!Array.isArray(crimesSafe)) {
            let menu = MENU_TEXT[$(".info-msg .msg").html().split("\n")[1]];
            debug($(".info-msg .msg").html().split("\n")[1]);
            debug(MENU_TEXT[$(".info-msg .msg").html().split("\n")[1]]);
            crimesSafe = crimesSafe[menu];
        }

        $(".specials-cont > li").each(function() {
            let row = $(this).find("ul");
            let subcrime = row.find(".choice-container > input").attr("value");
            let safe = crimesSafe && crimesSafe.includes(subcrime);

            doAction(row, safe);
        });
    }
}

function doAction(row, safe) {
    if (settings.onlySafe && !safe) {
        row.parent().hide();
    } else if (!settings.onlySafe && safe){
        row.css("background-color", "green");
    }
}