Torn Pickpocketing Colors

Color codes crimes based on difficulty

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Torn Pickpocketing Colors
// @version      0.4
// @namespace    https://github.com/Korbrm
// @description  Color codes crimes based on difficulty
// @icon         https://www.google.com/s2/favicons?sz=64&domain=torn.com
// @author       Korbrm [2931507]
// @license      MIT License
// @match        https://www.torn.com/loader.php?sid=crimes*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';


    const categoryColorMap = {
        "Safe": "#37b24d",
        "Moderately Unsafe": "#74b816",
        "Unsafe": "#f59f00",
        "Risky": "#f76707",
        "Dangerous": "#f03e3e",
        "Very Dangerous": "#7048e8",
    };

    var sideColorMap = {
        "Safe": "#37b24d",
        "Moderately Unsafe": "#74b816",
        "Unsafe": "#f59f00",
        "Risky": "#f76707",
        "Dangerous": "#f03e3e",
        "Very Dangerous": "#7048e8",
    }

    const tier1 = {
        "Safe": "#37b24d",
        "Moderately Unsafe": "#f76707",
        "Unsafe": "#f03e3e",
        "Risky": "#f03e3e",
        "Dangerous": "#f03e3e",
        "Very Dangerous": "#7048e8",
    }
    const tier2 = {
        "Safe": "#37b24d",
        "Moderately Unsafe": "#37b24d",
        "Unsafe": "#f76707",
        "Risky": "#f03e3e",
        "Dangerous": "#f03e3e",
        "Very Dangerous": "#7048e8",
    }
    const tier3 = {
        "Safe": "#37b24d",
        "Moderately Unsafe": "#37b24d",
        "Unsafe": "#37b24d",
        "Risky": "#f76707",
        "Dangerous": "#f03e3e",
        "Very Dangerous": "#7048e8",
    }
    const tier4 = {
        "Safe": "#37b24d",
        "Moderately Unsafe": "#37b24d",
        "Unsafe": "#37b24d",
        "Risky": "#37b24d",
        "Dangerous": "#f76707",
        "Very Dangerous": "#7048e8",
    }
    const tier5 = {
        "Safe": "#37b24d",
        "Moderately Unsafe": "#37b24d",
        "Unsafe": "#37b24d",
        "Risky": "#37b24d",
        "Dangerous": "#37b24d",
        "Very Dangerous": "#7048e8",
    }

    const markGroups = {
        "Safe": ["Drunk man", "Drunk woman", "Homeless person", "Junkie", "Elderly man", "Elderly woman"],
        "Moderately Unsafe": ["Classy lady", "Laborer", "Postal worker", "Young man", "Young woman", "Student"],
        "Unsafe": ["Rich kid", "Sex worker", "Thug"],
        "Risky": ["Jogger", "Businessman", "Businesswoman", "Gang member", "Mobster"],
        "Dangerous": ["Cyclist"],
        "Very Dangerous": ["Police officer"],
    };

    function updateDivColors() {
        var spanElement = document.querySelector('.value___FdkAT.copyTrigger___fsdzI');

        const url = window.location.href;
        if (!url.includes("#/pickpocketing")){
            return;
        }

        if (spanElement) {
            var pickpocketSkill = spanElement.textContent;
        }
        if (pickpocketSkill < 10) { sideColorMap = tier1; } else
            if (pickpocketSkill < 35) { sideColorMap = tier2; } else
                if (pickpocketSkill < 65) { sideColorMap = tier3; } else
                    if (pickpocketSkill < 80) { sideColorMap = tier4; } else
                    { sideColorMap = tier5; }


        const divElements = document.querySelectorAll('.titleAndProps___DdeVu:not(.processed)');
        divElements.forEach(divElement => {
            const divContent = divElement.querySelector('div').textContent.trim();
            const additionalData = divElement.querySelector('button.physicalPropsButton___xWW45');

            if (additionalData) {
                const additionalText = additionalData.textContent.trim();
                const text = divContent + ' ' + additionalText;

                for (const category in markGroups) {
                    if (markGroups[category].some(group => text.includes(group))) {
                        divElement.querySelector('div').style.color = categoryColorMap[category];
                        if (window.innerWidth > 386) {
                            divElement.querySelector('div').textContent = `${divContent} (${category})`;
                        }

                        divElement.classList.add('processed');
                        let parentElement = divElement;
                        for (let i = 0; i < 3; i++) {
                            parentElement = parentElement.parentElement;
                        }
                        if (!parentElement.classList.contains('processed')) {
                            parentElement.style.borderLeft = `3px solid ${sideColorMap[category]}`;
                            parentElement.classList.add('processed');
                        }
                    }
                }
            }
        });
    }

    updateDivColors();
    setInterval(updateDivColors, 1000);
})();