arson

quick links for arson

当前为 2025-11-14 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         arson
// @namespace    arson.zero.nao
// @version      0.2
// @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';


    function main() {

        if (!window.location.href.includes("arson")) {
            return;
        }

        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) => {
                            if (cur.total > 0) 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 = [];
                            const availableActions = target.availableActions.reduce((acc, cur) => {
                                acc.push(cur.crimeID);
                                return acc;
                            }, []);

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

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

                    })
                    .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, availableActions } = 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 (availableActions.includes(333)) { // check if stoking is available
                                crimeVal = 333;
                            }

                            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);
                }


            });


        }
    }


    if (window.location.href.includes("sid=crimes")) {
        if (window.location.href.includes("arson")) {
            main();
        }
        else {
            const urlChecker = setInterval(() => {
                if (window.location.href.includes("arson")) {
                    clearInterval(urlChecker);
                    main();
                }
            },
                500);
        }
    }
})();