mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
1 line
2.4 KiB
JavaScript
1 line
2.4 KiB
JavaScript
(()=>(e,t)=>{const n=new Map;const i=e=>{console.log("create new context");const t=new AudioContext;const i=t.createMediaElementSource(e);const o=t.createGain();i.connect(o);o.connect(t.destination);n.set(e,o.gain);return o.gain};const o=e=>{if(n.has(e)){const t=n.get(e);t.value=1}};const r=(e,t)=>{if(n.has(e)){const i=n.get(e);let o=i.value+t;if(o<0){o=0}i.value=o;return o}else{const n=i(e);const o=n.value+t;n.value=o;return o}};const s=async()=>{const e=["https://www.bilibili.com/bangumi/","https://www.bilibili.com/video/","https://www.bilibili.com/watchlater/","https://www.bilibili.com/medialist/play/"];if(e.every((e=>!document.URL.startsWith(e)))){return}let i;const o=e=>{let n=dq(".volume-overdrive-tip");if(!n){const e=dq(".bilibili-player-video-wrap");if(!e){return}e.insertAdjacentHTML("afterbegin",`\n<div class="volume-overdrive-tip-container">\n<i class="mdi mdi-volume-high"></i>\n<div class="volume-overdrive-tip"></div>\n</div>\n`);t.applyStyleFromText(`\n .volume-overdrive-tip-container {\n position: absolute;\n left: 50%;\n top: 50%;\n transform: translate(-50%, -50%);\n padding: 8px 16px;\n background-color: #000A;\n color: white;\n pointer-events: none;\n opacity: 0;\n z-index: 100;\n display: flex;\n align-items: center;\n font-size: 14pt;\n border-radius: 4px;\n transition: .2s ease-out;\n }\n .volume-overdrive-tip-container.show {\n opacity: 1;\n }\n .volume-overdrive-tip-container i {\n line-height: 1;\n margin-right: 8px;\n font-size: 18pt;\n }\n`,"volumeOverdriveStyle");n=dq(".volume-overdrive-tip")}const o=dq("video");n.innerHTML=`音量${Math.round(o.volume*100)}% x 增幅${Math.round(e*100)}% = ${Math.round(o.volume*e*100)}%`;if(i){clearTimeout(i)}dq(".volume-overdrive-tip-container").classList.add("show");i=window.setTimeout((()=>{dq(".volume-overdrive-tip-container").classList.remove("show")}),2e3)};Observer.videoChange((async()=>{n.clear();document.body.addEventListener("keydown",(e=>{const t=!e.shiftKey&&e.ctrlKey&&!e.altKey&&!e.metaKey;if(t&&(e.key==="ArrowDown"||e.key==="ArrowUp")){const t=dq("video");if(!t){return}const n=e.key==="ArrowDown"?-.1:.1;const i=r(t,n);o(i);e.preventDefault();e.stopImmediatePropagation()}}),{capture:true})}))};s();return{export:{setVolume:r}}})(); |