Skip to content

Instantly share code, notes, and snippets.

@viswanathgs
Last active March 24, 2024 11:26
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viswanathgs/72042a6827f557c2c3137e3d49a9113f to your computer and use it in GitHub Desktop.
Save viswanathgs/72042a6827f557c2c3137e3d49a9113f to your computer and use it in GitHub Desktop.
Tampermonkey script to remove unread notification count from tab titles
// ==UserScript==
// @name remove-title-notifications
// @namespace distractions
// @version 0.1
// @description Tampermonkey script to remove unread notification count from tab titles
// @author Viswanath Sivakumar
// @match */*
// @grant none
// ==/UserScript==
// Match titles of the form "(3) Gmail" and replace with "Gmail".
function removeCountFromTitle() {
const re = /^\(\d+\)\s*(.*)/;
const match = re.exec(document.title);
if (match !== null) {
document.title = match[1];
}
}
// Execute `func` when changes to `domElementName` occurs.
function runOnMutation(domElementName, func) {
var observer = new MutationObserver(function(mutations, observer) {
observer.disconnect(); // Pause observer to avoid possible infinite recursion
func();
observer.observe(target, config); // Resume observing
});
var target = document.querySelector(domElementName);
var config = { childList: true };
observer.observe(target, config); // Start listening for mutations
}
(function() {
'use strict';
// Replace original title
removeCountFromTitle();
// Watch for changes to title DOM element
runOnMutation('title', removeCountFromTitle);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment