mirror of
https://github.com/nuttylmao/nutty.gg.git
synced 2026-09-19 04:00:59 -04:00
Settings page now persists on reloads + added a "Load Defaults" button
This commit is contained in:
@@ -18,6 +18,7 @@
|
|||||||
<span id="urlLabel">Click to copy URL</span>
|
<span id="urlLabel">Click to copy URL</span>
|
||||||
<input id="widgetUrlInput" type="text" readonly onclick="CopyURLToClipboard()">
|
<input id="widgetUrlInput" type="text" readonly onclick="CopyURLToClipboard()">
|
||||||
</div>
|
</div>
|
||||||
|
<button id="loadDefaultsButton" onclick="OpenLoadDefaultsPopup()">Load Default Settings</button>
|
||||||
<button id="loadSettingsButton" onclick="OpenLoadSettingsPopup()">Load Settings</button>
|
<button id="loadSettingsButton" onclick="OpenLoadSettingsPopup()">Load Settings</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -48,6 +49,17 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div id="loadDefaultsWrapper">
|
||||||
|
<div id="loadDefaultsContainer">
|
||||||
|
<h2>Load Defaults</h2>
|
||||||
|
<label style="font-size: 0.8em;">Are you sure?</label>
|
||||||
|
<div style="display: flex; gap: 20px">
|
||||||
|
<button id="cancelDefaultsButton" onclick="CloseDefaultsPopup()">No</button>
|
||||||
|
<button style="background-color: var(--accent-color);" onclick="LoadDefaultSettings()">Yes</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -12,10 +12,14 @@ const urlLabel = document.getElementById('urlLabel');
|
|||||||
const settingsPanel = document.getElementById('settingsPanel');
|
const settingsPanel = document.getElementById('settingsPanel');
|
||||||
const widgetPreview = document.getElementById('widgetPreview');
|
const widgetPreview = document.getElementById('widgetPreview');
|
||||||
const loadURLBox = document.getElementById('loadUrlBox');
|
const loadURLBox = document.getElementById('loadUrlBox');
|
||||||
const cancelSettingsButton = document.getElementById('cancelSettingsButton');
|
const loadDefaultsBox = document.getElementById('loadDefaultsWrapper');
|
||||||
const loadSettingsBox = document.getElementById('loadSettingsWrapper');
|
const loadSettingsBox = document.getElementById('loadSettingsWrapper');
|
||||||
const unmuteLabel = document.getElementById('unmute-label');
|
const unmuteLabel = document.getElementById('unmute-label');
|
||||||
|
|
||||||
|
// Global variables
|
||||||
|
let settingsMap = new Map();
|
||||||
|
|
||||||
|
// Set visibility of the unmute indicator
|
||||||
if (showUnmuteIndicator)
|
if (showUnmuteIndicator)
|
||||||
unmuteLabel.style.display = 'inline';
|
unmuteLabel.style.display = 'inline';
|
||||||
|
|
||||||
@@ -25,9 +29,13 @@ if (showUnmuteIndicator)
|
|||||||
// LOAD FROM SETTINGS.JSON //
|
// LOAD FROM SETTINGS.JSON //
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
|
|
||||||
fetch(settingsJson)
|
function LoadJSON(settingsJson) {
|
||||||
|
fetch(settingsJson)
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
|
// Clear the settings panel
|
||||||
|
settingsPanel.innerHTML = '';
|
||||||
|
|
||||||
const groupedSettings = {};
|
const groupedSettings = {};
|
||||||
|
|
||||||
// Group settings by their 'group' property
|
// Group settings by their 'group' property
|
||||||
@@ -75,7 +83,8 @@ fetch(settingsJson)
|
|||||||
inputElement = document.createElement('input');
|
inputElement = document.createElement('input');
|
||||||
inputElement.type = 'text';
|
inputElement.type = 'text';
|
||||||
inputElement.id = setting.id; //Added setting ID
|
inputElement.id = setting.id; //Added setting ID
|
||||||
inputElement.value = setting.defaultValue;
|
inputElement.value = settingsMap.has(setting.id) ? settingsMap.get(setting.id) : setting.defaultValue;
|
||||||
|
inputElement.autocomplete = 'new-password';
|
||||||
break;
|
break;
|
||||||
case 'checkbox':
|
case 'checkbox':
|
||||||
const labelDiv = document.createElement('label');
|
const labelDiv = document.createElement('label');
|
||||||
@@ -83,7 +92,7 @@ fetch(settingsJson)
|
|||||||
checkBoxElement = document.createElement('input');
|
checkBoxElement = document.createElement('input');
|
||||||
checkBoxElement.type = 'checkbox';
|
checkBoxElement.type = 'checkbox';
|
||||||
checkBoxElement.id = setting.id;
|
checkBoxElement.id = setting.id;
|
||||||
checkBoxElement.checked = setting.defaultValue;
|
checkBoxElement.checked = settingsMap.has(setting.id) ? settingsMap.get(setting.id) : setting.defaultValue;
|
||||||
labelDiv.appendChild(checkBoxElement);
|
labelDiv.appendChild(checkBoxElement);
|
||||||
|
|
||||||
const slider = document.createElement('span');
|
const slider = document.createElement('span');
|
||||||
@@ -110,19 +119,19 @@ fetch(settingsJson)
|
|||||||
}
|
}
|
||||||
inputElement.appendChild(optionElement);
|
inputElement.appendChild(optionElement);
|
||||||
});
|
});
|
||||||
inputElement.value = setting.defaultValue;
|
inputElement.value = settingsMap.has(setting.id) ? settingsMap.get(setting.id) : setting.defaultValue;
|
||||||
break;
|
break;
|
||||||
case 'color':
|
case 'color':
|
||||||
inputElement = document.createElement('input');
|
inputElement = document.createElement('input');
|
||||||
inputElement.type = 'color';
|
inputElement.type = 'color';
|
||||||
inputElement.id = setting.id; //Added setting ID
|
inputElement.id = setting.id; //Added setting ID
|
||||||
inputElement.value = setting.defaultValue;
|
inputElement.value = settingsMap.has(setting.id) ? settingsMap.get(setting.id) : setting.defaultValue;
|
||||||
break;
|
break;
|
||||||
case 'number':
|
case 'number':
|
||||||
inputElement = document.createElement('input');
|
inputElement = document.createElement('input');
|
||||||
inputElement.type = 'number';
|
inputElement.type = 'number';
|
||||||
inputElement.id = setting.id; //Added setting ID
|
inputElement.id = setting.id; //Added setting ID
|
||||||
inputElement.value = setting.defaultValue;
|
inputElement.value = settingsMap.has(setting.id) ? settingsMap.get(setting.id) : setting.defaultValue;
|
||||||
inputElement.min = setting.min;
|
inputElement.min = setting.min;
|
||||||
inputElement.max = setting.max;
|
inputElement.max = setting.max;
|
||||||
inputElement.step = setting.step;
|
inputElement.step = setting.step;
|
||||||
@@ -132,7 +141,7 @@ fetch(settingsJson)
|
|||||||
inputElement.type = 'text';
|
inputElement.type = 'text';
|
||||||
inputElement.placeholder = 'Type to search...';
|
inputElement.placeholder = 'Type to search...';
|
||||||
inputElement.id = setting.id; //Added setting ID
|
inputElement.id = setting.id; //Added setting ID
|
||||||
inputElement.value = setting.defaultValue;
|
inputElement.value = settingsMap.has(setting.id) ? settingsMap.get(setting.id) : setting.defaultValue;
|
||||||
inputElement.setAttribute('list', 'streamer-bot-actions');
|
inputElement.setAttribute('list', 'streamer-bot-actions');
|
||||||
inputElement.autocomplete = 'off';
|
inputElement.autocomplete = 'off';
|
||||||
break;
|
break;
|
||||||
@@ -162,10 +171,22 @@ fetch(settingsJson)
|
|||||||
inputElement = document.createElement('input');
|
inputElement = document.createElement('input');
|
||||||
inputElement.type = 'text';
|
inputElement.type = 'text';
|
||||||
inputElement.id = setting.id; //Added setting ID
|
inputElement.id = setting.id; //Added setting ID
|
||||||
inputElement.value = setting.defaultValue;
|
inputElement.value = settingsMap.has(setting.id) ? settingsMap.get(setting.id) : setting.defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Save settings to settings map
|
||||||
|
if (!settingsMap.has(setting.id))
|
||||||
|
settingsMap.set(setting.id, setting.defaultValue);
|
||||||
|
|
||||||
|
// Refresh the preview when any setting changes
|
||||||
inputElement.addEventListener('input', function (event) {
|
inputElement.addEventListener('input', function (event) {
|
||||||
|
const settingElement = document.getElementById(setting.id);
|
||||||
|
if (setting.type == 'checkbox')
|
||||||
|
settingsMap.set(setting.id, settingElement.checked);
|
||||||
|
else
|
||||||
|
settingsMap.set(setting.id, settingElement.value);
|
||||||
|
|
||||||
|
SaveSettingsToStorage();
|
||||||
RefreshWidgetPreview(data);
|
RefreshWidgetPreview(data);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -199,10 +220,35 @@ fetch(settingsJson)
|
|||||||
|
|
||||||
UpdateSettingItemVisibility();
|
UpdateSettingItemVisibility();
|
||||||
RefreshWidgetPreview(data);
|
RefreshWidgetPreview(data);
|
||||||
|
SaveSettingsToStorage();
|
||||||
})
|
})
|
||||||
.catch(error => console.error('Error loading settings:', error));
|
.catch(error => console.error('Error loading settings:', error));
|
||||||
|
}
|
||||||
|
|
||||||
|
function SaveSettingsToStorage() {
|
||||||
|
console.log(settingsMap);
|
||||||
|
const settingsArray = Array.from(settingsMap.entries());
|
||||||
|
const settingsArrayString = JSON.stringify(settingsArray);
|
||||||
|
localStorage.setItem('settingsMap', settingsArrayString);
|
||||||
|
}
|
||||||
|
|
||||||
|
function LoadSettingsFromStorage() {
|
||||||
|
// Retrieve session rankings from local storage
|
||||||
|
const settingsMapString = localStorage.getItem('settingsMap');
|
||||||
|
if (settingsMapString) {
|
||||||
|
const settingsMapArray = JSON.parse(settingsMapString);
|
||||||
|
settingsMap = new Map(settingsMapArray);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function LoadDefaultSettings() {
|
||||||
|
localStorage.removeItem('settingsMap');
|
||||||
|
settingsMap = new Map();
|
||||||
|
LoadJSON(settingsJson);
|
||||||
|
|
||||||
|
loadDefaultsBox.style.visibility = 'hidden';
|
||||||
|
loadDefaultsBox.style.opacity = 0;
|
||||||
|
}
|
||||||
|
|
||||||
function RefreshWidgetPreview(data) {
|
function RefreshWidgetPreview(data) {
|
||||||
const settings = {};
|
const settings = {};
|
||||||
@@ -330,6 +376,11 @@ function CopyURLToClipboard() {
|
|||||||
}, 5000);
|
}, 5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function CloseDefaultsPopup() {
|
||||||
|
loadDefaultsBox.style.visibility = 'hidden';
|
||||||
|
loadDefaultsBox.style.opacity = 0;
|
||||||
|
};
|
||||||
|
|
||||||
function CloseSettings() {
|
function CloseSettings() {
|
||||||
loadSettingsBox.style.visibility = 'hidden';
|
loadSettingsBox.style.visibility = 'hidden';
|
||||||
loadSettingsBox.style.opacity = 0;
|
loadSettingsBox.style.opacity = 0;
|
||||||
@@ -359,6 +410,11 @@ function OpenMembershipPage() {
|
|||||||
window.open("https://nutty.gg/collections/member-exclusive-widgets", '_blank').focus();
|
window.open("https://nutty.gg/collections/member-exclusive-widgets", '_blank').focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function OpenLoadDefaultsPopup() {
|
||||||
|
loadDefaultsBox.style.visibility = 'visible';
|
||||||
|
loadDefaultsBox.style.opacity = 1;
|
||||||
|
}
|
||||||
|
|
||||||
function OpenLoadSettingsPopup() {
|
function OpenLoadSettingsPopup() {
|
||||||
loadSettingsBox.style.visibility = 'visible';
|
loadSettingsBox.style.visibility = 'visible';
|
||||||
loadSettingsBox.style.opacity = 1;
|
loadSettingsBox.style.opacity = 1;
|
||||||
@@ -417,3 +473,12 @@ window.addEventListener('message', (event) => {
|
|||||||
unmuteLabel.style.display = 'none';
|
unmuteLabel.style.display = 'none';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Load settings from local storage
|
||||||
|
LoadSettingsFromStorage();
|
||||||
|
|
||||||
|
// Load default settings
|
||||||
|
LoadJSON(settingsJson);
|
||||||
@@ -329,7 +329,8 @@ button:hover {
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
#loadSettingsWrapper {
|
#loadSettingsWrapper,
|
||||||
|
#loadDefaultsWrapper {
|
||||||
visibility: hidden;
|
visibility: hidden;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: 0;
|
||||||
@@ -346,7 +347,8 @@ button:hover {
|
|||||||
opacity: 0;
|
opacity: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#loadSettingsContainer {
|
#loadSettingsContainer,
|
||||||
|
#loadDefaultsContainer {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
left: 50%;
|
left: 50%;
|
||||||
top: 50%;
|
top: 50%;
|
||||||
|
|||||||
Reference in New Issue
Block a user