-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
46 lines (39 loc) · 1.43 KB
/
content.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// content.js
let audioContext = null;
let sourceNode = null;
let gainNode = null;
let filterNode = null;
let bassBoostNode = null;
function startLofiEffect() {
if (audioContext) return;
audioContext = new AudioContext();
const audioElement = document.querySelector('audio, video');
if (!audioElement) {
console.log("No audio element found on this page.");
return;
}
sourceNode = audioContext.createMediaElementSource(audioElement);
audioElement.playbackRate = 0.75;
gainNode = audioContext.createGain();
gainNode.gain.value = 0.8;
filterNode = audioContext.createBiquadFilter();
filterNode.type = "lowpass";
filterNode.frequency.value = 800;
bassBoostNode = audioContext.createBiquadFilter();
bassBoostNode.type = "lowshelf";
bassBoostNode.frequency.value = 10;
bassBoostNode.gain.value = 100;
console.log("Lofi effect started.");
sourceNode.connect(bassBoostNode).connect(filterNode).connect(gainNode).connect(audioContext.destination);
console.log("Lofi effects applied.");
}
function stopLofiEffect() {
if (audioContext) {
audioContext.close().then(() => {
console.log("Audio context closed");
audioContext = null;
}).catch(error => console.error("Error closing audio context:", error));
} else {
console.log("No active audio context to stop.");
}
}