Domino Tracker Notification

Get notified when the pizza tracker updates!

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

You will need to install an extension such as Tampermonkey to install this script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         Domino Tracker Notification
// @namespace    http://tampermonkey.net/
// @version      0.5
// @description  Get notified when the pizza tracker updates!
// @author       Therrom
// @include      /https://.*\.dominos\.[\w]+/.*/
// @grant        GM_notification
// ==/UserScript==

(function() {
    'use strict';

    setInterval(function() {checkTracker();}, 1000);
})();

let currentText = undefined;
let utter = undefined;

function checkTracker() {
    const tempText = document.querySelector("div p[role=status]")?.innerHTML
    if (tempText) {
        if (tempText != currentText) {
            currentText = tempText;
            GM_notification({title: 'Tracker Update', text: currentText, timeout: 1000});
            speak(currentText);
        }
    }
}

function speak(text) {
    if(window.speechSynthesis.getVoices().length == 0) {
        window.speechSynthesis.addEventListener('voiceschanged', function() {
            speak(text);
        });
    } else {
        if (utter === undefined) {
            detectVoice();
        }
        utter.text = text;
        window.speechSynthesis.speak(utter);
    }
}

function detectVoice() {
    let available_voices = window.speechSynthesis.getVoices();

    let voice = undefined;
    let defaultVoice = undefined;
    let language = window.navigator.userLanguage || window.navigator.language;

    for (let i=0; i<available_voices.length; i++) {
        if(available_voices[i].default) {
            defaultVoice = available_voices[i];
        }
        if (available_voices[i].lang == language) {
            voice = available_voices[i];
            break;
        }
    }

    if (voice === undefined) {
        voice = defaultVoice;
    }
    if (voice === undefined) {
        voice = available_voices[0]
    }

    utter = new SpeechSynthesisUtterance();
    utter.rate = 1;
    utter.pitch = 0.5;
    utter.voice = voice;
}