-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
34 lines (31 loc) · 1.57 KB
/
background.js
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
document.addEventListener('DOMContentLoaded', function() {
applyStoredBackground(); // Apply stored background on page load
});
// function applyStoredBackground() {
// const storedIndex = localStorage.getItem('selectedBackgroundIndex');
// if (storedIndex && backgroundImages[storedIndex]) {
// document.body.style.backgroundImage = `url('img/background/${backgroundImages[storedIndex]}')`;
// document.getElementById('dim-overlay').style.display = 'block';
// }
// }
// Apply stored background on load
function applyStoredBackground() {
const storedIndex = localStorage.getItem('selectedBackgroundIndex');
if (storedIndex) {
if (storedIndex.startsWith('url:')) {
// Custom URL case
const customUrl = storedIndex.replace('url:', '');
document.body.style.backgroundImage = `url('${customUrl}')`;
document.body.style.backgroundColor = ''; // Clear solid color
} else if (storedIndex.startsWith('#')) {
// HEX color case
document.body.style.backgroundColor = storedIndex;
document.body.style.backgroundImage = ''; // Clear image
} else if (backgroundImages[storedIndex]) {
// Image index case
document.body.style.backgroundImage = `url('img/background/${backgroundImages[storedIndex]}')`;
document.body.style.backgroundColor = ''; // Clear solid color
}
document.getElementById('dim-overlay').style.display = 'block';
}
}