Initial commit

This commit is contained in:
DevGPT
2023-08-12 22:37:09 +00:00
commit 3afdc4e2d2
6 changed files with 102 additions and 0 deletions

19
background.js Normal file
View File

@@ -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']
});
});

18
binauralGenerator.js Normal file
View File

@@ -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;
}
});

22
manifest.json Normal file
View File

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

13
popup.html Normal file
View File

@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<h1>Binaural Beats Generator</h1>
<p>Customize the frequency of the binaural beats:</p>
<input type="range" min="1" max="1000" value="440" class="slider" id="frequencySlider">
<p id="frequencyDisplay">Frequency: 440 Hz</p>
<script src="popup.js"></script>
</body>
</html>

14
popup.js Normal file
View File

@@ -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});
};
});

16
styles.css Normal file
View File

@@ -0,0 +1,16 @@
body {
font-family: Arial, sans-serif;
padding: 10px;
}
h1 {
color: #333;
}
.slider {
width: 100%;
}
#frequencyDisplay {
margin-top: 10px;
}