dancrew32 / morsefire

Firefox extension to play highlighted text as morse code. Highlight, right click, "Play selection as Morse Code"

Home Page:https://addons.mozilla.org/en-US/firefox/addon/morsefire

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Settings Management for Defaults:

dancrew32 opened this issue · comments

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
  }
}