Torn Crimes 2.0 - Disposal

Color codes disposal type based on difficulty

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Torn Crimes 2.0 - Disposal
// @version      1.0
// @namespace    https://github.com/Korbrm
// @description  Color codes disposal type 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 crimeTypeMappings = [
        {
            crimeType: 'Biological Waste',
            safe: ['Sink'],
            moderate: [],
            unsafe: ['Bury'],
            risky: ['Burn'],
            dangerous: ['Abandon'],
        }, {
            crimeType: 'Body Part',
            safe: [],
            moderate: [],
            unsafe: [],
            risky: [],
            dangerous: [],
        }, {
            crimeType: 'Building Debris',
            safe: ['Sink'],
            moderate: [''],
            unsafe: ['Abandon'],
            risky: ['Bury'],
            dangerous: [],
        }, {
            crimeType: 'Dead Body',
            safe: [],
            moderate: [],
            unsafe: [],
            risky: [],
            dangerous: [],
        }, {
            crimeType: 'Documents',
            safe: ['Burn'],
            moderate: [],
            unsafe: ['Bury'],
            risky: ['Abandon'],
            dangerous: ['Sink','Dissolve'],
        }, {
            crimeType: 'Firearm',
            safe: [],
            moderate: ['Sink'],
            unsafe: ['Bury'],
            risky: [],
            dangerous: ['Dissolve'],
        }, {
            crimeType: 'General Waste',
            safe: ['Bury'],
            moderate: ['Burn'],
            unsafe: ['Abandon'],
            risky: ['Sink'],
            dangerous: ['Dissolve'],
        }, {
            crimeType: 'Industrial Waste',
            safe: ['Sink'],
            moderate: [],
            unsafe: ['Bury'],
            risky: [],
            dangerous: ['Abandon'],
        }, {
            crimeType: 'Murder Weapon',
            safe: ['Sink'],
            moderate: [],
            unsafe: [],
            risky: [],
            dangerous: ['Dissolve'],
        }, {
            crimeType: 'Old Furniture',
            safe: ['Burn'],
            moderate: [''],
            unsafe: ['Abandon', 'Sink'],
            risky: ['Bury'],
            dangerous: ['Dissolve'],
        }, {
            crimeType: 'Broken Appliance',
            safe: ['Sink'],
            moderate: [],
            unsafe: ['Abandon'],
            risky: ['Bury'],
            dangerous: ['Dissolve'],
        }, {
            crimeType: 'Vehicle',
            safe: ['Sink'],
            moderate: ['Burn'],
            unsafe: ['Abandon'],
            risky: [],
            dangerous: [],
        },
    ];

    function changeButtonBorderColor(button, borderColor, borderThickness = '2px') {
        if (button) {
            button.style.border = `${borderThickness} solid ${borderColor}`;
        }
    }

    function applyBorderColorBasedOnCrimeType() {
        const crimeOptionElements = document.querySelectorAll('.crime-option');

        crimeOptionElements.forEach((crimeOptionElement) => {
            const crimeTypeElement = crimeOptionElement.querySelector('.crimeOptionSection___hslpu');
            const crimeTypeText = crimeTypeElement ? crimeTypeElement.textContent.trim() : '';

            const mapping = crimeTypeMappings.find((map) => map.crimeType === crimeTypeText);
            if (mapping) {
                const buttons = crimeOptionElement.querySelectorAll('button[aria-label]');
                buttons.forEach((button) => {
                    const buttonAriaLabel = button.getAttribute('aria-label');
                    if (mapping.safe.includes(buttonAriaLabel)) {
                        changeButtonBorderColor(button, '#37b24d', '4px');
                    } else if (mapping.moderate.includes(buttonAriaLabel)) {
                        changeButtonBorderColor(button, '#74b816');
                    } else if (mapping.unsafe.includes(buttonAriaLabel)) {
                        changeButtonBorderColor(button, '#f59f00');
                    } else if (mapping.risky.includes(buttonAriaLabel)) {
                        changeButtonBorderColor(button, '#f76707');
                    } else if (mapping.dangerous.includes(buttonAriaLabel)) {
                        changeButtonBorderColor(button, '#f03e3e');
                    }
                });
            }
        });
    }

    const observer = new MutationObserver(function(mutationsList) {
        for (let mutation of mutationsList) {
            if (mutation.type === 'childList') {
                applyBorderColorBasedOnCrimeType();
            }
        }
    });

    observer.observe(document.body, { subtree: true, childList: true });
})();