Skip to content

Instantly share code, notes, and snippets.

@lyc8503
Created February 8, 2026 14:20
Show Gist options
  • Select an option

  • Save lyc8503/639f4b95aa04b1b0c7f9541e8c7f2560 to your computer and use it in GitHub Desktop.

Select an option

Save lyc8503/639f4b95aa04b1b0c7f9541e8c7f2560 to your computer and use it in GitHub Desktop.
A Tampermonkey script to hide messages from blocked users in Telegram group chats (works in Telegram Web Version K)
// ==UserScript==
// @name Telegram Block Chat Message
// @namespace https://github.com/lyc8503
// @version 2026-02-08
// @description Block annoying users' messages everywhere (e.g. in Groups, Channels); Middle click someone's avatar to add to blocklist
// @author lyc8503
// @match https://web.telegram.org/*
// @grant GM_registerMenuCommand
// ==/UserScript==
(function() {
'use strict';
const KEY = 'telegram_block_list';
const getList = () => { try { return JSON.parse(localStorage.getItem(KEY) || '[]'); } catch { return []; } };
const setList = (l) => localStorage.setItem(KEY, JSON.stringify([...new Set(l)]));
const process = () => {
const list = getList();
document.querySelectorAll('.bubbles-group-avatar-container').forEach(container => {
const idDiv = container.querySelector('[data-peer-id]');
if (!idDiv) return;
const uid = idDiv.dataset.peerId;
// Hide already blocked users' message bubble
if (list.includes(uid)) {
const group = container.closest('.bubbles-group');
if (group) group.style.display = 'none';
}
// Middle click listener
if (!container.dataset.hasBlockListener) {
container.dataset.hasBlockListener = '1';
container.addEventListener('mousedown', function(e) {
if (e.button === 1) {
e.preventDefault();
e.stopPropagation();
if (confirm(`Block User ID: ${uid}?`)) {
setList([...getList(), uid]);
const group = container.closest('.bubbles-group');
if (group) group.style.display = 'none';
}
}
}, { capture: true });
}
});
};
GM_registerMenuCommand('Manage blocklist', () => {
const input = prompt('Current blocked users:', JSON.stringify(getList()));
if (input) {
try { setList(JSON.parse(input)); location.reload(); } catch { alert('Invalid JSON format'); }
}
});
new MutationObserver(process).observe(document.body, { childList: true, subtree: true });
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment