Potato Counter (fixed)

Fills in the correct answer (does not auto-submit)

// ==UserScript==
// @name         Potato Counter (fixed)
// @namespace    neopets
// @version      0.2
// @description  Fills in the correct answer (does not auto-submit)
// @match        https://www.neopets.com/medieval/potatocounter.phtml
// @match        http://www.neopets.com/medieval/potatocounter.phtml
// @run-at       document-idle
// @grant        none
// @license MIT
// ==/UserScript==

(function () {
  'use strict';

  function fillGuess(count) {
    var input = document.querySelector("form[action$='potatocounter.phtml'] input[name='guess']");
    if (input) input.value = count;
  }

  function countWithNative() {
    var form = document.querySelector("form[action$='potatocounter.phtml']");
    var table = form && form.previousElementSibling && form.previousElementSibling.tagName === 'TABLE'
      ? form.previousElementSibling
      : null;

    var imgs = (table
      ? table.querySelectorAll("img[src*='/medieval/potato']:not([src*='think'])")
      : document.querySelectorAll("img[src*='/medieval/potato']:not([src*='think'])")
    );

    fillGuess(imgs.length);
  }

  if (window.jQuery) {
    jQuery(function ($) {
      var $form = $("form[action$='potatocounter.phtml']");
      var $table = $form.prev("table");
      var count = $table.find("img[src*='/medieval/potato']:not([src*='think'])").length;

      // Fallback in case the DOM shifts
      if (!count) {
        count = $("img[src*='/medieval/potato']:not([src*='think'])").length;
      }
      $form.find("input[name='guess']").val(count);
    });
  } else {
    if (document.readyState === 'loading') {
      document.addEventListener('DOMContentLoaded', countWithNative);
    } else {
      countWithNative();
    }
  }
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址