P&W Auto Set Ship Amount

Instantly sets ship amount to 1 on the naval battle page in Politics and War

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         P&W Auto Set Ship Amount 
// @namespace    http://tampermonkey.net/
// @version      1.4
// @description  Instantly sets ship amount to 1 on the naval battle page in Politics and War
// @author       MangoTheGoat
// @match        https://politicsandwar.com/nation/war/navalbattle/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function setShipAmount() {
        let shipInput = document.querySelector('input#attShips, input[name="attShips"]');

        if (shipInput) {
            shipInput.value = 1;
            shipInput.dispatchEvent(new Event('input', { bubbles: true }));
            console.log("Ship amount set to 1 automatically.");
        } else {
            console.error("Ship quantity input field not found!");
        }
    }

    let attempts = 0;
    let interval = setInterval(() => {
        if (document.readyState === "complete" || attempts >= 20) {
            clearInterval(interval);
            setShipAmount();
        }
        attempts++;
    }, 100);

})();