Skip to content

Instantly share code, notes, and snippets.

@rcambrj
Forked from kmwallio/outlook-fluid.js
Last active May 8, 2017 14:54
Show Gist options
  • Save rcambrj/16eb22395bb679191fef to your computer and use it in GitHub Desktop.
Save rcambrj/16eb22395bb679191fef to your computer and use it in GitHub Desktop.
Userscript for badge icon for outlook.office365.com in a Fluid App (SSB).
// use for patterns:
// https://login.microsoftonline.com/*
// https://outlook.office365.com/*
// desktop badge count for https://outlook.office365.com/
(function () {
var logging = false;
function log () {
return logging && console.log.apply(console, ['badge:'].concat(Array.prototype.slice.apply(arguments)));
}
function getBadge() {
return window.fluid.dockBadge;
}
function setBadge(val) {
window.fluid.dockBadge = val;
}
function setOrRemoveBadge(val) {
if (!val) {
val = undefined;
}
return setBadge(val);
}
function extractCountFromUnreadText(text, fallback) {
var res = text.match(/\s*\d+\s*/);
if (res && res.length > 0) {
return parseInt(res[0].trim(), 10);
}
return fallback;
}
function check() {
log('checking...')
var loginPanel = document.querySelector('[id="login_panel"]');
if (loginPanel) {
setBadge('!');
} else {
// attempt to locate the unread count
var favouriteTree = document.querySelector('[id="MailFolderPane.FavoritesFolders"]');
var firstFavourite = favouriteTree && favouriteTree.querySelector('[role=treeitem]');
var unreadSpan = firstFavourite && firstFavourite.querySelector('span[id$=".ucount"]');
var text = '' + (unreadSpan || {}).innerText;
var newBadge = extractCountFromUnreadText(text, 0);
// newBadge should always be an integer here
setOrRemoveBadge(newBadge);
}
window.setTimeout(check, 5000);
};
check();
})();
@rcambrj
Copy link
Author

rcambrj commented Jul 30, 2015

I removed the beep because that's probably better implemented in the notification userscript -> https://gist.github.com/rcambrj/4d1b4fde4e4fa00f938f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment