PA planner

Automatically check the checkboxes for specified names on the faction crimes page

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         PA planner
// @namespace    adobi.nieltorn.com
// @version      0.3
// @description  Automatically check the checkboxes for specified names on the faction crimes page
// @author       ChatGPT+Adobi
// @match        https://www.torn.com/factions.php*
// @grant        none
// @license      MIT
// ==/UserScript==
 
// Usage: Create and follow a hyperlink with this structure. 4 names will plan a PA, 8 names will plan a PH.
// https://www.torn.com/factions.php?step=your&names=Adobi,Chedburn,Duke,Tiny#/tab=crimes
// It will check checkboxes for those names in the Political Assassination crime.
// Can be modified to pass a different crime as argument if there is demand for that functionality.
 
(function() {
    'use strict';
    // Sometimes the script won't do anything, because the page loaded too slow. Timeout for 2 seconds is my bandaid fix for that.
    setTimeout(() => {
        // Get the query parameter from the URL
        let query = new URLSearchParams(window.location.search);
        let names = query.get("names").toLowerCase().split(",");
        // Kill script if there is no names parameter
        if (!names) {
            return;
        }
 
        // Get all the checkboxes on the page
        let checkboxes = document.querySelectorAll("input[type='checkbox']");
        // Create an array to store the checked checkboxes for debugging purposes
        let checkedBoxes = [];
 
        // Loop through each checkbox
        for (let i = 0; i < checkboxes.length; i++) {
            // Get the checkbox's ID
            let checkboxId = checkboxes[i].id;
 
            // Check if the checkbox's ID contains any of the names
            for (let j = 0; j < names.length; j++) {
                if (names.length === 4 && checkboxId.indexOf("political-assassination-") === 0 && checkboxId.substring(24) === names[j]) {
                    // Check the checkbox
                    checkboxes[i].checked = true;
                    checkedBoxes.push(checkboxId);
                }
                if (names.length === 8 && checkboxId.indexOf("hijack-a-plane-") === 0 && checkboxId.substring(15) === names[j]) {
                    // Check the checkbox
                    checkboxes[i].checked = true;
                    checkedBoxes.push(checkboxId);
                }
 
            }
        }
        //alert(checkedBoxes.join(", "));

        let link = document.querySelector("li.item-wrap.last a.wai-support.t-blue.h");
        link.click();

        // Wait some time, then scroll to bottom of page.
        setTimeout(function() {
            window.scrollTo(0, document.body.scrollHeight);
        }, 800);
    }, 2000);
})();