Created
January 28, 2024 20:40
-
-
Save nunocunha/4ef42efe582633a4657112a754c1bd3c to your computer and use it in GitHub Desktop.
Remove Youtube notification counter
This file contains hidden or 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 Remove Youtube notification counter | |
// @match *://youtube.com/* | |
// @match *://*.youtube.com/* | |
// @run-at document-idle | |
// @version 202401282042 | |
// @author Nuno Cunha | |
// @homepage https://gist.github.com/nunocunha/4ef42efe582633a4657112a754c1bd3c | |
// ==/UserScript== | |
(() => { | |
const fixTitle = (() => { | |
let previousTitle = ''; | |
return (titleNode) => { | |
const hasTitle = titleNode !== undefined && titleNode !== null; | |
if (hasTitle && previousTitle !== titleNode.textContent) { | |
titleNode.textContent = titleNode.textContent.replace(/^\(\d+\)\s+/, ''); | |
previousTitle = titleNode.textContent; | |
} | |
}; | |
})(); | |
const observer = new MutationObserver((mutations) => fixTitle(mutations[0]?.target)); | |
observer.observe( | |
document.querySelector('title'), { | |
subtree: true, | |
characterData: true, | |
childList: true | |
} | |
); | |
fixTitle(document.querySelector('title')); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment