Mute Players

Right-click a player to mute them

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name        Mute Players
// @namespace   https://greasyfork.org/users/281093
// @match       https://sketchful.io/
// @grant       none
// @version     1.1
// @author      Bell
// @license     MIT
// @copyright   2020, Bell
// @description Right-click a player to mute them
// ==/UserScript==
/* jshint esversion: 6 */

const mutedPlayers = new Set();
const playerList = document.querySelector('#gamePlayersList');

playerList.addEventListener('contextmenu', (e) => {
	if (e.target.tagName === 'UL') return;
	e.preventDefault();

	const player = e.target.querySelector('.gameAvatarName');
	if (!player || player.style.color === 'teal') return;
	const playerName = player.textContent.trim();

	if (mutedPlayers.has(playerName)) {
		mutedPlayers.delete(playerName);
		player.style.filter = '';
	}
	else {
		mutedPlayers.add(playerName);
		player.style.filter = 'blur(1px) opacity(0.5)';
	}
});

const checkChat = (mutations) => {
	mutations.forEach(mutation => {
		const msgNode = mutation.addedNodes[0];
		if (!msgNode || msgNode.classList.contains('chatAdmin')) return;
		parseMessage(msgNode);
	});
};

const chat = document.querySelector('#gameChatList');
new MutationObserver(checkChat).observe(chat, { childList: true });

function parseMessage(msg) {
	let sender = msg.querySelector('b').textContent.trim();
	sender = sender.substring(0, sender.length - 1).trim();
	if (mutedPlayers.has(sender)) msg.remove();
}

new MutationObserver((mutations) => {
	mutations.forEach(mutation => {
		mutation.addedNodes.forEach(checkPlayer);
	});
}).observe(playerList, { childList: true });

function checkPlayer(playerNode) {
	const player = playerNode.querySelector('.gameAvatarName');
	if (!player) return;
	
	const playerName = player.textContent.trim();
	
	if (mutedPlayers.has(playerName)) { 
		player.style.filter = 'blur(1px) opacity(0.5)';
	}
}