-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
149 lines (140 loc) · 4.27 KB
/
index.html
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<title>SpotifyNowPlaying</title>
<style>
* {
color-scheme: dark light;
}
body {
background-color: rgba(0, 0, 0, 0);
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
font-weight: 600;
margin: 25px;
display: flex;
align-items: center;
}
#artistname {
font-weight: 200;
font-size: 25px;
}
#spotifyrightnow {
position: relative;
background-color: rgba(0, 0, 0, 0.6);
border-radius: 20px;
overflow: hidden;
height: 128px;
width: 100%;
border: 2px solid rgba(0, 0, 0, 0.9);
box-shadow: 7px 5px 5px rgba(0, 0, 0, 0.6);
box-sizing: border-box;
transition: opacity 0.7s;
}
#albumlabel {
position: relative;
top: -1px;
left: -1px;
width: 128px;
height: 128px;
border-radius: 16px 0px 0px 16px;
}
#songinfo {
position: absolute;
top: -1px;
left: 127px;
line-height: 48px;
font-size: 36px;
color: rgba(255, 255, 255, 0.9);
padding: 16px 24px;
overflow: hidden;
width: calc(100% - 128px);
box-sizing: border-box;
}
#songinfo > div {
width: max-content;
will-change: transform;
transition: 5s;
}
</style>
<script>
document.addEventListener("DOMContentLoaded", function () {
let songnameanim, artistnameanim;
//Animation
const animateText = (obj, maxwidth) => {
//Stop animation
obj.css("transition", "unset");
obj.css("transform", "");
//If name width more than block width
if (maxwidth < obj.width()) {
//Restore animation
obj.css("transition", "");
let position = false;
let animate = setInterval(() => {
console.log("tik");
if (!position) {
obj.css(
"transform",
"translateX(-" + (obj.width() - maxwidth) + "px)"
);
} else {
obj.css("transform", "translateX(0px)");
}
position = !position;
}, 6000);
return animate;
} else {
return null;
}
};
const animateTextStop = (animate) => {
clearInterval(animate);
};
let worker = setInterval(() => {
$.ajax({
url: "/getSong",
}).done((data) => {
if (data.is_playing) {
$("#spotifyrightnow").css("opacity", 1);
//Get previous names
let pastname = $("#songname").html();
let pastartistname = $("#artistname").html();
//Set current names
$("#albumlabel").attr("src", data.imageurl);
$("#songname").html(data.titlename);
$("#artistname").html(data.artistname);
if ($("#songname").html() != pastname) {
if (typeof songnameanim != "undefined")
clearInterval(songnameanim);
songnameanim = animateText(
$("#songname"),
$("#songinfo").width()
);
}
if ($("#artistname").html() != pastartistname) {
if (typeof artistnameanim != "undefined")
clearInterval(artistnameanim);
artistnameanim = animateText(
$("#artistname"),
$("#songinfo").width()
);
}
} else {
$("#spotifyrightnow").css("opacity", 0);
}
});
}, 500);
});
</script>
</head>
<body>
<div id="spotifyrightnow">
<img id="albumlabel" alt="" src="/public/image.png"/>
<div id="songinfo">
<div id="songname">Songname</div>
<div id="artistname">Artistname</div>
</div>
</div>
</body>
</html>