TORN: OC Payday

Easily do a payday after completing an oc.

当前为 2020-07-23 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         TORN: OC Payday
// @namespace    eu.torned.ocpayday
// @version      1.0.1
// @author       DeKleineKobini
// @description  Easily do a payday after completing an oc.
// @match        https://www.torn.com/factions.php?step=your
// @run-at       document-body
// @grant        none
// ==/UserScript==

new MutationObserver((mutations, observer) => {
    const crimes = $("#faction-crimes");
    if (!crimes.length) return;

    new MutationObserver((mutations, observer) => {
        let found = false;

        for (let mutation of mutations) {
            if (!mutation.addedNodes) continue;

            for (let node of mutation.addedNodes) {
                if (!node.classList || !node.classList.contains("crime-result")) continue;

                found = true;
                break;
            }

            if (found) break;
        }

        if (found) {
            handleCrime();
        }
    }).observe(crimes.get(0), {childList: true});

    observer.disconnect();
}).observe(document, {childList: true, subtree: true});

function handleCrime() {
    const participants = $(".crime-result").attr("data-criminals").slice(1, -1).split(",").map(parseFloat);
    let cashValue = $(".make-wrap > p:eq(0)").text().match(/\$(.*) made/i)[1].replaceAll(",", "");
    while (cashValue.includes(",")) cashValue = cashValue.replace(",", "");
    cashValue = parseInt(cashValue);

    const splitCash = cashValue / participants.length;

    $(".plan-again").append(`<span class="btn-wrap again-btn silver right" title="Pay Day these members."><span class="btn"><a class="torn-btn" href="${getURL(participants, splitCash)}" target="_blank">PAY DAY</a></span></span>`)
}

function getURL(players, amount) {
    return `https://www.torn.com/factions.php?step=your#/tab=controls&option=pay-day&select=${players.join(",")}&pay=${amount}`;
}