Pumpkin Finder

It displays a list of uncollected pumpkins

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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