Desktop Notification for OWA 2003

An experimental script to implement desktop notification for Outlook Web App 2003

目前為 2014-06-11 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @id             41f11ead-b1c5-4b87-a7d8-403c1fe2904f@scriptish
// @name           Desktop Notification for OWA 2003
// @version        0.1
// @namespace      
// @author         Ian Chu
// @description    An experimental script to implement desktop notification for Outlook Web App 2003
// @include        */owa/
// @include        */owa/#
// @run-at         document-end
// ==/UserScript==


(function () {
    var favicon;
    var linkTags = document.getElementsByTagName('head')[0].getElementsByTagName('link');
    for (var i = 0; i < linkTags.length; i++) {
        if (linkTags[i].getAttribute('rel').indexOf('icon') >= 0) {
            favicon = linkTags[i].getAttribute('href');
            break;
        }
    }
    var welcome = function () {
        new Notification(
            'Notification extension for Outlook WebApp', {
                icon: favicon,
                body: 'From now on, when you receive new mail,\n' +
                      'A notification box will appear like this.',
                onclick: function () {
                    window.focus();
                }
            }
        );
    }
    var lastPushedNumber = 0;
    var checkNewMailNotif = function () {
        var lnkNwMl = document.getElementById('lnkNwMl');
        if (lnkNwMl) {
            var pushedNumber = Number(lnkNwMl.getAttribute('_pushed'));
            if (pushedNumber > lastPushedNumber) {
                var newItemDialog = document.getElementById('idNewItmDlg');
                var spans = newItemDialog.getElementsByTagName('span');
                var nwItmTxtFrm, nwItmTxtSbj;
                for (var i = 0; i < spans.length; i++) {
                    if (spans[i].className.indexOf('nwItmTxtFrm') >= 0)
                       nwItmTxtFrm = spans[i];
                    else if (spans[i].className.indexOf('nwItmTxtSbj') >= 0)
                       nwItmTxtSbj = spans[i];
                }
                var mailFrom = nwItmTxtFrm.textContent;
                var mailSubj = nwItmTxtSbj.textContent;
                new Notification(mailFrom, {
                    icon: favicon,
                    body: mailSubj,
                    onclick: function () {
                        window.focus();
                        nwItmTxtFrm.click();
                    }
                });
            }
            lastPushedNumber = pushedNumber;
        } else {
            lastPushedNumber = 0;
        }
    }
    Notification.requestPermission(function (status) {
        if (Notification.permission !== status) {
            Notification.permission = status;
            welcome();
        }
        setInterval(checkNewMailNotif, 1000);
        welcome();
    });
}) ();