arson

quick links for arson

目前為 2025-11-12 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         arson
// @namespace    arson.zero.nao
// @version      0.1
// @description  quick links for arson
// @author       nao [2669774]
// @match        https://www.torn.com/page.php*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=torn.com
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    if (!window.location.href.includes("arson")) {
        return;
    }

    let api = "";
    let url = window.location.href;
    let rfc = getRFC();

    let igniters = [1466, 544, 742]; // igniters: windproof lighter, molotov, lighter
    let dampers = [1235, 833, 1463]; // fire extinguisher, sand, blanket

    const priority = [172, 1461, 544, 1235]; // gasoline, thermite, windproof, blanket


    function getRFC() {
        var rfc = $.cookie('rfc_v');
        if (!rfc) {
            var cookies = document.cookie.split('; ');
            for (var i in cookies) {
                var cookie = cookies[i].split('=');
                if (cookie[0] == 'rfc_v') {
                    return cookie[1];
                }
            }
        }
        return rfc;
    }

    const data = {};

    const { fetch: origFetch } = window;
    window.fetch = async (...args) => {
        const response = await origFetch(...args);

        if (response.url.includes("crimesData&step=crimesList") && window.location.href.includes("arson")) {
            response
                .clone()
                .json()
                .then(function(body) {
                    const targets = body.DB?.crimesByType?.targets;
                    const availableList = body.DB?.crimesByType?.availableItems.reduce((acc, cur) => {
                        acc.push(cur.itemID);
                        return acc;
                    }, []);


                    for (const target of targets) {
                        const title = target.title;
                        const story = target.story;
                        const subID = target.subID;
                        const recommended = target.suitable;
                        const available = target.itemsNeeded;

                        const key = title + story;


                        const items = [];

                        for (const item of available) {
                            if (!availableList.includes(item)) {
                                continue;
                            }
                            items.push(item);
                        }

                        data[key] = {
                            subID,
                            recommended,
                            items
                        };
                    }

                })
                .catch((err) => console.error(err));
        }

        console.log(data);
        setTimeout(insert, 200);
        return response;
    };


    function insert() {
        document.querySelectorAll("div[class^='virtualList_'] > div").forEach(function(el) {
            const titleStory = el.querySelector("div[class^='titleAndScenario']");
            if (!titleStory) return;
            let title = titleStory?.textContent;
            if (!title) {
                const zeroId = titleStory.getAttribute("zero-id");
                if (zeroId) {
                    title = zeroId;
                }
                else {

                    return;
                }
            }

            console.log(title, data[title]);



            if (data[title]) {
                const div = document.createElement("div");
                div.style.display = "flex";
                div.style.width = "100%";
                div.style.overflowX = "auto";
                div.style.overflowY = "hidden";
                div.style.scrollbarWidth = "none"; // Firefox
                div.style.msOverflowStyle = "none"; // IE/Edge
                div.id = "zero_" + title;

                const style = document.createElement("style");
                style.textContent = `
        #${div.id}::-webkit-scrollbar { display: none; }
        #${div.id} img.recommended {
            box-shadow: 0 0 6px 1px rgba(0, 255, 0, 0.6);
        }
    `;
                document.head.appendChild(style);

                const { subID, items, recommended } = data[title];
                if (items.length === 0) return;

                const ordered = [
                    ...items.filter(i => priority.includes(i)),
                    ...items.filter(i => !priority.includes(i))
                ];

                for (const item of ordered) {
                    const img = document.createElement("img");
                    img.src = `/images/items/${item}/medium.png`;
                    img.style.width = "50px"
                    img.style.border = "1px solid green";
                    img.style.margin = "2px";
                    img.style.flexShrink = "0";
                    img.style.cursor = "pointer";

                    if (recommended && recommended.includes(item)) {
                        img.classList.add("recommended");
                    }

                    img.addEventListener("click", function() {
                        img.style.border = "1px solid yellow";
                        img.style.backgroundColor = "rgba(255,255,0,0.2)";
                        let crimeVal = 331;

                        if (dampers.includes(item)) {
                            crimeVal = 334;
                        }

                        if (igniters.includes(item)) {
                            crimeVal = 332;
                        }

                        $.post(
                            `https://www.torn.com/page.php?sid=crimesData&step=attempt&typeID=13&crimeID=${crimeVal}&value1=${subID}&value2=${item}&rfcv=${rfc}`,
                            function(response) {
                                const responseJson = response;
                                const success = responseJson.DB?.outcome?.result != "error";
                                img.style.border = success ? "1px solid green" : "1px solid red";
                                img.style.backgroundColor = success
                                    ? "rgba(0,255,0,0.2)"
                                    : "rgba(255,0,0,0.2)";
                                setTimeout(() => {
                                    img.style.backgroundColor = "";
                                    img.style.border = "1px solid green";
                                }, 500);
                            }
                        ).fail(() => {
                            img.style.border = "1px solid red";
                            img.style.backgroundColor = "rgba(255,0,0,0.2)";
                            setTimeout(() => {
                                img.style.backgroundColor = "";
                                img.style.border = "1px solid green";
                            }, 500);
                        });
                    });

                    div.appendChild(img);
                }

                titleStory.innerHTML = "";
                titleStory.setAttribute("zero-id", title);
                titleStory.style.overflow = "hidden";
                titleStory.appendChild(div);
            }


        });


    }

})();