Torn Crimes 2.0 - Disposal - Fixed

Color codes disposal type based on difficulty

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Torn Crimes 2.0 - Disposal - Fixed
// @version      1.1
// @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], GNSC4 [3960752]
// @license      MIT License
// @match        https://www.torn.com/page.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 });
})();