Crime to Guide Hyperlink

Adds a hyperlink to the title of each crime, so that you can go to Emforus' guides for each crime easily.

Tendrás que instalar una extensión para tu navegador como Tampermonkey, Greasemonkey o Violentmonkey si quieres utilizar este script.

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

Tendrás que instalar una extensión como Tampermonkey o Violentmonkey para instalar este script.

Necesitarás instalar una extensión como Tampermonkey o Userscripts para instalar este script.

Tendrás que instalar una extensión como Tampermonkey antes de poder instalar este script.

Necesitarás instalar una extensión para administrar scripts de usuario si quieres instalar este script.

(Ya tengo un administrador de scripts de usuario, déjame instalarlo)

Tendrás que instalar una extensión como Stylus antes de poder instalar este script.

Tendrás que instalar una extensión como Stylus antes de poder instalar este script.

Tendrás que instalar una extensión como Stylus antes de poder instalar este script.

Para poder instalar esto tendrás que instalar primero una extensión de estilos de usuario.

Para poder instalar esto tendrás que instalar primero una extensión de estilos de usuario.

Para poder instalar esto tendrás que instalar primero una extensión de estilos de usuario.

(Ya tengo un administrador de estilos de usuario, déjame instalarlo)

// ==UserScript==
// @name         Crime to Guide Hyperlink
// @namespace    http://tampermonkey.net/
// @version      v1.0.2
// @description  Adds a hyperlink to the title of each crime, so that you can go to Emforus' guides for each crime easily.
// @author       DZei [2673922], Gemini 3.6 Flash
// @match        https://www.torn.com/page.php?sid=crimes*
// @icon         https://fonts.gstatic.com/s/i/short-term/release/materialsymbolsoutlined/add_link/default/48px.svg
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Hopefully I don't mess this up because this is my first time writing a userscript line-by-line. If you see notes throughout, ignore this, it's for my own learning and self-reflection, and also for you guys to see what I'm doing.
    // I'm using Gemini 3.6 Flash to instruct me on what to do generically because I am clueless on how to code, however everything is found and typed up myself. AI only provides the instructions on what to do and the framework for doing it.
    // Thanks Emforus for these guides :)

    // These are the forum links to each crime guide.
    const CRIME_GUIDES = {
        "SEARCH FOR CASH": "https://www.torn.com/forums.php#/p=threads&f=61&t=16343473",
        "BOOTLEGGING": "https://www.torn.com/forums.php#/p=threads&f=61&t=16341811",
        "GRAFFITI": "https://www.torn.com/forums.php#/p=threads&f=61&t=16344567",
        "SHOPLIFTING": "https://www.torn.com/forums.php#/p=threads&f=61&t=16346491",
        "PICKPOCKETING": "https://www.torn.com/forums.php#/p=threads&f=61&t=16358739",
        "CARD SKIMMING": "https://www.torn.com/forums.php#p=threads&f=61&t=16350490",
        "BURGLARY": "https://www.torn.com/forums.php#p=threads&f=61&t=16353303",
        "HUSTLING": "https://www.torn.com/forums.php#/p=threads&f=61&t=16363421",
        "DISPOSAL": "https://www.torn.com/forums.php#/p=threads&f=61&t=16367936",
        "CRACKING": "https://www.torn.com/forums.php#/p=threads&f=61&t=16373016",
        "FORGERY": "https://www.torn.com/forums.php#/p=threads&f=61&t=16388086",
        "SCAMMING": "https://www.torn.com/forums.php#/p=threads&f=61&t=16418415",
        "ARSON": "https://www.torn.com/forums.php#/p=threads&f=61&t=16510947",
    };

    // This bit is where the real change happens.
    function linkifyHeader() {
        const header = document.querySelector('div[class*="title___"]'); // apparently the bit after title is dynamic due to React/CSS modules that change when Torn updates itself so it's important not to set the full name because if it changes in the future, then this script might break.

        if (!header || header.dataset.linked) return; // !header checks if it's NOT on the page, || means OR logic, dataset stores variables inside HTML using data- prefix and I assume linked is the variable.

        const rawText = header.innerText.trim().toUpperCase();
        const guideUrl = CRIME_GUIDES[rawText];

        if (guideUrl) {
            header.dataset.linked = "true";
            header.innerHTML = `<a href="${guideUrl}" target="_blank" style="color: inherit; text-decoration: underline;">${header.innerText}</a>`;
        }
    }

    linkifyHeader(); // this is to run it

    const container = document.querySelector('#react-root') || document.body;
    const observer = new MutationObserver(linkifyHeader); // MutationObserver monitors for DOM changes
    observer.observe(container, { childList: true, subtree: true });
})();