Multiplayer Piano Optimizations [Sounds]

Play sounds when users join, leave, or mention you in Multiplayer Piano

当前为 2025-07-14 提交的版本,查看 最新版本

// ==UserScript==
// @name         Multiplayer Piano Optimizations [Sounds]
// @namespace    http://tampermonkey.net/
// @version      1.0.4
// @description  Play sounds when users join, leave, or mention you in Multiplayer Piano
// @author       zackiboiz, cheezburger0
// @match        *://multiplayerpiano.com/*
// @match        *://multiplayerpiano.net/*
// @match        *://qmppv2.qwerty0301.repl.co/*
// @match        *://mpp.8448.space/*
// @match        *://mpp.autoplayer.xyz/*
// @match        *://mpp.hyye.xyz/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=multiplayerpiano.net
// @grant        none
// @license      MIT
// ==/UserScript==

(async () => {
    const MPP = window.MPP;
    const version = "1.0.4";

    if (!MPP.chat.sendPrivate) {
        MPP.chat.sendPrivate = ({ name, color, message }) => {
            MPP.chat.receive({
                m: "a",
                t: Date.now(),
                a: message,
                p: {
                    _id: "usrscr",
                    id: "userscript",
                    name,
                    color
                }
            });
        };
    }

    const SOUNDS = {
        MENTION: "https://files.catbox.moe/f5tzag.mp3",
        JOIN: "https://files.catbox.moe/t3ztlz.mp3",
        LEAVE: "https://files.catbox.moe/kmpz7e.mp3"
    };

    const lastPlayed = {};
    const GAP_MS = 200;

    function play(src) {
        const now = Date.now();
        if (!lastPlayed[src] || now - lastPlayed[src] >= GAP_MS) {
            lastPlayed[src] = now;
            const sfx = new Audio(src);
            sfx.play().catch(() => {});
        }
    }

    function handleMessage(msg) {
        const sender = msg.p ?? msg.sender;
        replyMap[msg.id] = sender._id;

        const you = MPP.client.user._id;
        const isMention = msg.a.includes(`@${you}`);
        const isReplyToYou = msg.r && replyMap[msg.r] === you;

        if ((isMention || isReplyToYou) && !document.hasFocus()) {
            play(SOUNDS.MENTION);
        }
    }

    const replyMap = {};
    MPP.client.on("a", handleMessage);
    MPP.client.on("dm", handleMessage);

    MPP.client.on("participant added", () => play(SOUNDS.JOIN));
    MPP.client.on("bye", () => play(SOUNDS.LEAVE));

    MPP.client.on("c", (data) => {
        MPP.chat.sendPrivate({
            name: `[MPP Sounds] v${version}`,
            color: "#ffaa00",
            message: "Sound alerts loaded."
        });
    });
})();

QingJ © 2025

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