-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
362 lines (320 loc) · 11 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
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Screensaver</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="text/javascript" src="config.js"></script>
</head>
<style type="text/css">
body, html {
background-color: black;
height: 100%;
margin: 0;
overflow: hidden;
}
#info {
z-index: 50;
position: absolute;
background: black;
color: white;
}
#one, #two {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
}
img {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
object-fit: cover;
animation-timing-function: linear;
}
#two.visible {
opacity: 1;
}
#two {
opacity: 0;
z-index: 5;
transition: opacity ease;
transition-duration: 2s;
}
div p {
font-size: 50px;
position: absolute;
color: white;
left: 6%;
right: 6%;
text-shadow: 0px 2px 3px rgba(0, 0, 0, 0.5), 0px 4px 13px rgba(0, 0, 0, 0.2), 0px 9px 23px rgba(0, 0, 0, 0.2);
bottom: 8%;
font-family: sans-serif;
margin: 0;
display: block;
}
body.hiddenTitles div p.title {
display: none;
}
@keyframes zoomOut {
from {
transform: scale(1.1);
}
to {
transform: scale(1);
}
}
@keyframes zoomIn {
from {
transform: scale(1);
}
to {
transform: scale(1.1);
}
}
@keyframes moveRight {
from {
transform: scale(1.1) translateX(3%);
}
to {
transform: scale(1.1) translateX(-3%);
}
}
@keyframes moveLeft {
from {
transform: scale(1.1) translateX(-3%);
}
to {
transform: scale(1.1) translateX(3%);
}
}
@keyframes moveUp {
from {
transform: scale(1.1) translateY(4%);
}
to {
transform: scale(1.1) translateY(-4%);
}
}
@keyframes moveDown {
from {
transform: scale(1.1) translateY(-4%);
}
to {
transform: scale(1.1) translateY(4%);
}
}
@keyframes goGray {
from {
filter: grayscale(0%);
}
to {
filter: grayscale(100%);
}
}
@keyframes goColor {
from {
filter: grayscale(100%);
}
to {
filter: grayscale(0%);
}
}
</style>
<body>
<p id="info"></p>
<div id="one">
<img src="background.png" alt="">
<p class="title"></p>
</div>
<div id="two">
<img src="background.png" alt="">
<p class="title"></p>
</div>
</body>
<script>
let plexTokenParameter;
let urlSections;
let sectionList = [];
let sectionCount;
let videoList = [];
let one = document.getElementById("one");
let two = document.getElementById("two");
let infoBox = document.getElementById("info");
function initialize() {
plexTokenParameter = "?X-Plex-Token=" + config.plexToken;
urlSections = config.plexAddress + "/library/sections" + plexTokenParameter;
two.style.transitionDuration = config.transitionDuration + "ms";
if (!config.showTitle) document.body.classList.add("hiddenTitles");
document.getElementsByClassName("title")[0].style.color = config.titleColor;
document.getElementsByClassName("title")[1].style.color = config.titleColor;
document.getElementsByClassName("title")[0].style.textAlign = config.titlePosition;
document.getElementsByClassName("title")[1].style.textAlign = config.titlePosition;
document.getElementsByClassName("title")[0].style.opacity = config.titleOpacity;
document.getElementsByClassName("title")[1].style.opacity = config.titleOpacity;
if (config.usePlex) {
getSections();
} else {
console.log("Plex Api disabled in config");
startSlideShow();
}
}
function getSections() {
fetch(urlSections).then(function (response) {
if (response.ok) {
return response.text();
} else {
let errorText = "Error " + response.status + " " + response.statusText + "\n";
switch (response.status) {
case 401:
errorText += "Check your Plex Token";
break;
}
errorText += "\nCould not load sections";
infoBox.innerText = errorText;
startSlideShow();
}
}).then(function (text) {
let parser = new DOMParser();
let xmlDoc = parser.parseFromString(text, "text/xml");
let sections = xmlDoc.getElementsByTagName("Directory");
console.log("Found " + sections.length + " sections");
sectionCount = sections.length;
for (let i = 0; i < sections.length; i++) {
let section = {};
section.title = sections[i].getAttribute("title");
section.key = sections[i].getAttribute("key");
section.type = sections[i].getAttribute("type");
sectionList.push(section);
}
for (let i = 0; i < sectionList.length; i++) {
getContentArtFromSection(sectionList[i])
}
}).catch(function (err) {
console.log(err);
if (err === "fetch failed") {
infoBox.innerText = "Error: " + err.toString() + "\nCheck your Plex ip address";
} else {
infoBox.innerText = "Unknown Error: " + err.toString() + "\n";
}
startSlideShow();
})
}
function getContentArtFromSection(section) {
let tagName;
if (config.librariesToExclude.includes(section.title)) {
console.log("Ignored section with key '" + section.key + "' of type '" + section.type + "' called '" + section.title + "' because you said so in config.js");
isLastOne();
return;
}
if (section.type === "movie") {
tagName = "Video";
} else if (section.type === "show") {
tagName = "Directory";
} else {
console.log("Ignored section with key '" + section.key + "' of type '" + section.type + "' called '" + section.title + "'");
//eg Podcasts, Music etc. - we dont want its art
return;
}
let sectionUrl = config.plexAddress + "/library/sections/" + section.key + "/all" + plexTokenParameter;
fetch(sectionUrl).then(function (response) {
if (response.ok) {
return response.text();
} else {
throw new Error('Could not load section "' + section.title + '" of type "' + section.type + '" with key: "' + section.key + '"');
}
}).then(function (text) {
let parser = new DOMParser();
let xmlDoc = parser.parseFromString(text, "text/xml");
let items = xmlDoc.getElementsByTagName(tagName);
console.log(items.length + " items found in section '" + section.title + "'");
for (let i = 0; i < items.length; i++) {
if (items[i].getAttribute("art") === null) {
console.log("No artwork provided for media '" + items[i].getAttribute("title") + "'");
continue;
}
let video = {};
video.title = items[i].getAttribute("title");
video.key = items[i].getAttribute("ratingKey");
video.art = config.plexAddress + items[i].getAttribute("art") + plexTokenParameter;
videoList.push(video);
}
if (isLastOne()) {
startSlideShow()
}
}).catch(function (err) {
console.log("Unexptected error: " + 'Could not load section "' + section.title + '" of type "' + section.type + '" with key: "' + section.key + '"');
console.log(err);
});
}
function isLastOne() {
sectionCount--;
if (sectionCount === 0) {
startSlideShow();
}
}
function startSlideShow() {
if (config.useExtraImages) {
readAdditionalImages()
} else {
console.log("Local extra images disabled in config");
}
if (config.useExtraLinks) {
readAdditionalLinks()
} else {
console.log("Extra image links disabled in config");
}
if (videoList.length > 0) {
putRandomImageUrl(two);
swapImageAndChangeSrc();
setInterval(function () {
swapImageAndChangeSrc();
}, config.imageInterval);
} else {
document.getElementById("info").innerText += "\nYou didn't provide any images or something went wrong";
console.log("You didn't provide any images or something went wrong");
}
}
function swapImageAndChangeSrc() {
two.classList.toggle("visible");
let twoActive = two.classList.contains("visible");
let newInactive = twoActive ? one : two;
let newActive = twoActive ? two : one;
let newAnimationName = "none";
if (config.animations.length > 0) {
newAnimationName = config.animations[Math.floor(Math.random() * config.animations.length)];
}
newActive.getElementsByTagName("img")[0].style.animationName = newAnimationName;
newActive.getElementsByTagName("img")[0].style.animationDuration = config.imageInterval + config.transitionDuration + "ms";
setTimeout(() => putRandomImageUrl(newInactive), config.imageInterval / 2);
}
function putRandomImageUrl(containerDiv) {
let item = videoList[Math.floor(Math.random() * videoList.length)];
containerDiv.getElementsByTagName("img")[0].src = item.art;
containerDiv.getElementsByTagName("img")[0].style.animation = "";
containerDiv.getElementsByTagName("p")[0].textContent = item.title;
}
function readAdditionalImages() {
console.log("Using " + config.extraImages.length + " additional local artworks");
for (let i = 0; i < config.extraImages.length; i++) {
let video = {};
video.title = config.extraImages[i][0];
video.art = "extraImages/" + config.extraImages[i][1];
videoList.push(video);
}
}
function readAdditionalLinks() {
console.log("Using " + config.extraLinks.length + " additional external links");
for (let i = 0; i < config.extraLinks.length; i++) {
let video = {};
video.title = config.extraLinks[i][0];
video.art = config.extraLinks[i][1];
videoList.push(video);
}
}
initialize();
</script>
</html>