Last active
October 25, 2024 06:55
-
-
Save viswanathgs/72042a6827f557c2c3137e3d49a9113f to your computer and use it in GitHub Desktop.
Tampermonkey script to remove unread notification count from tab titles
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 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