An experimental script to implement desktop notification for Outlook Web App 2003
当前为
// ==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();
});
}) ();