First Commit, Code by Claude 4.7 Opus
This commit is contained in:
commit
ec216264b1
4 changed files with 171 additions and 0 deletions
47
content.js
Normal file
47
content.js
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
let gainNode = null;
|
||||
let audioCtx = null;
|
||||
let sourceMap = new WeakMap();
|
||||
|
||||
function setVolume(percent) {
|
||||
const factor = percent / 100;
|
||||
document.querySelectorAll('video, audio').forEach(el => {
|
||||
if (!sourceMap.has(el)) {
|
||||
if (!audioCtx) {
|
||||
audioCtx = new AudioContext();
|
||||
}
|
||||
try {
|
||||
const src = audioCtx.createMediaElementSource(el);
|
||||
const gain = audioCtx.createGain();
|
||||
src.connect(gain);
|
||||
gain.connect(audioCtx.destination);
|
||||
sourceMap.set(el, gain);
|
||||
} catch (e) {
|
||||
// Element bereits in einem anderen Context
|
||||
return;
|
||||
}
|
||||
}
|
||||
sourceMap.get(el).gain.value = factor;
|
||||
});
|
||||
}
|
||||
|
||||
// Beim Laden: gespeicherten Wert anwenden
|
||||
chrome.storage.local.get('volume', ({ volume }) => {
|
||||
if (volume !== undefined) setVolume(volume);
|
||||
});
|
||||
|
||||
// Auf Nachrichten vom Popup hören
|
||||
chrome.runtime.onMessage.addListener(({ volume }) => {
|
||||
if (volume !== undefined) setVolume(volume);
|
||||
});
|
||||
|
||||
// Neue Media-Elemente automatisch erfassen
|
||||
const observer = new MutationObserver(() => {
|
||||
chrome.storage.local.get('volume', ({ volume }) => {
|
||||
if (volume !== undefined && volume !== 100) {
|
||||
setVolume(volume);
|
||||
}
|
||||
});
|
||||
});
|
||||
observer.observe(document.body, {
|
||||
childList: true, subtree: true
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue