-
-
Notifications
You must be signed in to change notification settings - Fork 54
Custom badge update JS
The injected javascript interacts with the document as if it is a part of it (so window.* works as expected), and can call the badge update function with a count for any direct notifications, and then indirect notifications.
So you want to identify and count any elements corresponding to a direct or indirect notification, then call the updateBadge function, usually every 3s with the relevant counts.
The function signature is (for Hamsket)
window.hamsket.updateBadge = function(direct, indirect = 0)
This depends heavily on what a user would consider direct or indirect from a particular service. Most services don't have a concept of indirect notifications.
As much as possible, these should be written in a modern style andperform as little work as is feasible for each service while doing the necessary work as quickly as possible.
let checkUnread = () => {
let total = 0;
const counters = document.getElementsByClassName("icq-msg-counter");
for (let counter of counters) {
total += parseInt("block" === counter.style.display ? counter.innerHTML.trim() : 0);
}
hamsket.updateBadge(total);
};
setInterval(checkUnread, 3e3);