Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

Custom badge update JS

TheGoddessInari edited this page Aug 13, 2019 · 3 revisions

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.

Example

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);
Clone this wiki locally