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.

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

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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 });
})();