-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrefined-widget.html
201 lines (177 loc) · 6.87 KB
/
refined-widget.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<table
id="player"
style="
--main-color: #111;
--text-color: #fff;
--border-radius: 50px;
background-color: var(--main-color);
color: var(--text-color);
font-family: 'ubuntu', Arial, sans-serif;
font-size: 4vmin;
border-radius: var(--border-radius);
width: 100%;
height: auto;
position: relative;
overflow-x: hidden;
overflow-y: hidden;
"
>
<!-- Spotify Logo -->
<img
src="https://upload.wikimedia.org/wikipedia/commons/2/26/Spotify_logo_with_text.svg"
alt="Spotify Logo"
style="
width: 20em;
max-width: 10%;
position: absolute;
top: 2em;
right: 2em;
opacity: 0.6;
z-index: 1;
height: auto;
"
/>
<tr height="100%">
<td width="20%" align="center">
<img
id="player-album-art"
style="margin: 1em; max-height: 50vmin; border-radius: var(--border-radius);"
/>
</td>
<td width="80%">
<div id="player-status" style="margin: 1em; font-size: 1.2em;"></div>
<div style="margin: 1em;">
<!-- Song Title as a Link -->
<a id="player-song" href="" target="_blank" style="display: block; font-size: 1.5em; color: var(--text-color); text-decoration: underline; margin-bottom: 0.5em;"></a>
<!-- Artist and Album Pills with Extra Space -->
<div id="pill-container" style="display: none; gap: 0.5em; flex-wrap: wrap; margin-top: 0.5em;">
<a id="player-artist-pill" href="" target="_blank" style="color: var(--text-color); background: #333; padding: 0.5em 1em; border-radius: 9999px; text-decoration: none;"></a>
<a id="player-album-pill" href="" target="_blank" style="color: var(--text-color); background: #333; padding: 0.5em 1em; border-radius: 9999px; text-decoration: none;"></a>
</div>
<div id="player-time" style="position: relative; float: right; top: -0.5em; font-weight: bold; font-size: 1em;"></div>
<!-- Spotify-themed progress bar -->
<div id="player-progress-back" style="background-color: #333; border-radius: 20px; height: 1em; margin-top: 1.5em; box-shadow: inset 0 0 5px rgba(0,0,0,0.5); display: none;">
<div id="player-progress" style="background: linear-gradient(90deg, #1db954, #1ed760); height: 100%; border-radius: 20px; transition: width 0.3s ease;"></div>
</div>
</div>
</td>
</tr>
</table>
<!-- Responsive style for mobile devices -->
<style>
@media (max-width: 768px) {
#player tr, #player td {
display: block;
width: 100%;
}
#player-album-art {
max-height: 30vmin;
}
#player div, #player a {
font-size: 3vmin;
}
#player-time {
position: relative;
float: none;
text-align: center;
margin-top: 0.5em;
}
#player {
overflow: hidden;
}
}
/* Add the background blur effect */
#player {
position: relative;
overflow: hidden;
--background-image: url(''); /* Placeholder for dynamic background */
background-color: var(--main-color);
color: var(--text-color);
font-family: 'ubuntu', Arial, sans-serif;
font-size: 4vmin;
border-radius: var(--border-radius);
filter: opacity(0.95);
width: 100%;
height: auto;
}
#player::before {
content: "";
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-image: var(--background-image); /* Use CSS variable for dynamic background */
background-position: center;
background-size: cover;
filter: blur(30px); /* Apply blur only to the background */
z-index: -2; /* Place it behind the player content */
}
#player img {
z-index: 1; /* Ensure images are above the background */
}
</style>
<link href="https://fonts.cdnfonts.com/css/ubuntu" rel="stylesheet">
<script>
const serviceHost = "https://spotify.thanuj-usp.workers.dev";
const spotifyUser = "Pavan Thanuj Upadrasta";
let songData, progressInterval, previousSongId;
function updatePlayer() {
fetch(`${serviceHost}/get-now-playing`)
.then(response => response.json())
.then(data => {
if (data.hasOwnProperty("ERROR")) {
document.getElementById("player-status").innerHTML = `I am not listening to anything right now!`;
document.getElementById("player-status").style.textAlign = "left";
document.getElementById("pill-container").style.display = "none";
document.getElementById("player-progress-back").style.display = "none";
clearInterval(progressInterval);
return;
}
songData = data;
document.getElementById("player-status").innerHTML = data.is_playing ? `▶️ ${spotifyUser} is now listening to...` : `⏸️ ${spotifyUser} has paused.`;
// Update song title link
const songLink = document.getElementById("player-song");
songLink.href = data.item.external_urls.spotify;
songLink.textContent = data.item.name;
// Update artist and album pills
const artistLink = document.getElementById("player-artist-pill");
artistLink.href = data.item.artists[0].external_urls.spotify;
artistLink.textContent = `🎤 ${data.item.artists[0].name}`;
const albumLink = document.getElementById("player-album-pill");
albumLink.href = data.item.album.external_urls.spotify;
albumLink.textContent = `💽 ${data.item.album.name}`;
// Display the pills and progress bar
document.getElementById("pill-container").style.display = "flex";
document.getElementById("player-progress-back").style.display = "block";
// Update album art and background
const albumArt = data.item.album.images[1].url;
document.getElementById("player-album-art").src = albumArt;
document.getElementById("player").style.setProperty('--background-image', `url(${albumArt})`);
// Initial progress bar width
updateProgress();
clearInterval(progressInterval);
if (data.is_playing) {
progressInterval = setInterval(() => {
songData.progress_ms += 1000;
updateProgress();
}, 1000);
}
});
}
function updateProgress() {
const progressSeconds = Math.ceil(songData.progress_ms / 1000);
const totalSeconds = Math.ceil(songData.item.duration_ms / 1000);
const formatTime = val => val.toString().padStart(2, "0");
const currentTime = `${formatTime(Math.floor(progressSeconds / 60))}:${formatTime(progressSeconds % 60)}`;
const totalTime = `${formatTime(Math.floor(totalSeconds / 60))}:${formatTime(totalSeconds % 60)}`;
document.getElementById("player-time").textContent = `${currentTime} / ${totalTime}`;
document.getElementById("player-progress").style.width = `${(progressSeconds / totalSeconds) * 100}%`;
if (progressSeconds >= totalSeconds) {
clearInterval(progressInterval);
updatePlayer();
}
}
updatePlayer();
setInterval(updatePlayer, 10000);
</script>