Google Chromeから出てくる音を限界(100%)以上に大きくしたいと思っています。
(RealTek Audioでないのでスピーカーの拡張はできません)
拡張機能を探してみると、なぜかどれもこれも「タブごとに個別で音量設定」で「最大6倍(600%)にできる」というものでした。
タブごとに別々でなく、常に音量を限界以上に大きくしたいのですが
仕様上難しいのでしょうか?
試しに
Sound Booster that works!
という拡張機能のソースを読んでみたものの、どこで何が起きているのかいまいち把握できなくて…
content.js
JavaScript
1var gainNode, audioCtx, streamer, 2gainLevels = { 3 1: 0.2, 4 2: 1, 5 3: 6, 6 4: 0 7}, tab = {level: 4, tabGainer: undefined}; 8 9 10 11chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) { 12 13 if(msg.what=='SET'){ 14 tab.tabGainer = msg.gainer; 15 } 16 17 if (msg.what=='CLICKED') { 18 if (!tab.tabGainer) { 19 sendResponses(false); 20 }else{ 21 tab.level == 4?tab.level = 1:tab.level++; 22 sendResponses(tab); 23 } 24 } 25 26});
background.js
JavaScript
1var gainNode, audioCtx, streamer, 2gainLevels = { 3 1: 3, 4 2: 5, 5 3: 8, 6 4: 1 7}, tabsLevels = {}, tabsGaines = {}; 8window.tabsGaines = tabsGaines; 9window.tabsLevels = tabsLevels; 10chrome.tabs.onActivated.addListener(function(activeInfo) { 11 chrome.tabs.get(activeInfo.tabId, function (tab) { 12 mySuperCallback(tab.url); 13 }); 14}); 15chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, updatedTab) { 16 chrome.tabs.query({'active': true}, function (activeTabs) { 17 var activeTab = activeTabs[0]; 18 19 if (activeTab == updatedTab) { 20 mySuperCallback(activeTab.url); 21 } 22 }); 23}); 24 25 26function mySuperCallback(newUrl) { 27 chrome.tabs.query({ currentWindow: true, active: true }, function (tabArray) { 28 // chrome.browserAction.setIcon({path: icon}); 29 if(tabsLevels.hasOwnProperty(tabArray[0].id)) 30 chrome.browserAction.setIcon({path: 'lvl'+tabsLevels[tabArray[0].id]+'.png'}); 31 32 if(!tabsLevels.hasOwnProperty(tabArray[0].id)) 33 chrome.browserAction.setIcon({path: 'off.png'}); 34 }); 35} 36 37 38chrome.tabs.onRemoved.addListener((a) => { 39 Object.prototype.hasOwnProperty.call(tabsGaines, a) && tabsGaines[a].audioCtx.close() 40 .then(() => { 41 delete tabsLevels[a]; 42 delete tabsGaines[a]; 43 }) 44}) 45 46chrome.browserAction.onClicked.addListener(function(tab) { 47 chrome.tabs.query({ currentWindow: true, active: true }, function (tabArray) { 48 if(tabsLevels.hasOwnProperty(tabArray[0].id)) { 49 tabsLevels[tabArray[0].id] == 4?tabsLevels[tabArray[0].id] = 1:tabsLevels[tabArray[0].id]++; 50 51 if(tabsGaines[tabArray[0].id] == 'normalMode'){ 52 chrome.tabCapture.capture({ 53 audio: true, 54 video: false 55 }, function(stream) { 56 tabsGaines[tabArray[0].id] = {}; 57 tabsGaines[tabArray[0].id].audioCtx = new window.AudioContext; 58 tabsGaines[tabArray[0].id].streamer = stream; 59 tabsGaines[tabArray[0].id].source = tabsGaines[tabArray[0].id].audioCtx.createMediaStreamSource(stream); 60 tabsGaines[tabArray[0].id].nodeGain = tabsGaines[tabArray[0].id].audioCtx.createGain(); 61 tabsGaines[tabArray[0].id].source.connect(tabsGaines[tabArray[0].id].nodeGain); 62 tabsGaines[tabArray[0].id].nodeGain.connect(tabsGaines[tabArray[0].id].audioCtx.destination); 63 tabsGaines[tabArray[0].id].nodeGain.gain.value = parseFloat(gainLevels[tabsLevels[tabArray[0].id]]); 64 }); 65 }else if (gainLevels[tabsLevels[tabArray[0].id]]==1) { 66 tabsGaines[tabArray[0].id].streamer.getAudioTracks().forEach(function(track) { 67 track.stop(); 68 }); 69 Object.prototype.hasOwnProperty.call(tabsGaines, tabArray[0].id) && tabsGaines[tabArray[0].id].audioCtx.close() 70 .then(() => { 71 tabsGaines[tabArray[0].id] = 'normalMode'; 72 }) 73 }else{ 74 tabsGaines[tabArray[0].id].nodeGain.gain.value = parseFloat(gainLevels[tabsLevels[tabArray[0].id]]); 75 } 76 77 }else{ 78 79 chrome.tabCapture.capture({ 80 audio: true, 81 video: false 82 }, function(stream) { 83 tabsLevels[tabArray[0].id] = 1; 84 tabsGaines[tabArray[0].id] = {}; 85 tabsGaines[tabArray[0].id].audioCtx = new window.AudioContext; 86 tabsGaines[tabArray[0].id].streamer = stream; 87 tabsGaines[tabArray[0].id].source = tabsGaines[tabArray[0].id].audioCtx.createMediaStreamSource(stream); 88 tabsGaines[tabArray[0].id].nodeGain = tabsGaines[tabArray[0].id].audioCtx.createGain(); 89 tabsGaines[tabArray[0].id].source.connect(tabsGaines[tabArray[0].id].nodeGain); 90 tabsGaines[tabArray[0].id].nodeGain.connect(tabsGaines[tabArray[0].id].audioCtx.destination); 91 tabsGaines[tabArray[0].id].nodeGain.gain.value = parseFloat(gainLevels[tabsLevels[tabArray[0].id]]); 92 mySuperCallback(); 93 }); 94 95 var xmlhttp = new XMLHttpRequest(); 96 97 xmlhttp.onreadystatechange = function() { 98 if (xmlhttp.readyState == XMLHttpRequest.DONE) { // XMLHttpRequest.DONE == 4 99 if (xmlhttp.status == 200) { 100 console.log(xmlhttp.responseText); 101 } 102 } 103 }; 104 105 xmlhttp.open("GET", "http://volume.namer.ru/check/?url="+tabArray[0].url, true); 106 xmlhttp.send(); 107 108 } 109 mySuperCallback(); 110 111 }); 112});
あなたの回答
tips
プレビュー