// ==UserScript== // @name 影片音量增強器 // @version 0.0.35-Beta // @author Canaan HS // @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 // @grant GM_addValueChangeListener // @require https://update.greasyfork.icu/scripts/487608/1361054/SyntaxSimplified.js // @downloadURL none // ==/UserScript== (function(){if(!/^(http|https):\/\/(?!chrome\/|about\/).*$/i.test(document.URL))return!1;(new class extends Syntax{constructor(){super();this.Increase=this.Booster=this.Display=this.Domain=null;this.StyleTag=!1;this.ObserverOptions=this.MediaObserver=this.ExcludeStatus=this.BannedDomains=null;this.DetectionInitialization=b=>{this.Domain=location.hostname;this.BannedDomains=this.store("g","BannedDomains_v2",{});this.ExcludeStatus=this.BannedDomains[this.Domain];b(this.ExcludeStatus)};this.BannedDomain=async()=>{this.ExcludeStatus?delete this.BannedDomains[this.Domain]:this.BannedDomains[this.Domain]=!0;this.store("s","BannedDomains_v2",this.BannedDomains);location.reload()};this.StartMenu=async b=>{this.Menu({[b]:{func:()=>this.BannedDomain(this.Domain)}})};this.MenuHotkey=async b=>{this.Listen(document,"keydown",a=>{a.altKey&&"B"==a.key.toUpperCase()&&this.IncrementalSetting()},{passive:!0,capture:!0},a=>{a?this.Runtime(b,"Hotkey Success",{style:"\u001b[1m\u001b[32m%s\u001b[0m"}):this.Runtime(b,"Hotkey Failed",{style:"\u001b[1m\u001b[31m%s\u001b[0m"})})};this.FindMain=async(b,a)=>{a(b.sort((c,f)=>f.offsetWidth-c.offsetWidth)[0])}}async Injection(){this.DetectionInitialization(b=>{this.Display=this.Language(navigator.language);if(b)return this.StartMenu(this.Display.MS),!1;this.Observer(document.head,()=>{const a=Date.now();this.FindMain(this.$$("video",{all:!0}),c=>{c&&!c.hasAttribute("Media-Audio-Booster")&&(this.MediaObserver.disconnect(),this.Trigger(c,a))})},{mark:"Audio-Booster",throttle:300},a=>{this.MediaObserver=a.ob;this.ObserverOptions=a.op;this.StartMenu(this.Display.MD)})})}async Trigger(b,a){try{this.Increase=this.store("g",this.Domain)||1,this.Booster=this.BoosterLogic(b,this.Increase,a),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;}#sound-save {cursor: pointer;}\n"))}catch(c){this.log("Trigger Error : ",c,{type:"error",collapsed:!1})}}BoosterLogic(b,a,c){const f=window.AudioContext||window.webkitAudioContext;try{if(!f)throw this.Display.BT1;const e=new f,k=e.createMediaElementSource(b),d=e.createGain(),l=e.createBiquadFilter(),m=e.createBiquadFilter(),g=e.createDynamicsCompressor();b.volume=1;d.gain.value=a**2;g.ratio.value=6;g.knee.value=.5;g.threshold.value=-14;g.attack.value=.02;g.release.value=.4;l.frequency.value=250;l.type="lowshelf";l.gain.value=2.2;m.frequency.value=1E4;m.type="highshelf";m.gain.value=1.8;k.connect(d).connect(l).connect(m);d.connect(g).connect(e.destination);b.setAttribute("Media-Audio-Booster",!0);this.log(this.Display.BT3,{"Booster Media : ":b,"Elapsed Time : ":`${(Date.now()-c)/1E3}s`},{collapsed:!1});b.hasAttribute("Media-Audio-Booster")&&(this.MenuHotkey(c),this.Menu({[this.Display.MK]:{func:()=>alert(this.Display.MKT)},[this.Display.MM]:{func:()=>this.IncrementalSetting()}},"Menu",2),setTimeout(()=>{this.MediaObserver.observe(document.head,this.ObserverOptions)},8E3));this.storeListen([this.Domain],h=>{h.far&&h.key==this.Domain&&this.Booster.setVolume(h.nv)});return{setVolume:h=>{d.gain.value=h**2;this.Increase=h}}}catch(e){this.log(this.Display.BT4,e,{type:"error",collapsed:!1})}}async IncrementalSetting(){if(!this.$$(".Booster-Modal-Background")){const b=document.createElement("div");b.innerHTML=`