OC - Prevent Joining Low %

Prevents joining OCs if success rate is too low

当前为 2025-02-26 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         OC - Prevent Joining Low %
// @namespace    Titanic_
// @version      1.0
// @description  Prevents joining OCs if success rate is too low
// @author       Titanic_ [2968477]
// @license      MIT
// @match        https://www.torn.com/factions.php?step=your*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    // minimum %
    const LEVEL_REQUIREMENTS = {
        7:  75,
        8:  65,
        9:  0,
        10: 0
    };

    function observe() {
        if (!window.location.href.includes("tab=crimes")) return;

        if (window.OCCheckInterval) clearInterval(window.OCCheckInterval);
        window.OCCheckInterval = setInterval(() => {
            if (document.querySelector("[class*=joinButton_]")) process();
        }, 500);
    }

    function process() {
        document.querySelectorAll("#faction-crimes-root div[class*=contentLayer_]").forEach(row => {
            if (row.dataset.checked !== undefined) return;

            const ocLevel = parseInt(row.querySelector("span[class*=levelValue_]").textContent)
            if (!ocLevel) return console.warn("Failed to find OC Level");

            const minSuccessRate = LEVEL_REQUIREMENTS[ocLevel];
            if (minSuccessRate === undefined) return;

            row.querySelectorAll("[class*=joinButton_]").forEach(btn => {
                const successRate = parseInt(btn.closest("[class*=wrapper]")?.querySelector("[class*=successChance]").textContent)
                if (!successRate) return console.warn("Failed to find OC Success Rate");

                if (successRate < minSuccessRate) btn.disabled = true;
            });

            row.dataset.checked = "checked";
        });
    }

    window.addEventListener("hashchange", observe);
    observe();
})();