Crime2Types

See crime types next to the names in Crimes 2.0 overview

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Crime2Types
// @description  See crime types next to the names in Crimes 2.0 overview
// @version      1.1
// @namespace    kvassh.crime2types
// @license      MIT
// @icon         https://www.google.com/s2/favicons?sz=64&domain=torn.com
// @homepage     https://greasyfork.org/en/scripts/528153-crime2types
// @author       Kvassh
// @match        https://www.torn.com/loader.php?sid=crimes*
// @run-at       document-end
// @grant        GM_addStyle
// ==/UserScript==

GM_addStyle(`
.c2t { 
    font-size:0.8rem; text-transform:none; 
}
.c2tTheft               { color:#333; border-left: 2px solid #f1948a; padding:5px; } 
.c2tCounterfeiting      { color:#333; border-left: 2px solid #fff59d; padding:5px; } 
.c2tVandalism           { color:#333; border-left: 2px solid #81d4fa; padding:5px; } 
.c2tFraud               { color:#333; border-left: 2px solid #ce93d8; padding:5px; } 
.c2tIllicitServices     { color:#333; border-left: 2px solid #a5d6a7; padding:5px; }
.c2tCybercrime          { color:#333; border-left: 2px solid #ffcc80; padding:5px; }
`);

(function() {
    'use strict';

    function waitForElement(selector) {
        return new Promise(resolve => {
            if (document.querySelector(selector)) {
                resolve(document.querySelector(selector));
            }
            const observer = new MutationObserver(mutations => {
                if (document.querySelector(selector)) {
                    observer.disconnect();
                    resolve(document.querySelector(selector));
                }
            });
            observer.observe(document.body, {
                childList: true,
                subtree: true
            });
        });
    }

    const crimeMappings = {
        "Search for cash":  "Theft",
        "Bootlegging":      "Counterfeiting",
        "Graffiti":         "Vandalism",
        "Shoplifting":      "Theft",
        "Pickpocketing":    "Theft",
        "Card Skimming":    "Fraud",
        "Burglary":         "Theft",
        "Hustling":         "Fraud",
        "Disposal":         "Illicit Services",
        "Cracking":         "Cybercrime",
        "Forgery":          "Counterfeiting",
        "Scamming":         "Fraud",
    };

    const selector = (id) => {
        if (window.innerWidth <= 765) {
            console.log("Using selector for mobile view");
            return `#react-root > div > div.crimes-hub-root > div > a:nth-child(${id}) > [class^='crimeDetails'] > div > span`;
        } else {
            console.log("Using selector for desktop view");
            return `#react-root > div > div.crimes-hub-root > div > a:nth-child(${id}) > [class^='titleBar'] > div > span`;
        }
    }

    function showCrimeTypes() {
        for (let i=0; i <= Object.keys(crimeMappings).length; i++) {
            waitForElement(selector(i)).then(el => {
                const crimeName = el.innerText.toLowerCase().split('(')[0].trim();
                console.log(crimeName);
                for (const [name, type] of Object.entries(crimeMappings)) {
                    if (crimeName.includes(name.toLowerCase())) {
                        el.innerHTML = `${crimeName} <span class="c2t c2t${type.replace(' ', '')}">(${type})</span>`;
                        break;
                    }
                }
            });
        }
    }

    /** Setup event listener for navigation so we can re-add the html after navigating back from subcrime */
    try {
        navigation.addEventListener('navigate', () => {
            setTimeout(() => {
                showCrimeTypes();
            },100);
        });
    } catch (error) {
        log("FATAL ERROR: Could not add EventListener for navigation navigate: " + JSON.stringify(error));
    }

    /** Init the main job */
    showCrimeTypes();

})();