P&W Auto Set Ship Amount

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

  1. // ==UserScript==
  2. // @name P&W Auto Set Ship Amount
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.4
  5. // @description Instantly sets ship amount to 1 on the naval battle page in Politics and War
  6. // @author MangoTheGoat
  7. // @match https://politicsandwar.com/nation/war/navalbattle/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. function setShipAmount() {
  15. let shipInput = document.querySelector('input#attShips, input[name="attShips"]');
  16.  
  17. if (shipInput) {
  18. shipInput.value = 1;
  19. shipInput.dispatchEvent(new Event('input', { bubbles: true }));
  20. console.log("Ship amount set to 1 automatically.");
  21. } else {
  22. console.error("Ship quantity input field not found!");
  23. }
  24. }
  25.  
  26. let attempts = 0;
  27. let interval = setInterval(() => {
  28. if (document.readyState === "complete" || attempts >= 20) {
  29. clearInterval(interval);
  30. setShipAmount();
  31. }
  32. attempts++;
  33. }, 100);
  34.  
  35. })();