Mute Players

Right-click a player to mute them

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

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.

ستحتاج إلى تثبيت إضافة مثل Stylus لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتتمكن من تثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

(لدي بالفعل مثبت أنماط للمستخدم، دعني أقم بتثبيته!)

// ==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)';
	}
}