Get notified when the pizza tracker updates!
当前为
// ==UserScript==
// @name Domino Tracker Notification
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Get notified when the pizza tracker updates!
// @author Therrom
// @match *://*.dominos.de/eStore/*/Tracker
// @grant none
// ==/UserScript==
(function() {
'use strict';
setInterval(() => checkTracker(), 1000);
})();
var currentStatus = -1;
function checkTracker() {
if (model && model.CurrentStatus && model.CurrentStatus.StatusCode) {
var tempStatus = model.CurrentStatus.StatusCode;
if (tempStatus != currentStatus) {
speak(model.CurrentStatus.StatusText);
currentStatus = tempStatus;
}
}
}
function speak(text) {
// list of languages is probably not loaded, wait for it
if(window.speechSynthesis.getVoices().length == 0) {
window.speechSynthesis.addEventListener('voiceschanged', function() {
textToSpeech(text);
});
}
else {
// languages list available, no need to wait
textToSpeech(text)
}
}
function textToSpeech(text) {
// get all voices that browser offers
var available_voices = window.speechSynthesis.getVoices();
// this will hold an english voice
var voice = '';
for(var i=0; i<available_voices.length; i++) {
if(available_voices[i].default) {
voice = available_voices[i];
break;
}
}
if(voice === '')
voice = available_voices[0];
// new SpeechSynthesisUtterance object
var utter = new SpeechSynthesisUtterance();
utter.rate = 1;
utter.pitch = 0.5;
utter.text = text;
utter.voice = voice;
// speak
window.speechSynthesis.speak(utter);
}