Files
tools-app/extension/popup.js

35 lines
1.2 KiB
JavaScript

// popup.js
document.addEventListener('DOMContentLoaded', () => {
const soundToggle = document.getElementById('soundToggle');
// Load saved setting
chrome.storage.local.get(['playSound'], (result) => {
soundToggle.checked = result.playSound !== false; // Default to true
});
// Save setting on change
soundToggle.addEventListener('change', () => {
chrome.storage.local.set({ playSound: soundToggle.checked });
// Play test sound if enabled
if (soundToggle.checked) {
const audioContext = new (window.AudioContext || window.webkitAudioContext)();
const oscillator = audioContext.createOscillator();
const gainNode = audioContext.createGain();
oscillator.connect(gainNode);
gainNode.connect(audioContext.destination);
oscillator.type = 'sine';
oscillator.frequency.setValueAtTime(500, audioContext.currentTime);
oscillator.frequency.exponentialRampToValueAtTime(1000, audioContext.currentTime + 0.1);
gainNode.gain.setValueAtTime(0.1, audioContext.currentTime);
gainNode.gain.exponentialRampToValueAtTime(0.01, audioContext.currentTime + 0.1);
oscillator.start();
oscillator.stop(audioContext.currentTime + 0.1);
}
});
});