// ==UserScript== // @name 影片音量增強器 // @version 0.0.33 // @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/1330066/GrammarSimplified.js // @downloadURL none // ==/UserScript== /^(http|https):\/\/(?!chrome\/|about\/).*$/i.test(document.URL)&&(new class 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 a=>{this.Listen(document,"keydown",b=>{b.altKey&&"B"==b.key.toUpperCase()&&this.IncrementalSetting()},{passive:!0,capture:!0},b=>{var c=(Date.now()-a).toFixed(2)+"ms";b?this.log("Hotkey Success",c):this.log("Hotkey Failed",c)})};this.FindMain=async(a,b)=>{b(a.sort((c,f)=>f.offsetWidth-c.offsetWidth)[0])}}async Injection(){if(this.ExcludeStatus)this.StatusMenu(this.Display.MS);else{let a=Date.now();const b=new MutationObserver(()=>{this.FindMain(this.$$("video",!0),c=>{c&&!c.hasAttribute("Media-Audio-Booster")&&(b.disconnect(),this.Trigger(c,a))})});b.observe(document.head,{childList:!0,subtree:!0});this.StatusMenu(this.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;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;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: 15px;font-weight:bold;}.Booster-Modal-Background-Closur {opacity: 0;pointer-events: none;}.Booster-Slider {width: 350px;}div input {cursor: pointer;}"))}catch(c){this.log("Trigger Error : ",c,"error")}}BoosterLogic(a,b,c){var f=window.AudioContext||window.oAudioContext;try{if(!f)throw this.Display.BT1;var d=new f,e=d.createMediaElementSource(a);const h=d.createGain();var g=d.createBiquadFilter(),l=d.createBiquadFilter(),k=d.createDynamicsCompressor();return a.volume=1,h.gain.value=b**2,k.ratio.value=6,k.knee.value=.5,k.threshold.value=-14,k.attack.value=.02,k.release.value=.4,g.frequency.value=250,g.type="lowshelf",g.gain.value=2.2,l.frequency.value=1E4,l.type="highshelf",l.gain.value=1.8,e.connect(h).connect(g).connect(l),h.connect(k).connect(d.destination),a.setAttribute("Media-Audio-Booster",!0),this.Menu({[this.Display.MK]:()=>alert(this.Display.MKT),[this.Display.MM]:()=>this.IncrementalSetting()}),this.MenuHotkey(c),this.log(this.Display.BT3,{"Booster Media : ":a,"Elapsed Time : ":(Date.now()-c).toFixed(2)+"ms"}),a.hasAttribute("Media-Audio-Booster")&&setTimeout(()=>{this.Injection()},5E3),{setVolume:m=>{h.gain.value=m**2;this.Increase=m}}}catch(h){this.log(this.Display.BT4,h)}}async IncrementalSetting(){if(!this.$$(".Booster-Modal-Background")){var a=document.createElement("div");a.innerHTML=`