Last active
January 30, 2018 03:05
-
-
Save shellscape/17270cbaa6175d15c59858b778c150a7 to your computer and use it in GitHub Desktop.
Restore the Modern, Red Unread Icon in Gmail using ViolentMonkey or TamperMonkey
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 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