commit 3afdc4e2d2a25465b01b00035dcd3f6195257034 Author: DevGPT Date: Sat Aug 12 22:37:09 2023 +0000 Initial commit diff --git a/background.js b/background.js new file mode 100644 index 0000000..7033420 --- /dev/null +++ b/background.js @@ -0,0 +1,19 @@ +chrome.runtime.onInstalled.addListener(() => { + chrome.storage.sync.set({frequency: '440'}); +}); + +chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => { + if (changeInfo.status === 'complete' && /^http/.test(tab.url)) { + chrome.scripting.executeScript({ + target: {tabId: tabId}, + files: ['binauralGenerator.js'] + }); + } +}); + +chrome.action.onClicked.addListener((tab) => { + chrome.scripting.executeScript({ + target: {tabId: tab.id}, + files: ['binauralGenerator.js'] + }); +}); \ No newline at end of file diff --git a/binauralGenerator.js b/binauralGenerator.js new file mode 100644 index 0000000..7a09369 --- /dev/null +++ b/binauralGenerator.js @@ -0,0 +1,18 @@ +let context = new AudioContext(); +let oscillator = context.createOscillator(); +let gainNode = context.createGain(); + +oscillator.connect(gainNode); +gainNode.connect(context.destination); + +chrome.storage.sync.get('frequency', (data) => { + oscillator.frequency.value = data.frequency; +}); + +oscillator.start(); + +chrome.storage.onChanged.addListener((changes, areaName) => { + if (areaName === 'sync' && changes.frequency) { + oscillator.frequency.value = changes.frequency.newValue; + } +}); \ No newline at end of file diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..7acf55e --- /dev/null +++ b/manifest.json @@ -0,0 +1,22 @@ +{ + "manifest_version": 3, + "name": "Binaural Beats Generator", + "version": "1.0", + "permissions": ["storage", "tabs", "activeTab"], + "action": { + "default_popup": "popup.html", + "default_icon": { + "16": "images/icon16.png", + "48": "images/icon48.png", + "128": "images/icon128.png" + } + }, + "background": { + "service_worker": "background.js" + }, + "icons": { + "16": "images/icon16.png", + "48": "images/icon48.png", + "128": "images/icon128.png" + } +} \ No newline at end of file diff --git a/popup.html b/popup.html new file mode 100644 index 0000000..8d00d09 --- /dev/null +++ b/popup.html @@ -0,0 +1,13 @@ + + + + + + +

Binaural Beats Generator

+

Customize the frequency of the binaural beats:

+ +

Frequency: 440 Hz

+ + + \ No newline at end of file diff --git a/popup.js b/popup.js new file mode 100644 index 0000000..d0d1630 --- /dev/null +++ b/popup.js @@ -0,0 +1,14 @@ +document.addEventListener('DOMContentLoaded', () => { + let slider = document.getElementById('frequencySlider'); + let display = document.getElementById('frequencyDisplay'); + + chrome.storage.sync.get('frequency', (data) => { + slider.value = data.frequency; + display.textContent = `Frequency: ${data.frequency} Hz`; + }); + + slider.oninput = () => { + display.textContent = `Frequency: ${slider.value} Hz`; + chrome.storage.sync.set({frequency: slider.value}); + }; +}); \ No newline at end of file diff --git a/styles.css b/styles.css new file mode 100644 index 0000000..651aa63 --- /dev/null +++ b/styles.css @@ -0,0 +1,16 @@ +body { + font-family: Arial, sans-serif; + padding: 10px; +} + +h1 { + color: #333; +} + +.slider { + width: 100%; +} + +#frequencyDisplay { + margin-top: 10px; +} \ No newline at end of file