Created
December 8, 2023 15:34
-
-
Save rmnmjw/5b327cc923d92008ea39670664a89be6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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