Domino Tracker Notification

Get notified when the pizza tracker updates!

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==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;
}