-
Notifications
You must be signed in to change notification settings - Fork 0
/
colorz-theme.html
188 lines (170 loc) · 7.31 KB
/
colorz-theme.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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Now Playing - Colorz</title>
<link
href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap"
rel="stylesheet"
/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/color-thief/2.3.2/color-thief.umd.js"></script>
<style>
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
font-family: "Roboto", sans-serif;
background-color: transparent; /* Transparent pour OBS */
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
.now-playing-container {
width: 400px;
height: 120px;
display: flex;
align-items: center;
background: #f7931e; /* Couleur par défaut */
border-radius: 0px; /* Pas de coins arrondis */
padding: 0;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3); /* Ombre subtile */
position: relative;
transition: background-color 0.5s ease, color 0.5s ease; /* Transition pour un effet fluide */
}
.music-cover {
width: 100px;
height: 120px;
margin: 0; /* Pas de marge */
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3); /* Ombre pour l'image */
flex-shrink: 0;
object-fit: cover; /* L'image remplit bien le conteneur */
}
.music-body {
display: flex;
flex-direction: column;
justify-content: center;
flex: 1;
padding: 10px;
overflow: hidden;
}
.music-name,
.music-artist {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
transition: color 0.5s ease; /* Transition pour un effet fluide */
}
.music-name {
font-size: 1.2em;
font-weight: 700;
}
.music-artist {
font-size: 1em;
font-weight: 400;
}
/* Couleurs par défaut */
.text-light {
color: #fff; /* Texte blanc */
}
.text-dark {
color: #000; /* Texte noir */
}
</style>
</head>
<body>
<div class="now-playing-container" id="now-playing-container">
<img
id="cover"
class="music-cover"
crossOrigin="anonymous"
/>
<div class="music-body">
<div class="music-name text-light" id="title"></div>
<div class="music-artist text-light" id="artist"></div>
</div>
</div>
<script>
const colorThief = new ColorThief();
const coverElement = document.getElementById("cover");
const containerElement = document.getElementById("now-playing-container");
const titleElement = document.getElementById("title");
const artistElement = document.getElementById("artist");
let currentTitle = "";
let currentArtist = "";
let currentCoverUrl = "";
function getLuminance(color) {
// Calcule la luminosité relative de la couleur
const [r, g, b] = color.map((v) => v / 255);
const luminance = 0.2126 * r + 0.7152 * g + 0.0722 * b;
return luminance;
}
function setDynamicBackground() {
if (coverElement.complete) {
const dominantColor = colorThief.getColor(coverElement);
containerElement.style.backgroundColor = `rgb(${dominantColor.join(",")})`;
// Ajuste la couleur du texte en fonction de la luminosité
const luminance = getLuminance(dominantColor);
if (luminance > 0.5) {
// Couleur de fond claire, texte foncé
titleElement.classList.remove("text-light");
artistElement.classList.remove("text-light");
titleElement.classList.add("text-dark");
artistElement.classList.add("text-dark");
} else {
// Couleur de fond foncée, texte clair
titleElement.classList.remove("text-dark");
artistElement.classList.remove("text-dark");
titleElement.classList.add("text-light");
artistElement.classList.add("text-light");
}
} else {
coverElement.addEventListener("load", () => {
const dominantColor = colorThief.getColor(coverElement);
containerElement.style.backgroundColor = `rgb(${dominantColor.join(",")})`;
const luminance = getLuminance(dominantColor);
if (luminance > 0.5) {
titleElement.classList.remove("text-light");
artistElement.classList.remove("text-light");
titleElement.classList.add("text-dark");
artistElement.classList.add("text-dark");
} else {
titleElement.classList.remove("text-dark");
artistElement.classList.remove("text-dark");
titleElement.classList.add("text-light");
artistElement.classList.add("text-light");
}
});
}
}
function refreshContent() {
fetch("/now-playing-data")
.then((response) => response.json())
.then((data) => {
if (
data.title &&
data.artist &&
(data.title !== currentTitle ||
data.artist !== currentArtist ||
data.coverUrl !== currentCoverUrl)
) {
titleElement.textContent = data.title;
artistElement.textContent = data.artist;
coverElement.src = data.coverUrl || coverElement.src;
currentTitle = data.title;
currentArtist = data.artist;
currentCoverUrl = data.coverUrl;
// Met à jour la couleur dynamique
setDynamicBackground();
}
})
.catch((error) => console.error("Error fetching data:", error));
}
refreshContent();
setInterval(refreshContent, 5000);
</script>
</body>
</html>