-
Notifications
You must be signed in to change notification settings - Fork 0
/
inject.js
45 lines (37 loc) · 1.37 KB
/
inject.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
(function() {
let eventArray = [];
let count = true;
chrome.storage.local.get('audioDataArray', function (result) {
});
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
let windowVideos = document.querySelectorAll("video");
if(count && windowVideos && eventArray.length == 0){
windowVideos.forEach(function(element){
eventArray.push(amplifyMedia(element,request.data));
})
count = false;
}
else{
let windowVideos = document.querySelectorAll("video");
eventArray.forEach(function(element,index){
eventArray[index].gain.gain.value = request.data;
})
}
});
})();
function amplifyMedia(mediaElem, multiplier) {
var context = new (window.AudioContext || window.webkitAudioContext),
result = {
context: context,
source: context.createMediaElementSource(mediaElem),
gain: context.createGain(),
media: mediaElem,
amplify: function(multiplier) { result.gain.gain.value = multiplier; },
getAmpLevel: function() { return result.gain.gain.value; }
};
result.source.connect(result.gain);
result.gain.connect(context.destination);
result.amplify(multiplier);
return result;
}