Greasy Fork is available in English.

Pumpkin Finder

It displays a list of uncollected pumpkins

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Pumpkin Finder
// @namespace    http://tampermonkey.net/
// @version      1.0.1
// @description  It displays a list of uncollected pumpkins
// @author       Diramix
// @match        https://wplace.live/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=wplace.live
// @grant        none
// ==/UserScript==

(() => {
  const targetSelector = 'body > div > dialog:nth-child(20) > div > div:nth-child(5)';
  const iframeUrl = 'https://wplace.samuelscheit.com/#pumpkins=1';
  let iframe = null;
  let cleanupInterval = null;

  // --- Extract pumpkin numbers from data-tip ---
  function getClaimedNumbers() {
    const el = document.querySelector(`${targetSelector} > div[data-tip]`);
    if (!el) return [];
    const text = el.getAttribute('data-tip') || '';
    const matches = text.match(/#(\\d+)/g) || [];
    return matches.map(n => parseInt(n.replace('#', ''), 10));
  }

  // --- Remove pumpkins inside iframe ---
  function removePumpkins() {
    if (!iframe?.contentDocument) return;

    const doc = iframe.contentDocument;
    const container = doc.querySelector('#pumpkins-modal');
    if (!container) return; // modal not yet loaded

    const claimed = getClaimedNumbers();
    if (!claimed.length) return;

    let removed = 0;
    claimed.forEach(num => {
      container.querySelectorAll('div').forEach(div => {
        const txt = div.innerText || '';
        if (txt.match(new RegExp(`\\b${num}\\b`))) {
          div.remove();
          removed++;
        }
      });
    });

    if (removed > 0) console.log(`[pumpkins] Removed ${removed} pumpkins`);
  }

  // --- Add iframe into the modal ---
  function injectIframe() {
    const container = document.querySelector(targetSelector);
    if (!container) return;
    if (container.querySelector('iframe[src*="wplace.samuelscheit.com"]')) return;

    iframe = document.createElement('iframe');
    iframe.src = iframeUrl;
    iframe.style.width = '100%';
    iframe.style.height = '600px';
    iframe.style.border = '1px solid #444';
    container.appendChild(iframe);

    console.log('[pumpkins] iframe added');

    iframe.addEventListener('load', () => {
      console.log('[pumpkins] iframe loaded');
      const tryRemove = () => {
        if (!document.body.contains(iframe)) {
          clearInterval(cleanupInterval);
          cleanupInterval = null;
          return;
        }
        removePumpkins();
      };

      // check every second until pumpkins-modal appears
      const waitForModal = setInterval(() => {
        if (iframe?.contentDocument?.querySelector('#pumpkins-modal')) {
          clearInterval(waitForModal);
          tryRemove(); // first cleanup
          cleanupInterval = setInterval(tryRemove, 5000); // every 5s
        }
      }, 1000);
    });
  }

  // --- Watch for the dialog to appear ---
  const observer = new MutationObserver(() => {
    const container = document.querySelector(targetSelector);
    if (container) injectIframe();
  });

  observer.observe(document.body, { childList: true, subtree: true });
  console.log('[pumpkins] observer started');
})();