-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
51 lines (43 loc) · 1.28 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
$(document).ready(function () {
const $play = $("#play");
const $stream = $("#stream");
const $title = $("#title");
const $cover = $("#cover img");
textFit($play, {alignHoriz: true, alignVert: true});
var initialLoadingDone = false;
var originalDocumentTitle = document.title;
$stream.on("canplay", function () {
initialLoadingDone = true;
$("#stream").trigger("play");
});
function ajax() {
$.getJSON("https://streamdata.radiohitwave.com/api/", function (data) {
$cover.attr("src", data.cover);
$title.html(data.title);
document.title = originalDocumentTitle + " | " + data.title;
textFit($title, {alignHoriz: true, alignVert: true, maxFontSize: 22});
});
}
const playIcon = $("#play i");
$stream.on("play pause", function () {
if (!initialLoadingDone) {
playIcon.addClass("fa-spin fa-spinner");
return;
}
playIcon.toggleClass("fa-play fa-pause");
playIcon.removeClass("fa-spin fa-spinner");
});
$play.on("click", function () {
const nativeStream = $stream[0];
if (nativeStream.paused) {
nativeStream.play();
} else if (nativeStream.readyState >= 3) {
nativeStream.pause();
}
});
ajax();
setInterval(ajax, 5000);
setTimeout(() => {
$("body").css("visibility", "visible");
}, 100);
});