forked from SuperBlueEyeBall/Old-GmingRealm-Repo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettingsloader.js
97 lines (82 loc) · 3.47 KB
/
settingsloader.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
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
(function () {
const savedSettings = JSON.parse(localStorage.getItem('latestSettings')) || {};
const defaultSettings = {
backgroundColor: '',
fontColor: '',
headerColor: '',
gameblockFontColor: '',
gradient: '',
backgroundURL: '',
backgroundAttachment: 'fixed',
imageSize: 100,
fitToViewport: false,
rotate: 0,
transparency: 100
};
const settings = Object.assign({}, defaultSettings, savedSettings);
// Log all settings from localStorage
console.log("Settings loaded from localStorage (settingsloader.js):", settings);
// Find the existing #background container
const backgroundDiv = document.getElementById('background');
if (backgroundDiv) {
backgroundDiv.style.position = 'fixed';
backgroundDiv.style.top = '0';
backgroundDiv.style.left = '0';
backgroundDiv.style.width = '100vw';
backgroundDiv.style.height = '100vh';
backgroundDiv.style.zIndex = '-1'; // Ensure it's behind other content
backgroundDiv.style.backgroundSize = 'cover';
backgroundDiv.style.backgroundPosition = 'center';
backgroundDiv.style.transition = 'all 0.3s ease';
// backgroundDiv.style.opacity = settings.transparency / 100; // Apply transparency
backgroundDiv.style.transform = `rotate(${settings.rotate}deg)`; // Apply rotation
} else {
console.error('No #background div found');
}
console.log("Styles before applying settings (settingsloader.js):", {
BackgroundPosition: backgroundDiv.style.position,
backgroundAttachment: backgroundDiv.style.backgroundAttachment,
backgroundSize: backgroundDiv.style.backgroundSize
});
const inlineStyles = `
body {
background-color: ${settings.backgroundColor || 'inherit'};
color: ${settings.fontColor || 'inherit'};
}
header {
background-color: ${settings.headerColor || 'inherit'};
}
.game-button a, .title {
color: ${settings.gameblockFontColor || 'inherit'};
}
`;
const styleTag = document.createElement('style');
styleTag.innerHTML = inlineStyles;
document.head.appendChild(styleTag);
// Apply background image or gradient to the existing #background div
if (settings.backgroundURL) {
backgroundDiv.style.backgroundImage = `url(${settings.backgroundURL})`;
} else if (settings.gradient) {
backgroundDiv.style.backgroundImage = `linear-gradient(${settings.gradient})`;
} else {
backgroundDiv.style.backgroundColor = settings.backgroundColor || 'inherit'; // Apply background color if no image or gradient
}
// Apply background attachment (scroll or fixed)
backgroundDiv.style.backgroundAttachment = settings.backgroundAttachment; // Can be 'scroll' or 'fixed'
backgroundDiv.style.backgroundSize = settings.fitToViewport ? '100% auto' : `${settings.imageSize}%`;
// Apply font color to all text inside the header
const headerElements = document.querySelectorAll('header, header *'); // Select header and all its child elements
headerElements.forEach(el => {
el.style.color = settings.fontColor || 'inherit';
});
// Apply gameblock font color to all elements with class "title"
const titleStuff = document.querySelectorAll('.title');
titleStuff.forEach(el => {
el.style.color = settings.gameblockFontColor || 'inherit';
});
console.log("Styles after applying settings (settingsloader.js):", {
BackgroundPosition: backgroundDiv.style.position,
backgroundAttachment: backgroundDiv.style.backgroundAttachment,
backgroundSize: backgroundDiv.style.backgroundSize
});
})();