-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
102 lines (93 loc) · 2.5 KB
/
script.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
var base = window.location.href;
if(base.includes("?")) {
base = base.split("?")[0];
}
console.log(base);
setInterval(getCounter, 1000);
//getCounter();
var sound=false;
function enableSound(e){
sound = true;
console.log("sound enabled")
e.style.display = "none";
}
// timer zum aktualisieren
// als aller erstes laden
// wenn event dann daten updaten und erzeugen
function getCounter() {
// use fetch on the /posts route, then pass the response along
fetch(base + "/json").then((response) => {
// with the response, convert it to JSON, then pass it along
response.json().then((json) => {
// print that JSON
console.log(json);
document.querySelector("#data").innerHTML = json.counter;
let audio = document.querySelector("#audio");
if(sound) {
playSound(audio, json["playSound"], json["sound-file"]);
}
});
});
}
function playSound(audio, shouldplaysound, soundfile) {
if (shouldplaysound) {
if (!(audio.paused || audio.ended)) {
console.debug("audio is still playing. Do nothing.");
} else {
audio.loop = false;
audio.muted = false;
audio.preload = true;
audio.src = soundfile;
audio.load();
audio.play();
fetch(base + "/played").then((response) => {
// if change then play sound
response.json().then((json) => {
console.log("done");
});
});
}
}
}
function increment() {
fetch(base + "/inc").then((response) => {
// with the response, convert it to JSON, then pass it along
response.json().then((json) => {
// print that JSON
console.log(json);
// if change then play sound
});
});
}
function decrement() {
fetch(base + "/dec").then((response) => {
// with the response, convert it to JSON, then pass it along
response.json().then((json) => {
// print that JSON
console.log(json);
// if change then play sound
});
});
}
function reset() {
fetch(base + "/reset").then((response) => {
// with the response, convert it to JSON, then pass it along
response.json().then((json) => {
// print that JSON
console.log(json);
// if change then play sound
});
});
}
function set() {
var url = new URL(base + "/set");
url.searchParams.append("n", 15);
fetch(url).then((response) => {
// with the response, convert it to JSON, then pass it along
response.json().then((json) => {
// print that JSON
console.log(json);
// if change then play sound
});
});
}