Greasy Fork is available in English.
Play sounds when users join, leave, or mention you in Multiplayer Piano
当前为
// ==UserScript==
// @name Multiplayer Piano Optimizations [Sounds]
// @namespace http://tampermonkey.net/
// @version 1.0.3
// @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.3";
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) {
replyMap[msg.id] = msg.p._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."
});
});
})();