Bilibili-Evolved/min/default-player-mode.min.js
2021-08-28 20:41:32 +08:00

1 line
1.8 KiB
JavaScript

(()=>(e,t)=>{if(typeof isEmbeddedPlayer!=="undefined"&&isEmbeddedPlayer()){return}const n=[{name:"常规",action:()=>{}},{name:"宽屏",action:async()=>{const{playerAgent:e}=await t.importAsync("player-agent");console.log(e);await e.widescreen()}},{name:"网页全屏",action:()=>{document.querySelector(".bilibili-player-video-web-fullscreen").click()}},{name:"全屏",action:async()=>{const e=await SpinQuery.condition((()=>document.querySelector(".bilibili-player-video video")),(e=>e!==null&&e.readyState===4&&document.readyState==="complete"&&document.hasFocus()));if(e===null){console.warn("[默认播放器模式] 未能应用全屏模式, 等待超时.");return}document.querySelector(".bilibili-player-video-btn-fullscreen").click()}}];let i=()=>{};let a=()=>{};async function o(){const{playerAgent:n}=await t.importAsync("player-agent");if(e.autoLightOff){await SpinQuery.unsafeJquery();const e=await n.query.control.buttons.settings();if(!e){return}e.mouseover().mouseout();const t=async e=>{const t=await SpinQuery.select(".bilibili-player-video-btn-setting-right-others-content-lightoff .bui-checkbox-input, squirtle-single-setting-other-choice squirtle-lightoff");t.checked=e;raiseEvent(t,"change")};i=()=>t(true);a=()=>t(false)}}async function l(){await o();const{playerReady:l}=await t.importAsync("player-ready");const{playerAgent:r}=await t.importAsync("player-agent");await l();const c=await r.query.video.element();if(!c){return}const s=n.find((t=>t.name===e.defaultPlayerMode));const y=()=>{if(s&&$("#bilibiliPlayer[class*=mode-]").length===0){s.action()}};const d=_.get(JSON.parse(localStorage.getItem("bilibili_player_settings")),"video_status.autoplay",false);if(e.applyPlayerModeOnPlay&&!d){c.addEventListener("play",y,{once:true})}else{y()}if(d){i()}c.addEventListener("ended",a);c.addEventListener("pause",a);c.addEventListener("play",i)}Observer.videoChange(l)})();