Domino Tracker Notification

Get notified when the pizza tracker updates!

当前为 2020-06-11 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

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