// ==UserScript== // @name 影片音量增強器 // @version 0.0.31 // @author HentaiSaru // @description 增強影片音量上限,最高增幅至 20 倍,有些不支援的網站,影片會沒聲音 或是 沒有效果,命令選單有時有 BUG 會多創建一個,但不影響原功能使用。 // @description:zh-TW 增強影片音量上限,最高增幅至 20 倍,有些不支援的網站,影片會沒聲音禁用增幅即可,命令選單有時有 BUG 會多創建一個,但不影響原功能使用。 // @description:zh-CN 增强影片音量上限,最高增幅至 20 倍。有些不支援的网站,影片会没声音,禁用增幅即可。命令选单有时有 BUG 会多创建一个,但不影响原功能使用。 // @description:en Enhance the upper limit of video volume, boosting up to 20 times. For unsupported websites where videos have no sound, disabling the boost is sufficient. Occasionally, there may be a bug in the command menu causing duplication, but it does not affect the original functionality. // @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 unsafeWindow // @grant GM_setValue // @grant GM_getValue // @grant GM_addStyle // @grant GM_registerMenuCommand // @require https://update.greasyfork.icu/scripts/487608/1329278/GrammarSimplified.js // @downloadURL none // ==/UserScript== (function(){if(/^(http|https):\/\/(?!chrome\/|about\/).*$/i.test(document.URL)){class l extends API{constructor(){super();this.Increase=this.Booster=null;this.StyleTag=!1;this.Domain=location.hostname;this.Display=this.Language(navigator.language);this.BannedDomains=this.store("get","BannedDomains",[]);this.ExcludeStatus=this.BannedDomains.includes(this.Domain);this.BannedDomain=async a=>{this.ExcludeStatus?this.BannedDomains=this.BannedDomains.filter(b=>b!=a):this.BannedDomains.push(a);this.store("set","BannedDomains",this.BannedDomains);location.reload()};this.StatusMenu=async a=>{this.Menu({[a]:()=>this.BannedDomain(this.Domain)})};this.MenuHotkey=async()=>{this.AddListener(document,"keydown",a=>{a.altKey&&"b"===a.key&&this.IncrementalSetting()},{passive:!0,capture:!0})};this.Verify=()=>{const a=this.$$("video");return a&&a.hasAttribute("Media-Audio-Booster")?!0:!1}}static async Injection(){let a,b=new l;b.ExcludeStatus?b.StatusMenu(b.Display.MS):((new MutationObserver(()=>{(a=b.$$("video"))&&!a.hasAttribute("Media-Audio-Booster")&&b.Trigger(a,performance.now())})).observe(document.head,{childList:!0,subtree:!0}),b.StatusMenu(b.Display.MD))}async Trigger(a,b){try{this.Increase=this.store("get",this.Domain)||1,this.Booster=this.BoosterLogic(a,this.Increase,b),this.StyleTag||(this.StyleTag=!0,this.AddStyle(".Booster-Modal-Background {top: 0;left: 0;width: 100%;height: 100%;display: flex;z-index: 9999;overflow: auto;position: fixed;align-items: center;justify-content: center;}.Booster-Modal-Button {top: 0;margin: 3% 2%;color: #d877ff;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;cursor: pointer;text-decoration: none;}.Booster-Modal-Content {width: 400px;padding: 5px;overflow: auto;background-color: #cff4ff;border-radius: 10px;text-align: center;border: 2px ridge #82c4e2;border-collapse: collapse;margin: 2% auto 8px auto;}.Booster-Multiplier {font-size:25px;color:rgb(253, 1, 85);margin: 10px;font-weight:bold;}.Booster-Slider {width: 350px;}div input {cursor: pointer;}"))}catch(e){this.log("Trigger Error : ",e,"error")}}BoosterLogic(a,b,e){const c=window.AudioContext||window.oAudioContext;try{if(!c)throw this.Display.BT1;const d=new c,n=d.createMediaElementSource(a),g=d.createGain(),h=d.createBiquadFilter(),k=d.createBiquadFilter(),f=d.createDynamicsCompressor();a.volume=1;g.gain.value=b**2;f.ratio.value=6;f.knee.value=.5;f.threshold.value=-14;f.attack.value=.02;f.release.value=.4;h.frequency.value=250;h.type="lowshelf";h.gain.value=2.2;k.frequency.value=1E4;k.type="highshelf";k.gain.value=1.8;n.connect(g).connect(h).connect(k);g.connect(f).connect(d.destination);a.setAttribute("Media-Audio-Booster",!0);if(!this.Verify())throw this.Display.BT2;this.MenuHotkey();this.Menu({[this.Display.MK]:()=>alert(this.Display.MKT),[this.Display.MM]:()=>this.IncrementalSetting()});this.log(this.Display.BT3,{"Booster Media : ":a,"Elapsed Time : ":`${(performance.now()-e).toFixed(2)}ms`});return{setVolume:m=>{g.gain.value=m**2;this.Increase=m}}}catch(d){this.log(this.Display.BT4,d)}}async IncrementalSetting(){if(!this.$$(".Booster-Modal-Background")){const a=document.createElement("div");a.innerHTML=`