Skip to content

Instantly share code, notes, and snippets.

@fallaciousreasoning
Last active November 18, 2019 23:11
Show Gist options
  • Save fallaciousreasoning/5a046f8f1fe12b10bd115545fc6f503e to your computer and use it in GitHub Desktop.
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.
// ==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