Bilibili-Evolved/min/scroll-out-player.min.js
2021-04-28 15:10:34 +08:00

1 line
2.3 KiB
JavaScript

(()=>(e,t)=>{let n;let i="视频中间";var o;(function(e){e["TOP"]="视频顶部";e["MID"]="视频中间";e["BOT"]="视频底部"})(o||(o={}));function l(e,t){switch(e){case o.TOP:return t===null||t===void 0?void 0:t.top;case o.MID:return(t===null||t===void 0?void 0:t.top)+(t===null||t===void 0?void 0:t.height)/2;case o.BOT:return(t===null||t===void 0?void 0:t.top)+(t===null||t===void 0?void 0:t.height);default:return 0}}let r=function(e,t){var i;const o=(i=n)===null||i===void 0?void 0:i.getBoundingClientRect();if((o===null||o===void 0?void 0:o.top)&&o.height){let n=l(e,o);if(n<=0){t?t():"";window.addEventListener("scroll",c,{passive:true});window.removeEventListener("scroll",v)}}};let s=function(e,t){var i;const o=(i=n)===null||i===void 0?void 0:i.getBoundingClientRect();if((o===null||o===void 0?void 0:o.top)&&o.height){let n=l(e,o);if(n>=0){t?t():"";window.addEventListener("scroll",v,{passive:true});window.removeEventListener("scroll",c)}}};let u=()=>{};let a=()=>{};async function d(){await SpinQuery.unsafeJquery();const e=await SpinQuery.any((()=>unsafeWindow.$(".bilibili-player-video-btn-setting")));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");t.checked=e;raiseEvent(t,"change")};u=()=>t(true);a=()=>t(false)}function v(){r(i,(()=>{if(e.scrollOutPlayerAutoPause&&!n.paused)n.pause();if(e.scrollOutPlayerAutoLightOn&&e.autoLightOff&&!e.scrollOutPlayerAutoPause)a()}))}function c(){s(i,(()=>{if(e.scrollOutPlayerAutoPause&&n.paused)n.play();if(e.scrollOutPlayerAutoLightOn&&e.autoLightOff&&!e.scrollOutPlayerAutoPause&&!n.paused)u()}))}function f(){window.addEventListener("scroll",v,{passive:true})}function p(){window.removeEventListener("scroll",v)}function w(){Observer.videoChange((async()=>{n.addEventListener("play",f);n.addEventListener("pause",p);n.addEventListener("ended",p)}))}async function y(){await d();addSettingsListener("triggerPlayerOutPlace",(e=>i=e));n=dq(".bilibili-player-video video");w()}y();return{reload:()=>{window.addEventListener("scroll",v);w()},unload:()=>{Observer.videoChange((async()=>{n.removeEventListener("play",f);n.removeEventListener("pause",p);n.removeEventListener("ended",p)}));window.removeEventListener("scroll",v);window.removeEventListener("scroll",c)}}})();