mirror of
https://github.com/elder-plinius/binaural-beats-generator.git
synced 2026-02-12 16:52:50 +00:00
Update popup.js
This commit is contained in:
25
popup.js
25
popup.js
@@ -3,29 +3,30 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
let display = document.getElementById('frequencyDisplay');
|
||||
let playPauseButton = document.getElementById('togglePlayPause');
|
||||
|
||||
// Load the stored frequency value and set the slider and display accordingly
|
||||
chrome.storage.sync.get('frequency', (data) => {
|
||||
slider.value = data.frequency;
|
||||
display.textContent = `Frequency: ${data.frequency} Hz`;
|
||||
slider.value = data.frequency || 440; // Default to 440Hz if no value is stored
|
||||
display.textContent = `Frequency: ${slider.value} Hz`;
|
||||
});
|
||||
|
||||
// Update the frequency value when the slider is moved
|
||||
slider.oninput = () => {
|
||||
display.textContent = `Frequency: ${slider.value} Hz`;
|
||||
chrome.storage.sync.set({frequency: slider.value});
|
||||
};
|
||||
|
||||
// Handle the play/pause button click
|
||||
playPauseButton.addEventListener('click', function() {
|
||||
// Send a message to the background script to toggle play/pause
|
||||
chrome.runtime.sendMessage({action: 'togglePlayPause'}, (response) => {
|
||||
if (chrome.runtime.lastError) {
|
||||
console.error(chrome.runtime.lastError.message);
|
||||
return;
|
||||
}
|
||||
if (response && response.status) {
|
||||
if (response.status === 'playing') {
|
||||
playPauseButton.textContent = 'Pause';
|
||||
} else {
|
||||
playPauseButton.textContent = 'Play';
|
||||
}
|
||||
if (response && response.status === 'playing') {
|
||||
playPauseButton.textContent = 'Pause';
|
||||
} else {
|
||||
playPauseButton.textContent = 'Play';
|
||||
}
|
||||
});
|
||||
|
||||
// Send a message to resume the AudioContext in the background script
|
||||
chrome.runtime.sendMessage({action: 'resumeAudioContext'});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user