Outlook OWA Notifier and Unread Title Updater

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Outlook OWA Notifier and Unread Title Updater
// @version      0.4
// @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) {
            var summary = $("div[aria-label*='Unread'")
            .attr('aria-label')
            .replace('1 Unread, From ', '')
            .replace('Subject ', '')
            .replace('Files Attached, ', '')
            .replace('Last message ', '')
            .replace('Conversation Collapsed, ', '')
            .trim();
            
            var notification = new Notification(summary);
            
            notification.onclick = function () {
                window.focus();
            };
        }
        
        unreadCount = newUnreadCount;
    }, 1000);

})();