Last active
November 18, 2019 23:11
-
-
Save fallaciousreasoning/5a046f8f1fe12b10bd115545fc6f503e to your computer and use it in GitHub Desktop.
Uses the experimental Badging API to Badge messenger.com when installed as a desktop PWA.
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 Messenger.com Unread Count | |
// @namespace Violentmonkey Scripts | |
// @match https://www.messenger.com/* | |
// @grant none | |
// ==/UserScript== | |
const getUnreadCount = () => { | |
return document.querySelectorAll('._1ht3').length; | |
} | |
const updateUnreadCount = () => { | |
const Badge = navigator.setAppBadge || navigator.setExperimentalAppBadge; | |
if (!Badge) | |
return; | |
const unreadCount = getUnreadCount(); | |
Badge.call(navigator, unreadCount); | |
} | |
const poll = (func, regularity) => { | |
func(); | |
setTimeout(() => { | |
poll(func, regularity); | |
}, regularity) | |
}; | |
poll(updateUnreadCount, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment