-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathhazy.js
More file actions
784 lines (687 loc) · 23.9 KB
/
hazy.js
File metadata and controls
784 lines (687 loc) · 23.9 KB
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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
(function hazy() {
if (!Spicetify?.Platform || !Spicetify?.Platform?.History?.listen) {
setTimeout(hazy, 100);
return;
}
const defImage = "https://i.imgur.com/Wl2D0h0.png";
let startImage = localStorage.getItem("hazy:startupBg") || defImage;
const toggleInfo = [
{
id: "UseCustomBackground",
name: "Custom background",
defVal: false,
},
{
id: "UseCustomColor",
name: "Custom color",
defVal: false,
},
{
id: "HideNowPlayingSidebar",
name: "Hide now playing sidebar",
defVal: false,
},
];
const toggles = {
UseCustomBackground: false,
UseCustomColor: false,
HideNowPlayingSidebar: false
};
const sliders = [
{
id: "blur",
name: "Blur",
min: 0,
max: 50,
step: 1,
defVal: 15,
end: "px",
},
{ id: "cont", name: "Contrast", min: 0, max: 200, step: 2, defVal: 50 },
{ id: "satu", name: "Saturation", min: 0, max: 200, step: 2, defVal: 70 },
{
id: "bright",
name: "Brightness",
min: 0,
max: 200,
step: 2,
defVal: 120,
},
];
(function sidebar() {
if (localStorage.getItem("Hazy Sidebar Activated")) return;
// Sidebar settings
const parsedObject = JSON.parse(
localStorage.getItem("spicetify-exp-features")
);
// Variable if client needs to reload
let reload = false;
// Array of features
const features = [
"enableYLXSidebar",
"enableRightSidebar",
"enableRightSidebarTransitionAnimations",
"enableRightSidebarLyrics",
"enableRightSidebarExtractedColors",
"enablePanelSizeCoordination",
];
for (const feature of features) {
// Ignore if feature not present
if (!parsedObject?.[feature]) continue;
// Change value if disabled
if (!parsedObject?.[feature]?.value) {
parsedObject[feature].value = true;
reload = true;
}
}
localStorage.setItem(
"spicetify-exp-features",
JSON.stringify(parsedObject)
);
localStorage.setItem("Hazy Sidebar Activated", true);
if (reload) {
window.location.reload();
reload = false;
}
})();
function loadSliders() {
sliders.forEach((opt) => {
const val = localStorage.getItem(`${opt.id}Amount`) || opt.defVal;
document.documentElement.style.setProperty(
`--${opt.id}`,
`${val}${opt.end || "%"}`
);
});
}
function setAccentColor(color) {
document.querySelector(":root").style.setProperty("--spice-button", color);
document
.querySelector(":root")
.style.setProperty("--spice-button-active", color);
document.querySelector(":root").style.setProperty("--spice-accent", color);
}
async function fetchFadeTime() {
try {
const response = await Spicetify.Platform.PlayerAPI._prefs.get({
key: "audio.crossfade_v2",
});
// Default to 0.4s if crossfade is disabled
if (!response.entries["audio.crossfade_v2"].bool) {
document.documentElement.style.setProperty("--fade-time", "0.4s");
return;
}
const fadeTimeResponse = await Spicetify.Platform.PlayerAPI._prefs.get({
key: "audio.crossfade.time_v2",
});
const fadeTime =
fadeTimeResponse.entries["audio.crossfade.time_v2"].number;
// Use the CSS variable "--fade-time" for transition time
document.documentElement.style.setProperty(
"--fade-time",
`${fadeTime / 1000}s`
);
} catch (error) {
document.documentElement.style.setProperty("--fade-time", "0.4s");
}
}
function getCurrentBackground(replace) {
let url = Spicetify?.Player?.data?.item?.metadata?.image_url;
if (toggles.UseCustomBackground || !url || !URL.canParse(url)) return startImage;
if (replace)
url = url.replace("spotify:image:", "https://i.scdn.co/image/");
return url;
}
async function onSongChange() {
fetchFadeTime();
const album_uri = Spicetify?.Player?.data?.item?.metadata?.album_uri;
if (album_uri !== undefined && !album_uri.includes("spotify:show")) {
// Album
} else if (Spicetify?.Player?.data?.item?.uri?.includes("spotify:episode")) {
// Podcast
} else if (Spicetify?.Player?.data?.item?.isLocal) {
// Local file
} else if (Spicetify?.Player?.data?.item?.provider === "ad") {
// Ad
return;
} else {
// When clicking a song from the homepage, songChange is fired with half empty metadata
setTimeout(onSongChange, 200);
}
updateLyricsPageProperties();
// Custom code added by lily
if (!toggles.UseCustomColor) {
// Get the accent color from the background image
const img = new Image();
// Allows CORS-enabled images
img.crossOrigin = "Anonymous";
img.onload = function () {
const canvas = document.createElement("canvas");
const ctx = canvas.getContext("2d");
canvas.width = img.width;
canvas.height = img.height;
ctx.drawImage(img, 0, 0);
const imageData = ctx.getImageData(
0,
0,
canvas.width,
canvas.height
).data;
const rgbList = [];
// Note that we are looping every 4 (red, green, blue and alpha)
for (let i = 0; i < imageData.length; i += 4)
rgbList.push({
r: imageData[i],
g: imageData[i + 1],
b: imageData[i + 2],
});
// Attempt with filters
let hexColor = findColor(rgbList);
// Retry without filters if no color is found
if (!hexColor) hexColor = findColor(rgbList, true);
setAccentColor(hexColor);
};
img.src = getCurrentBackground(true);
} else {
setAccentColor(localStorage.getItem("CustomColor") || "#ffc0ea");
}
// Update background
document.documentElement.style.setProperty(
"--image_url",
`url("${getCurrentBackground(false)}")`
);
}
// Gets the most prominent color in a list of RGB values
function findColor(rgbList, skipFilters = false) {
const colorCount = {};
let maxColor = "";
let maxCount = 0;
for (let i = 0; i < rgbList.length; i++) {
if (
!skipFilters &&
(isTooDark(rgbList[i]) || isTooCloseToWhite(rgbList[i]))
) {
continue;
}
const color = `${rgbList[i].r},${rgbList[i].g},${rgbList[i].b}`;
colorCount[color] = (colorCount[color] || 0) + 1;
if (colorCount[color] > maxCount) {
maxColor = color;
maxCount = colorCount[color];
}
}
return maxColor ? rgbToHex(...maxColor.split(",").map(Number)) : null;
}
// Converts RGB to Hex
function rgbToHex(r, g, b) {
return "#" + [r, g, b].map((x) => x.toString(16).padStart(2, "0")).join("");
}
// Checks if a color is too dark
function isTooDark(rgb) {
const brightness = 0.299 * rgb.r + 0.587 * rgb.g + 0.114 * rgb.b;
// Adjust this value to control the "darkness" threshold
const threshold = 100;
return brightness < threshold;
}
// Checks if a color is too close to white
function isTooCloseToWhite(rgb) {
const threshold = 200;
return rgb.r > threshold && rgb.g > threshold && rgb.b > threshold;
}
loadSliders();
loadToggles();
Spicetify.Player.addEventListener("songchange", onSongChange);
if (window.navigator.userAgent.indexOf("Win") !== -1)
document.body.classList.add("windows");
galaxyFade();
function scrollToTop() {
const element = document.querySelector(".main-entityHeader-container");
element.scrollIntoView({ behavior: "smooth", block: "start" });
}
document.addEventListener("click", (event) => {
if (event.target.closest(".main-entityHeader-topbarTitle")) scrollToTop();
});
// Window Zoom Variable
function updateZoomVariable() {
let prevOuterWidth = window.outerWidth;
let prevInnerWidth = window.innerWidth;
let prevRatio = window.devicePixelRatio;
function calculateAndApplyZoom() {
const newOuterWidth = window.outerWidth;
const newInnerWidth = window.innerWidth;
const newRatio = window.devicePixelRatio;
if (
prevOuterWidth <= 160 ||
prevRatio !== newRatio ||
prevOuterWidth !== newOuterWidth ||
prevInnerWidth !== newInnerWidth
) {
const zoomFactor = newOuterWidth / newInnerWidth || 1;
document.documentElement.style.setProperty("--zoom", zoomFactor);
console.debug(
`[Hazy] Zoom Updated: ${newOuterWidth} / ${newInnerWidth} = ${zoomFactor}`
);
// Update previous values
prevOuterWidth = newOuterWidth;
prevInnerWidth = newInnerWidth;
prevRatio = newRatio;
}
}
calculateAndApplyZoom();
window.addEventListener("resize", calculateAndApplyZoom);
}
updateZoomVariable();
function waitForElement(elements, func, timeout = 100) {
const queries = elements.map((element) => document.querySelector(element));
if (queries.every((a) => a)) {
func(queries);
} else if (timeout > 0) {
setTimeout(waitForElement, 300, elements, func, timeout - 1);
}
}
waitForElement(
[".Root__globalNav"],
(element) => {
const isCenteredGlobalNav = Spicetify.Platform.version >= "1.2.46.462";
let addedClass = "control-nav";
if (element?.[0]?.classList.contains("Root__globalNav"))
addedClass = isCenteredGlobalNav ? "global-nav-centered" : "global-nav";
document.body.classList.add(addedClass);
},
10000
);
Spicetify.Platform.History.listen(updateLyricsPageProperties);
waitForElement([".Root__lyrics-cinema"], ([lyricsCinema]) => {
const lyricsCinemaObserver = new MutationObserver(
updateLyricsPageProperties
);
const lyricsCinemaObserverConfig = {
attributes: true,
attributeFilter: ["class"],
};
lyricsCinemaObserver.observe(lyricsCinema, lyricsCinemaObserverConfig);
});
waitForElement([".main-view-container"], ([mainViewContainer]) => {
const mainViewContainerResizeObserver = new ResizeObserver(
updateLyricsPageProperties
);
mainViewContainerResizeObserver.observe(mainViewContainer);
});
// Fixes container shifting & active line clipping
// Taken from Bloom | https://github.com/nimsandu/spicetify-bloom
function updateLyricsPageProperties() {
function setLyricsPageProperties() {
function calculateLyricsMaxWidth(lyricsContentWrapper) {
const lyricsContentContainer = lyricsContentWrapper.parentElement;
const marginLeft = Number.parseInt(
window.getComputedStyle(lyricsContentWrapper).marginLeft,
10
);
const totalOffset = lyricsContentWrapper.offsetLeft + marginLeft;
return Math.round(
0.95 * (lyricsContentContainer.clientWidth - totalOffset)
);
}
waitForElement(
[".lyrics-lyrics-contentWrapper"],
([lyricsContentWrapper]) => {
lyricsContentWrapper.style.maxWidth = "";
lyricsContentWrapper.style.width = "";
// 0, 1 - blank lines
const lyric = document.querySelector(
".lyrics-lyricsContent-lyric"
)[2];
document.documentElement.style.setProperty(
"--lyrics-text-direction",
/[\u0591-\u07FF]/.test(lyric.innerText) ? "right" : "left"
);
document.documentElement.style.setProperty(
"--lyrics-active-max-width",
`${calculateLyricsMaxWidth(lyricsContentWrapper)}px`
);
// Lock lyrics wrapper width
const lyricsWrapperWidth =
lyricsContentWrapper.getBoundingClientRect().width;
lyricsContentWrapper.style.maxWidth = `${lyricsWrapperWidth}px`;
lyricsContentWrapper.style.width = `${lyricsWrapperWidth}px`;
}
);
}
function lyricsCallback(mutationsList, lyricsObserver) {
for (const mutation of mutationsList)
for (addedNode of mutation.addedNodes)
if (addedNode.classList?.contains("lyrics-lyricsContent-provider"))
setLyricsPageProperties();
lyricsObserver.disconnect;
}
waitForElement(
[".lyrics-lyricsContent-provider"],
([lyricsContentProvider]) => {
setLyricsPageProperties();
const lyricsObserver = new MutationObserver(lyricsCallback);
lyricsObserver.observe(lyricsContentProvider.parentElement, {
childList: true,
});
}
);
}
function setFadeDirection(scrollNode) {
let fadeDirection = "full";
if (scrollNode.scrollTop === 0) {
fadeDirection = "bottom";
} else if (
scrollNode.scrollHeight -
scrollNode.scrollTop -
scrollNode.clientHeight ===
0
) {
fadeDirection = "top";
}
scrollNode.setAttribute("fade", fadeDirection);
}
// Add fade and dimness effects to mainview and the artist image on scroll
// Taken from Galaxy | https://github.com/harbassan/spicetify-galaxy/
function galaxyFade() {
const setupFade = (selector, onScrollCallback) => {
waitForElement([selector], ([scrollNode]) => {
let ticking = false;
scrollNode.addEventListener("scroll", () => {
if (!ticking) {
window.requestAnimationFrame(() => {
onScrollCallback(scrollNode);
ticking = false;
});
ticking = true;
}
});
// Initial trigger
onScrollCallback(scrollNode);
});
};
// Apply artist fade function
const applyArtistFade = (scrollNode) => {
const scrollValue = scrollNode.scrollTop;
const fadeValue = Math.max(0, (-0.3 * scrollValue + 100) / 100);
document.documentElement.style.setProperty("--artist-fade", fadeValue);
};
// Main view - apply artist fade + fade direction
setupFade(
".Root__main-view [data-overlayscrollbars-viewport]",
(scrollNode) => {
applyArtistFade(scrollNode);
setFadeDirection(scrollNode);
}
);
// Nav bar - fade direction only
setupFade(
".Root__nav-bar [data-overlayscrollbars-viewport]",
(scrollNode) => {
scrollNode.setAttribute("fade", "bottom");
setFadeDirection(scrollNode);
}
);
// Right sidebar - fade direction only
setupFade(
".Root__right-sidebar [data-overlayscrollbars-viewport]",
(scrollNode) => {
scrollNode.setAttribute("fade", "bottom");
setFadeDirection(scrollNode);
}
);
}
function loadToggles() {
toggles.UseCustomBackground = JSON.parse(
localStorage.getItem("UseCustomBackground")
);
toggles.UseCustomColor = JSON.parse(localStorage.getItem("UseCustomColor"));
toggles.HideNowPlayingSidebar = JSON.parse(localStorage.getItem("HideNowPlayingSidebar"));
if (toggles.HideNowPlayingSidebar) {
document.body.classList.add("__hazy_hidenowplayingsidebar");
}
else {
document.body.classList.remove("__hazy_hidenowplayingsidebar");
}
onSongChange();
}
// Input for custom background images (disabled until properly implemented)
/* const bannerInput = document.createElement("input");
bannerInput.type = "file";
bannerInput.className = "banner-input";
bannerInput.accept = [
"image/jpeg",
"image/apng",
"image/avif",
"image/gif",
"image/png",
"image/svg+xml",
"image/webp",
].join(",");
// When user selects a custom background image
bannerInput.onchange = () => {
if (!bannerInput.files.length) return;
const file = bannerInput.files[0];
const reader = new FileReader();
reader.onload = (event) => {
const result = event.target.result;
const [, , uid] = Spicetify.Platform.History.location.pathname.split("/");
if (!uid) {
try {
localStorage.setItem("hazy:startupBg", result);
} catch {
Spicetify.showNotification("File too large");
return;
}
document.querySelector("#home-select img").src = result;
}
};
reader.readAsDataURL(file);
}; */
// Create edit home topbar button
const homeEdit = new Spicetify.Topbar.Button("Hazy Settings", "edit", () => {
const content = document.createElement("div");
content.innerHTML = `
<div class="main-playlistEditDetailsModal-albumCover" id="home-select">
<div class="main-entityHeader-image" draggable="false">
<img aria-hidden="false" draggable="false" loading="eager" class="main-image-image main-entityHeader-image main-entityHeader-shadow">
</div>
<div class="main-playlistEditDetailsModal-imageChangeButton">
<div class="main-editImage-buttonContainer"></div>
</div>
</div>`;
function createToggle(opt) {
let { id, name, defVal } = opt;
const toggleRow = document.createElement("div");
toggleRow.classList.add("hazyOptionRow");
toggleRow.innerHTML = `
<span class="hazyOptionDesc">${name}:</span>
<button class="hazyOptionToggle">
<span class="toggleWrapper">
<span class="toggle"></span>
</span>
</button>`;
toggleRow.setAttribute("name", id);
toggleRow
.querySelector("button")
.addEventListener("click", () =>
toggleRow.querySelector(".toggle").classList.toggle("enabled")
);
const isEnabled = JSON.parse(localStorage.getItem(id)) ?? defVal;
toggleRow.querySelector(".toggle").classList.toggle("enabled", isEnabled);
content.append(toggleRow);
}
function createSlider(opt) {
let { id, name, min, max, step, defVal, end } = opt;
const val = localStorage.getItem(`${id}Amount`) || defVal;
const slider = document.createElement("div");
slider.classList.add("hazyOptionRow");
slider.innerHTML = `
<div class="slider-container">
<label for="${id}-input">${name}:</label>
<input class="slider" id="${id}-input" type="range" min="${min}" max="${max}" step="${step}" value="${val}">
<div class="slider-value">
<p id="${id}-value" contenteditable="true" >${val}${end || "%"}</p>
</div>
</div>`;
slider.querySelector(`#${id}-value`).addEventListener("input", () => {
let content = slider.querySelector(`#${id}-value`).textContent.trim();
const number = Number.parseInt(content);
if (content.length > 3) {
// Truncate the content to 3 characters
content = slider.querySelector(`#${id}-value`).textContent =
content.slice(0, 3);
}
slider.querySelector(`#${id}-input`).value = number;
});
slider.querySelector(`#${id}-input`).addEventListener("input", () => {
slider.querySelector(`#${id}-value`).textContent = `${
slider.querySelector(`#${id}-input`).value
}${opt.end || "%"}`;
});
content.append(slider);
}
const srcInput = document.createElement("input");
srcInput.type = "text";
srcInput.classList.add(
"main-playlistEditDetailsModal-textElement",
"main-playlistEditDetailsModal-titleInput"
);
srcInput.id = "src-input";
srcInput.placeholder =
"Background image URL";
if (!startImage.startsWith("data:image")) {
srcInput.value = startImage;
}
content.append(srcInput);
toggleInfo.forEach(createToggle);
// Additional settings (added by lily)
const colorRow = document.createElement("div");
colorRow.classList.add("hazyOptionRow");
// Color label
const colorLabel = document.createElement("label");
colorLabel.id = "color-label";
colorLabel.htmlFor = "color";
colorLabel.textContent = "Color:";
colorLabel.style.textAlign = "right";
colorLabel.style.marginRight = "10px";
colorLabel.style.fontSize = "0.875rem";
colorRow.append(colorLabel);
// Color picker
const colorInput = document.createElement("input");
colorInput.type = "color";
colorInput.id = "color-input";
colorInput.value = localStorage.getItem("CustomColor") || "#30bf63";
colorInput.style.border = "none";
colorRow.append(colorInput);
content.append(colorRow);
sliders.forEach(createSlider);
loadSliders();
img = content.querySelector("img");
img.src = localStorage.getItem("hazy:startupBg") || defImage;
srcInput.addEventListener("input", () => {
img.src = srcInput.value
})
/* const editButton = content.querySelector(
".main-editImageButton-image.main-editImageButton-overlay"
);
editButton.onclick = () => {
bannerInput.click();
};
const removeButton = content.querySelector(
".main-playlistEditDetailsModal-imageDropDownButton"
);
removeButton.onclick = () => {
content.querySelector("img").src = defImage;
}; */
const buttonsRow = document.createElement("div");
buttonsRow.style.display = "flex";
buttonsRow.style.paddingTop = "15px";
buttonsRow.style.alignItems = "flex-end";
const resetButton = document.createElement("button");
resetButton.id = "value-reset";
resetButton.innerHTML = "Reset";
const saveButton = document.createElement("button");
saveButton.id = "home-save";
saveButton.innerHTML = "Apply";
saveButton.onclick = async () => {
// Check if image background is valid
let invalidImage = false;
try {
await fetch(srcInput.value, {
"mode": "no-cors"
});
}
catch (error) {
invalidImage = true;
}
if (!srcInput.value || !URL.canParse(srcInput.value) || invalidImage) {
saveButton.innerHTML = "Invalid image";
saveButton.classList.add("applyfailed");
saveButton.disabled = true;
setTimeout(() => {
saveButton.innerHTML = "Apply";
saveButton.classList.remove("applyfailed");
saveButton.disabled = false;
}, 3000);
return;
}
// Change the button text to "Applied!", add "applied" class, and disable the button
saveButton.innerHTML = "Applied!";
saveButton.classList.add("applied");
saveButton.disabled = true;
// Revert back to "Apply", remove "applied" class, and enable the button after a second
setTimeout(() => {
saveButton.innerHTML = "Apply";
saveButton.classList.remove("applied");
saveButton.disabled = false;
}, 1000);
// Update changed bg image
startImage = srcInput.value || content.querySelector("img").src;
localStorage.setItem("hazy:startupBg", startImage);
// Save the selected custom color (added by lily)
localStorage.setItem(
"CustomColor",
document.getElementById("color-input").value
);
toggleInfo.forEach((opt) =>
localStorage.setItem(
opt.id,
document
.querySelector(`.hazyOptionRow[name=${opt.id}] .toggle`)
.classList.contains("enabled")
)
);
sliders.forEach((opt) =>
localStorage.setItem(
opt.id + "Amount",
document.querySelector(`.hazyOptionRow #${opt.id}-input`).value
)
);
loadSliders();
loadToggles();
};
resetButton.onclick = () => {
sliders.forEach((opt) => {
document.querySelector(`.hazyOptionRow #${opt.id}-input`).value =
opt.defVal;
document.querySelector(
`.hazyOptionRow #${opt.id}-value`
).textContent = `${opt.defVal}${opt.end || "%"}`;
});
toggleInfo.forEach((opt) => {
document
.querySelector(`.hazyOptionRow[name=${opt.id}] .toggle`)
.classList.toggle("enabled", opt.defVal);
});
document.getElementById("src-input").value = defImage;
img.src = defImage;
document.getElementById("color-input").value = "#30bf63";
};
const issueButton = document.createElement("a");
issueButton.classList.add("issue-button");
issueButton.innerHTML = "Report Issue";
issueButton.href = "https://github.com/Astromations/Hazy/issues";
buttonsRow.append(issueButton, resetButton, saveButton);
content.append(buttonsRow);
Spicetify.PopupModal.display({ title: "Hazy Settings", content });
});
homeEdit.element.classList.toggle("hidden", false);
})();