mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
1 line
2.5 KiB
JavaScript
1 line
2.5 KiB
JavaScript
(()=>{return(e,i)=>{const t=["https://www.bilibili.com/bangumi/","https://www.bilibili.com/video/"];if(t.some(e=>document.URL.startsWith(e))){const e={w:".bilibili-player-video-web-fullscreen",t:".bilibili-player-video-btn-widescreen",r:".bilibili-player-video-btn-repeat",m:".bilibili-player-video-btn-volume .bilibili-player-iconfont-volume",l:".video-toolbar .like",c:".video-toolbar .coin,.tool-bar .coin-info",s:".video-toolbar .collect"};let t;const a=e=>{let a=dq(".keymap-playback-tip");if(!a){const e=dq(".bilibili-player-video-wrap");if(!e){return}e.insertAdjacentHTML("afterbegin",`\n<div class="keymap-playback-tip-container">\n<i class="mdi mdi-fast-forward"></i>\n<div class="keymap-playback-tip"></div>x\n</div>\n`);i.applyStyleFromText(`\n.keymap-playback-tip-container {\nposition: absolute;\nleft: 50%;\ntop: 50%;\ntransform: translate(-50%, -50%);\npadding: 8px 16px;\nbackground-color: #000A;\ncolor: white;\npointer-events: none;\nopacity: 0;\nz-index: 100;\ndisplay: flex;\nalign-items: center;\nfont-size: 14pt;\nborder-radius: 4px;\ntransition: .2s ease-out;\n}\n.keymap-playback-tip-container.show {\nopacity: 1;\n}\n.keymap-playback-tip-container i {\nline-height: 1;\nmargin-right: 8px;\nfont-size: 18pt;\n}\n`,"keymapStyle");a=dq(".keymap-playback-tip")}a.innerHTML=e.toString();if(t){clearTimeout(t)}dq(".keymap-playback-tip-container").classList.add("show");t=setTimeout(()=>{dq(".keymap-playback-tip-container").classList.remove("show")},2e3)};document.body.addEventListener("keydown",i=>{if(document.activeElement&&["input","textarea"].includes(document.activeElement.nodeName.toLowerCase())){return}const t=i.key.toLowerCase();const n=!i.shiftKey&&!i.altKey&&!i.ctrlKey;if(t in e&&n){const a=dq(e[t]);if(!a){return}i.stopPropagation();i.preventDefault();a.click()}else if(t==="d"&&n){const e=dq(".bilibili-player-video-danmaku-switch input");if(!e){return}i.stopPropagation();i.preventDefault();e.checked=!e.checked;raiseEvent(e,"change")}else if(i.shiftKey){const e=dq(".bilibili-player-video video");if(e===null){return}i.stopPropagation();i.preventDefault();const n=[.5,.75,1,1.25,1.5,2];if(t===">"||t==="ArrowUp".toLowerCase()){e.playbackRate=n.find(i=>i>e.playbackRate)||n[n.length-1];a(e.playbackRate)}else if(t==="<"||t==="ArrowDown".toLowerCase()){e.playbackRate=[...n].reverse().find(i=>i<e.playbackRate)||n[0];a(e.playbackRate)}else if(t==="?"){e.playbackRate=1;a(e.playbackRate)}else if(t==="w"){const e=dq(".video-toolbar .ops .watchlater,.more-ops-list .ops-watch-later");if(e!==null){e.click()}}}})}}})(); |