-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
executable file
·85 lines (66 loc) · 2.13 KB
/
popup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
const msg = new SpeechSynthesisUtterance();
const voice = [];
const voicesDropdown = document.querySelector('[name="voice"]');
const options = document.querySelectorAll('[name="text"]');
const range = document.getElementById("range");
const label = document.getElementById("interval");
function populateVoices(params) {
voices = this.getVoices();
voicesDropdown.innerHTML = voices.map((voice) => `<option value="${voice.name}">${voice.name} (${voice.lang})</option>`).join("");
}
function setVoice() {
msg.voice = voices.find((voice) => voice.name === this.value);
toggle();
}
function toggle(startOver = true) {
speechSynthesis.cancel();
if (startOver) {
msg.text = document.querySelector(`#clock h3`).textContent;
speechSynthesis.speak(msg);
}
}
function setOption() {
console.log(this.name, this.value);
msg[this.name] = this.value;
toggle();
}
function getInterval() {
return range.value * 1000;
}
speechSynthesis.addEventListener("voiceschanged", populateVoices);
voicesDropdown.addEventListener("change", setVoice);
options.forEach((option) => option.addEventListener("change", setOption));
//clock init
function speakTime() {
msg.text = document.querySelector(`#clock h3`).textContent;
speechSynthesis.speak(msg);
console.log(msg);
}
function showTime() {
const date = new Date();
const h = date.getHours();
const m = date.getMinutes();
const s = date.getSeconds();
const clock = `${h < 10 ? 0 : ""}${h}:${m < 10 ? 0 : ""}${m}:${s < 10 ? 0 : ""}${s}`;
const time = `${h < 10 ? 0 : ""}${h}:${m < 10 ? 0 : ""}${m}`;
document.querySelector(`#clock h2`).innerText = clock;
document.querySelector(`#clock h3`).innerText = time;
}
setInterval(showTime, 1000);
var thisInterval = null;
range.addEventListener("input", () => {
interval.innerText = range.value;
const mult = range.value * 60000;
if (thisInterval === null) {
thisInterval = setInterval(speakTime, mult);
} else {
clearInterval(thisInterval);
thisInterval = setInterval(speakTime, mult);
}
});
showTime();
setTimeout(() => {
var e = document.getElementById("voices");
var strUser = (e.options[e.selectedIndex].text = "loremipsum");
console.log(strUser);
}, 1000);