wplace Brown Audio

Play "brown" sound on Brown button

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         wplace Brown Audio
// @namespace    https://wplace.live/
// @version      1.0
// @description  Play "brown" sound on Brown button
// @author       ApertureUA
// @match        *://wplace.live/*
// @license      WTFPLv2.0
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // configurable audio source
    const AUDIO_SRC = "https://soundbuttonsworld.com/uploads/a3551eb5-0f9e-49e3-9718-0980b181b9db.mp3";

    // create hidden audio element
    const audio = document.createElement("audio");
    audio.src = AUDIO_SRC;
    audio.style.display = "none";
    document.body.appendChild(audio);

    // helper to attach event
    function attachEvents(el) {
        el.addEventListener("click", () => {
            audio.currentTime = 0;
            audio.play().catch(e => console.log("Audio play blocked:", e));
        });
    }

    // find existing "Brown" elements
    document.querySelectorAll('[aria-label="Brown"]').forEach(attachEvents);

    // watch for future elements (in case site updates dynamically)
    const observer = new MutationObserver(mutations => {
        for (const m of mutations) {
            for (const node of m.addedNodes) {
                if (node.nodeType === 1) { // element
                    if (node.getAttribute("aria-label") === "Brown") {
                        attachEvents(node);
                    }
                    node.querySelectorAll?.('[aria-label="Brown"]').forEach(attachEvents);
                }
            }
        }
    });

    observer.observe(document.body, { childList: true, subtree: true });
})();