媒體音量增強器

增强媒体音量最高至 20 倍,可记住增强设置后自动应用,部分网站可能无效或无声,可选择禁用。

// ==UserScript==
// @name         媒體音量增強器
// @version      0.0.37
// @author       Canaan HS
// @description  增強媒體音量最高至 20 倍,可記住增強設置後自動應用,部分網站可能無效或無聲,可選擇禁用。
// @description:zh-TW 增強媒體音量最高至 20 倍,可記住增強設置後自動應用,部分網站可能無效或無聲,可選擇禁用。
// @description:zh-CN 增强媒体音量最高至 20 倍,可记住增强设置后自动应用,部分网站可能无效或无声,可选择禁用。
// @description:en Boost media volume up to 20 times, automatically apply saved settings, may not work or have no sound on some sites, can disable if needed.

// @noframes
// @match        *://*/*
// @icon         https://cdn-icons-png.flaticon.com/512/8298/8298181.png

// @license      MIT
// @namespace    https://greasyfork.org/users/989635

// @run-at       document-start
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_getResourceURL
// @grant        GM_registerMenuCommand
// @grant        GM_addValueChangeListener
// @resource     Img https://cdn-icons-png.flaticon.com/512/8298/8298181.png
// @require      https://update.greasyfork.org/scripts/487608/1456525/ClassSyntax_min.js
// ==/UserScript==
(async()=>{(new class extends Syntax{constructor(){super();this.Increase=this.Booster=null;this.EnhanceNodes=[];this.MediaContent=null;this.AudioContext=window.AudioContext||window.webkitAudioContext;this.ExcludeStatus=this.Init=this.ObserverOption=this.MediaObserver=null;this.Host=this.Device.Host;this.Lang=this.Language(this.Device.Lang);this.BannedHost=this.Store("g","BannedDomains_v2",{});this.GetBannedHost=c=>{this.ExcludeStatus=this.BannedHost[this.Host]??!1;c(!this.ExcludeStatus)};this.Banned=async()=>{this.ExcludeStatus?delete this.BannedHost[this.Host]:this.BannedHost[this.Host]=!0;this.Store("s","BannedDomains_v2",this.BannedHost);location.reload()};this.MenuHotkey=async()=>{this.AddListener(document,"keydown",c=>{c.altKey&&"B"==c.key.toUpperCase()&&this.BoosterMenu()},{passive:!0,capture:!0})}}BoosterFactory(c,b){try{if(!this.AudioContext)throw this.Lang.Transl("\u4e0d\u652f\u63f4\u97f3\u983b\u589e\u5f37\u7bc0\u9ede");this.MediaContent||(this.MediaContent=new this.AudioContext);"suspended"===this.MediaContent.state&&this.MediaContent.resume();const d=this.EnhanceNodes.length;for(const a of c){const f=this.MediaContent.createMediaElementSource(a),g=this.MediaContent.createGain(),h=this.MediaContent.createBiquadFilter(),e=this.MediaContent.createBiquadFilter(),l=this.MediaContent.createBiquadFilter(),k=this.MediaContent.createDynamicsCompressor(),m=setInterval(()=>{a.volume=1},1E3);setTimeout(()=>{clearInterval(m)},3E3);g.gain.value=this.Increase**2;h.type="lowshelf";h.gain.value=2.2;h.frequency.value=200;e.type="peaking";e.Q.value=1;e.gain.value=3;e.frequency.value=1200;l.type="highshelf";l.gain.value=1.8;l.frequency.value=12E3;k.ratio.value=5.4;k.knee.value=.4;k.threshold.value=-12;k.attack.value=.02;k.release.value=.4;f.connect(g).connect(h).connect(e).connect(l).connect(k).connect(this.MediaContent.destination);a.setAttribute("Enhanced-Node",!0);this.EnhanceNodes.push(g)}this.EnhanceNodes.length>d&&(this.Log(this.Lang.Transl("\u6dfb\u52a0\u589e\u5f37\u7bc0\u9ede\u6210\u529f"),{"Booster Media : ":c,"Elapsed Time : ":this.Runtime(b,{log:!1})},{collapsed:!1}),this.Init||(this.Init=!0,this.Menu({[this.Lang.Transl("\ud83d\udcdc \u83dc\u55ae\u71b1\u9375")]:{func:()=>alert(this.Lang.Transl("\u71b1\u9375\u547c\u53eb\u8abf\u6574\u83dc\u55ae!!\n\n\u5feb\u6377\u7d44\u5408 : (Alt + B)"))},[this.Lang.Transl("\ud83d\udee0\ufe0f \u8abf\u6574\u83dc\u55ae")]:{func:()=>this.BoosterMenu()}},"Menu",2),this.MenuHotkey(),this.StoreListen([this.Host],a=>{a.far&&a.key==this.Host&&this.Booster.setVolume(a.nv)})));setTimeout(()=>{this.MediaObserver.observe(document,this.ObserverOption)},3E3);return{setVolume:a=>{this.Increase=a;this.EnhanceNodes.forEach(f=>{f.gain.value=this.Increase**2})}}}catch(d){this.Log(this.Lang.Transl("\u589e\u5f37\u932f\u8aa4"),d,{type:"error",collapsed:!1})}}async Trigger(c,b){try{this.Increase=this.Store("g",this.Host)??1,this.Booster=this.BoosterFactory(c,b)}catch(d){this.Log("Trigger Error : ",d,{type:"error",collapsed:!1})}}async Injec(){const c=async b=>{this.Menu({[b]:{func:()=>this.Banned()}})};this.GetBannedHost(b=>{if(b){const d=this.Debounce(a=>{const f=[...this.$$("video, audio",{all:!0})].filter(g=>g&&!g.hasAttribute("Enhanced-Node"));0<f.length&&a(f)},400);this.Observer(document,()=>{const a=this.Runtime();d(f=>{this.MediaObserver.disconnect();this.Trigger(f,a)})},{mark:"Media-Booster",attributes:!1,throttle:500},a=>{this.MediaObserver=a.ob;this.ObserverOption=a.op;c(this.Lang.Transl("\u274c \u7981\u7528\u589e\u5e45"))})}else c(this.Lang.Transl("\u2705 \u555f\u7528\u589e\u5e45"))})}async BoosterMenu(){function c(){a.classList.add("Booster-Modal-Background-Closur");setTimeout(()=>{b.remove()},800)}if(!this.$$("#Booster_Modal_Background")){var b=document.createElement("div"),d=b.attachShadow({mode:"open"});b.id="Booster_Modal_Background";d.innerHTML=`<style id="Booster-Menu">Booster_Modal_Background {top: 0;left: 0;opacity: 1;width: 100%;height: 100%;display: flex;z-index: 9999;overflow: auto;position: fixed;align-items: center;justify-content: center;transition: opacity 0.4s ease;}.Booster-Modal-Button {margin: 0 2% 2% 0;color: #d877ff;cursor: pointer;font-size: 16px;font-weight: bold;padding: 0 0.3rem;border-radius: 3px;background-color: #ffebfa;border: 1px solid rgb(124, 183, 252);}.Booster-Modal-Button:hover,.Booster-Modal-Button:focus {color: #fc0e85;text-decoration: none;}.Booster-Modal-Content {width: 400px;padding: 5px;overflow: auto;text-align: center;border-radius: 10px;background-color: #cff4ff;border: 2px ridge #82c4e2;border-collapse: collapse;margin: 2% auto 8px auto;}.Booster-Slider {width: 350px;cursor: pointer;margin-bottom: 1rem;}.Booster-Multiplier {margin: 2rem;font-size: 25px;font-weight: bold;color:rgb(253, 1, 85);}.Booster-Multiplier img {width: 8%;}.Booster-Multiplier span {display: flex;align-items: center;justify-content: center;}.Booster-Modal-Background-Closur {opacity: 0;pointer-events: none;}</style><Booster_Modal_Background id="Booster-Modal-Menu"><div class="Booster-Modal-Content"><div><h2 style="color: #3754f8;">${this.Lang.Transl("\u97f3\u91cf\u589e\u5f37")}</h2><div class="Booster-Multiplier"><span><img src="${GM_getResourceURL("Img")}">${this.Lang.Transl("\u589e\u5f37\u500d\u6578 ")}<span id="Booster-CurrentValue">${this.Increase}</span>${this.Lang.Transl(" \u500d")}</span></div><input type="range" id="Adjustment-Sound-Enhancement" class="Booster-Slider" min="0" max="20.0" value="${this.Increase}" step="0.1"><br></div><div style="text-align: right;"><button class="Booster-Modal-Button" id="Booster-Menu-Close">${this.Lang.Transl("\u95dc\u9589")}</button><button class="Booster-Modal-Button" id="Booster-Sound-Save">${this.Lang.Transl("\u4fdd\u5b58")}</button></div></div></Booster_Modal_Background>`;document.body.appendChild(b);d=b.shadowRoot;var a=d.querySelector("Booster_Modal_Background"),f=d.querySelector("#Booster-CurrentValue"),g=d.querySelector("#Adjustment-Sound-Enhancement"),h;this.Listen(g,"input",e=>{h=e.target.value;f.textContent=h;this.Booster.setVolume(h)});this.Listen(a,"click",e=>{e.stopPropagation();e=e.target;"Booster-Sound-Save"===e.id?(this.Increase=e=parseFloat(g.value),this.Store("s",this.Host,e),c()):"Booster-Menu-Close"!==e.id&&"Booster-Modal-Menu"!==e.id||c()})}}Language(c){var b={},d={"\u2705 \u555f\u7528\u589e\u5e45":"\u2705 \u542f\u7528\u589e\u5e45","\ud83d\udcdc \u83dc\u55ae\u71b1\u9375":"\ud83d\udcdc \u83dc\u5355\u70ed\u952e","\ud83d\udee0\ufe0f \u8abf\u6574\u83dc\u55ae":"\ud83d\udee0\ufe0f \u8c03\u6574\u83dc\u5355","\u95dc\u9589":"\u5173\u95ed","\u97f3\u91cf\u589e\u5f37":"\u97f3\u91cf\u589e\u5f3a","\u589e\u5f37\u500d\u6578 ":"\u589e\u5f3a\u500d\u6570 ","\u589e\u5f37\u932f\u8aa4":"\u589e\u5f3a\u9519\u8bef","\u6dfb\u52a0\u589e\u5f37\u7bc0\u9ede\u6210\u529f":"\u6dfb\u52a0\u589e\u5f3a\u8282\u70b9\u6210\u529f","\u4e0d\u652f\u63f4\u97f3\u983b\u589e\u5f37\u7bc0\u9ede":"\u4e0d\u652f\u6301\u97f3\u9891\u589e\u5f3a\u8282\u70b9","\u71b1\u9375\u547c\u53eb\u8abf\u6574\u83dc\u55ae!!\n\n\u5feb\u6377\u7d44\u5408 : (Alt + B)":"\u70ed\u952e\u547c\u53eb\u8c03\u6574\u83dc\u5355!!\n\n\u5feb\u6377\u7ec4\u5408 : (Alt + B)"};b={"en-US":{"\u274c \u7981\u7528\u589e\u5e45":"\u274c Disable Boost","\u2705 \u555f\u7528\u589e\u5e45":"\u2705 Enable Boost","\ud83d\udcdc \u83dc\u55ae\u71b1\u9375":"\ud83d\udcdc Menu Hotkey","\ud83d\udee0\ufe0f \u8abf\u6574\u83dc\u55ae":"\ud83d\udee0\ufe0f Adjust Menu"," \u500d":"x","\u95dc\u9589":"Close","\u4fdd\u5b58":"Save","\u97f3\u91cf\u589e\u5f37":"Volume Boost","\u589e\u5f37\u500d\u6578 ":"Boost Multiplier ","\u589e\u5f37\u932f\u8aa4":"Boost Error","\u6dfb\u52a0\u589e\u5f37\u7bc0\u9ede\u6210\u529f":"Successfully Added Boost Node","\u4e0d\u652f\u63f4\u97f3\u983b\u589e\u5f37\u7bc0\u9ede":"Audio Boost Node Not Supported","\u71b1\u9375\u547c\u53eb\u8abf\u6574\u83dc\u55ae!!\n\n\u5feb\u6377\u7d44\u5408 : (Alt + B)":"Hotkey to Call Adjust Menu!!\n\nShortcut: (Alt + B)"},"zh-CN":d,"zh-SG":d,"zh-TW":b,"zh-HK":b,"zh-MO":b};const a=b[c]??b["en-US"];return{Transl:f=>a[f]??f}}}).Injec()})();