Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Restore the Modern, Red Unread Icon in Gmail using ViolentMonkey or TamperMonkey
// ==UserScript==
// @name Gmail Count Red
// @namespace Violentmonkey Scripts
// @match *://mail.google.com/*
// @grant none
// ==/UserScript==
function fix (link) {
const href = link.getAttribute('href');
link.setAttribute('href', href.replace('-b', '_2x'));
}
const iconInterval = setInterval(() => {
const link = document.querySelector('link[rel=icon]');
if (link) {
clearInterval(iconInterval);
fix(link);
const observer = new MutationObserver(((mutations) => {
mutations.forEach((mutation) => {
const nodes = mutation.addedNodes || [];
const child = mutation.type === 'childList';
if (child && nodes.length && nodes[0].nodeName === 'LINK') {
fix(nodes[0])
}
});
}));
observer.observe(document.head, {
attributes: true,
childList: true,
characterData: true
});
}
}, 100);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment