Outlook OWA Notifier and Unread Title Updater

Update the HTML title with the number of unread messages and notify of new messages

目前為 2016-04-27 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Outlook OWA Notifier and Unread Title Updater
// @version      0.2
// @description  Update the HTML title with the number of unread messages and notify of new messages
// @author       Dan Moore
// @match        */owa/*
// @grant        none
// @namespace    https://greasyfork.org/users/40703
// ==/UserScript==

(function() {    
    Notification.requestPermission();
    
    var $title = $('title');
    var unreadCount = 0;

    setInterval(function() {
        var unread = $('[title=Inbox]').next().next().html();
        var newUnreadCount = unreadCount;
        
        if (unread.length) {
            $title.html(unread + ' - Outlook');
            newUnreadCount = parseInt(unread);
        } else {
            $title.html('Outlook');
            newUnreadCount = 0;
        }
        
        if (newUnreadCount > unreadCount) {
            new Notification("New message in Outlook!");
        }
        
        unreadCount = newUnreadCount;
    }, 1000);

})();