Skip to content

Instantly share code, notes, and snippets.

@rmnmjw
Created December 8, 2023 15:34
Show Gist options
  • Save rmnmjw/5b327cc923d92008ea39670664a89be6 to your computer and use it in GitHub Desktop.
Save rmnmjw/5b327cc923d92008ea39670664a89be6 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name telegram.org - show number in title
// @namespace Violentmonkey Scripts
// @match https://web.telegram.org/a/
// @grant none
// @version 1.0
// @author -
// @description 8.12.2023, 16:26:01
// ==/UserScript==
const debounce = (func, wait, immediate) => {
let timeout;
return function() {
const context = this, args = arguments;
const later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
};
const callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
};
};
(() => {
const action = debounce(() => {
const number = document.querySelectorAll('.ChatBadge.unread:not(.muted)').length;
let title = 'Telegram'
if (number) {
title = `${title} (${number})`
}
document.querySelectorAll('title').forEach(el => el.innerHTML = title);
}, 100, true);
const mo = new MutationObserver(action)
mo.observe( document, { childList:true, subtree:true })
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment