Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nunocunha/4ef42efe582633a4657112a754c1bd3c to your computer and use it in GitHub Desktop.
Save nunocunha/4ef42efe582633a4657112a754c1bd3c to your computer and use it in GitHub Desktop.
Remove Youtube notification counter
// ==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