PA planner

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==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);
})();