TESTE 01

Overlay da Missão para o site WPlace

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         TESTE 01
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Overlay da Missão para o site WPlace
// @author       Víkish
// @match        https://wplace.live/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=partidomissao
// @grant        none
// ==/UserScript==

(function() {
  'use strict';

  function isEditableElement(el) {
    if (!el) return false;
    const tag = el.tagName.toLowerCase();
    return (
      tag === 'input' ||
      tag === 'textarea' ||
      el.isContentEditable
    );
  }

  function isVisible(el) {
    return !!(el && el.offsetWidth > 0 && el.offsetHeight > 0);
  }

  function findPaletteButton() {
    const btns = Array.from(document.querySelectorAll('button, a'));
    return btns.find(b => b.textContent.trim().toLowerCase().includes('pintar'));
  }

  // dispara eventos de pointer (em vez de .click()) para não causar zoom
  function safeClick(el) {
    if (!el) return;
    const rect = el.getBoundingClientRect();
    const opts = { bubbles: true, clientX: rect.x+5, clientY: rect.y+5 };
    el.dispatchEvent(new PointerEvent("pointerdown", opts));
    el.dispatchEvent(new PointerEvent("pointerup", opts));
  }

  (function(){
    function enterKeyHandler(e){
      try{
        if (!(e.key === 'Enter' || e.keyCode === 13)) return;
        if (isEditableElement(document.activeElement)) return;
        if (e.ctrlKey || e.metaKey || e.altKey) return;

        e.preventDefault();
        e.stopImmediatePropagation();
        e.stopPropagation();

        const paintBtn = findPaletteButton();
        if (!paintBtn) return;

        const closeButtons = Array.from(document.querySelectorAll('button.btn.btn-circle.btn-sm'))
          .filter(isVisible);
        const closeIcon = closeButtons.length ? closeButtons[0] : null;
        const isOpen = !!closeIcon;

        if (isOpen) {
          safeClick(closeIcon);
          setTimeout(()=>{
            try { if (document.activeElement && typeof document.activeElement.blur === 'function') document.activeElement.blur(); } catch(e){}
          }, 30);
        } else {
          safeClick(paintBtn);
        }
      }catch(err){}
    }

    function enterKeyUpBlocker(e){
      try{
        if (!(e.key === 'Enter' || e.keyCode === 13)) return;
        if (isEditableElement(document.activeElement)) return;
        if (e.ctrlKey || e.metaKey || e.altKey) return;
        e.preventDefault();
        e.stopImmediatePropagation();
        e.stopPropagation();
      }catch(err){}
    }

    document.addEventListener('keydown', enterKeyHandler, { passive: false, capture: true });
    document.addEventListener('keyup', enterKeyUpBlocker, { passive: false, capture: true });
  })();

})();