Settings Management for Defaults:
dancrew32 opened this issue · comments
Dan Masquelier commented
function saveSettings(settings) {
browser.storage.local.set({ morseFireSettings: settings });
}
saveSettings({ wpm: 25, freq: 600 });
function getSettings() {
return browser.storage.local.get('morseFireSettings')
.then(result => result.morseFireSettings || defaultSettings);
}
getSettings().then(settings => console.log(settings));
options.html:
<!DOCTYPE html>
<html>
<head>
<title>MorseFire Settings</title>
</head>
<body>
<label for="wpm">WPM:</label>
<input type="number" id="wpm">
<!-- Repeat for other settings -->
<button id="save">Save</button>
<script src="options.js"></script>
</body>
</html>
(options.js):
document.addEventListener('DOMContentLoaded', () => {
// Load current settings and populate the form
getSettings().then(settings => {
document.getElementById('wpm').value = settings.wpm;
// Repeat for other settings
});
// Save settings when the Save button is clicked
document.getElementById('save').addEventListener('click', () => {
const wpm = parseInt(document.getElementById('wpm').value, 10);
// Repeat for other settings
saveSettings({ wpm });
});
});
manifest.json file additions:
{
"options_ui": {
"page": "options.html",
"chrome_style": true
}
}
Dan Masquelier commented
Done in 7ff6460