Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Userscript you can use with Fluid App to add a counter to the dock.
/*
Fluid App Userscript
FastMail web interface
URL pattern: *www.fastmail.com*
*/
// For best results, make sure to turn on desktop notifications
// in fastmail. Otherwise the counter will only update every 90s
// instead of instantly.
(function() {
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
};
};
function getFolderCount(name) {
var folderEl = document.getElementsByClassName('v-FolderSource--' + name)[0];
if (!folderEl) return 0;
var badgeEl = folderEl.getElementsByClassName('v-FolderSource-badge')[0];
if (!badgeEl) return 0;
return parseInt(badgeEl.innerText.trim()) || 0;
}
function updateBadge() {
var inboxCount = getFolderCount('inbox');
console.log("Badge = " + inboxCount);
if (inboxCount > 0) {
window.fluid.dockBadge = inboxCount;
} else {
window.fluid.dockBadge = "";
}
}
var debounceUpdateBadge = debounce(updateBadge, 1000);
window.setTimeout(updateBadge, 2000);
window.setTimeout(updateBadge, 5000);
window.setTimeout(updateBadge, 10000);
window.setInterval(updateBadge, 90000);
var oldNotify = window.Notification;
window.Notification = function(title, opt) {
if (window.fluid.dockBadge && window.fluid.dockBadge !== "") {
window.fluid.dockBadge++;
} else {
window.fluid.dockBadge = 1;
}
new oldNotify(title, opt);
}
document.addEventListener('keydown', debounceUpdateBadge);
})();
@YANOUSHek

This comment has been minimized.

Copy link

@YANOUSHek YANOUSHek commented Sep 17, 2020

Are you still using fluid? Mine stopped showing the badge icon and I can't figure out why. The code properly sets the window.fluid.dockBadge property, but the badge isn't shown.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.