Scripts/owa.js
2019-06-11 16:07:56 +02:00

50 lines
1.4 KiB
JavaScript

// ==UserScript==
// @name OWA
// @namespace Violentmonkey Scripts
// @match https://webmail.med.uni-muenchen.de/owa/*
// @updateURL https://gitea.bmsch.de/balthasar/Scripts/raw/branch/master/owa.js
// @downloadURL https://gitea.bmsch.de/balthasar/Scripts/raw/branch/master/owa.js
// @grant none
// @version 1.1.0
// ==/UserScript==
Notification.requestPermission().then(function(result) {
console.log(result);
});
notified = 0
var matchDigits = RegExp('^\\d+$','');
window.setInterval(function(){
var search = document.querySelectorAll('.ms-font-weight-semibold[title="Posteingang"]')
if (search.length == 0){
// no search result
nMails = 0
}
else {
var x = search[0].parentElement.children[2]
var children = search[0].parentElement.children
nMails = "x"
for (i=0; i<children.length; i++){
ih = children[i].innerHTML
if (matchDigits.test(ih)){
nMails = ih
//console.log("matched "+nMails)
}
}
}
if (document.title.slice(0,1) === "("){
document.title = "("+nMails+') ' + document.title.slice(4)
}
else {
document.title = "("+nMails+') ' + document.title
}
if (nMails > 0){
if (notified < nMails) {
//console.log("OWA: "+nMails+" new mails")
var img = 'https://webmail.med.uni-muenchen.de/owa/prem/15.0.1365.1/resources/images/0/favicon.ico';
var n = new Notification("New mails on OWA: "+nMails, {icon:img});
notified = nMails
}
}
}, 10000);