PA planner

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

Você precisará instalar uma extensão como Tampermonkey, Greasemonkey ou Violentmonkey para instalar este script.

Você precisará instalar uma extensão como Tampermonkey para instalar este script.

Você precisará instalar uma extensão como Tampermonkey ou Violentmonkey para instalar este script.

Você precisará instalar uma extensão como Tampermonkey ou Userscripts para instalar este script.

Você precisará instalar uma extensão como o Tampermonkey para instalar este script.

Você precisará instalar um gerenciador de scripts de usuário para instalar este script.

(Eu já tenho um gerenciador de scripts de usuário, me deixe instalá-lo!)

Você precisará instalar uma extensão como o Stylus para instalar este estilo.

Você precisará instalar uma extensão como o Stylus para instalar este estilo.

Você precisará instalar uma extensão como o Stylus para instalar este estilo.

Você precisará instalar um gerenciador de estilos de usuário para instalar este estilo.

Você precisará instalar um gerenciador de estilos de usuário para instalar este estilo.

Você precisará instalar um gerenciador de estilos de usuário para instalar este estilo.

(Eu já possuo um gerenciador de estilos de usuário, me deixar fazer a instalação!)

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