mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
1 line
7.9 KiB
JavaScript
1 line
7.9 KiB
JavaScript
(()=>(i,t)=>{const o=i=>{let t=0,o=0;for(;i&&!isNaN(i.offsetLeft)&&!isNaN(i.offsetTop);)t+=i.offsetLeft-i.scrollLeft,o+=i.offsetTop-i.scrollTop,i=i.offsetParent;return{x:t,y:o}},e=(i,t=1)=>{const o=i.toString(),e=o.indexOf(".");return-1!==e?o.length-e>t+1?o.substring(0,e+t+1):o:o+".0"},s=i=>{i=Math.abs(i);const t=Math.floor(i/3600),o=Math.floor((i-3600*t)/60);let s=e(i-3600*t-60*o)+"秒";return o>0&&(s=o+"分"+s),t>0&&(s=t+"小时"+s),s},n=i=>{i=Math.abs(i);const t=Math.floor(i/3600),o=Math.floor((i-3600*t)/60),s=i-3600*t-60*o;let n=(s<10?"0":"")+e(s);return n=(o<10?"0":"")+o+":"+n,n=(t<10?"0":"")+t+":"+n};class l{constructor(i){this.lowSpeedForward=void 0,this.lowSpeedBackward=void 0,this.mediumSpeedForward=void 0,this.mediumSpeedBackward=void 0,this.highSpeedForward=void 0,this.highSpeedBackward=void 0,this.lowVolumeUp=void 0,this.lowVolumeDown=void 0,this.mediumVolumeUp=void 0,this.mediumVolumeDown=void 0,this.highVolumeUp=void 0,this.highVolumeDown=void 0,this.speedCancel=void 0,this.volumeCancel=void 0,this.minSwipeDistance=20,this.onActionStart=void 0,this.onActionEnd=void 0,this._element=i,this._touchStart=!1,this._startPosition=null,this._lastAction=null,i.addEventListener("touchstart",()=>{this._touchStart=!0}),i.addEventListener("touchend",()=>{this._startPosition=null,this.onActionEnd&&this.onActionEnd(this._lastAction),this._lastAction=null})}startAction(i,t,o){if(this._touchStart&&(this.onActionStart&&this.onActionStart(),this._startPosition=o,this._touchStart=!1),"vertical"===i)if(Math.abs(t)<this.minSwipeDistance)this.volumeCancel&&this.volumeCancel(),this._lastAction=null;else{let i=0,e=void 0,s=void 0;if(this._startPosition.x<1/3?(i=.4,e=this.lowVolumeUp,s=this.lowVolumeDown):this._startPosition.x>=1/3&&this._startPosition.x<=2/3?(i=1,e=this.mediumVolumeUp,s=this.mediumVolumeDown):(i=2,e=this.highVolumeUp,s=this.highVolumeDown),t>0){const s=Math.round(100*i*(t-this.minSwipeDistance)/(1.5*o.height));e&&e(s),this._lastAction={type:"volume",volume:s}}else{const e=Math.round(100*i*(t+this.minSwipeDistance)/(1.5*o.height));s&&s(e),this._lastAction={type:"volume",volume:e}}}else if("horizontal"===i)if(o.y<1/3&&(o.x<.1||o.x>.9)||Math.abs(t)<this.minSwipeDistance)this.speedCancel&&this.speedCancel(),this._lastAction=null;else{let i=0,o=void 0,e=void 0;if(this._startPosition.y<1/3?(i=.05,o=this.lowSpeedForward,e=this.lowSpeedBackward):this._startPosition.y>=1/3&&this._startPosition.y<=2/3?(i=.2,o=this.mediumSpeedForward,e=this.mediumSpeedBackward):(i=1,o=this.highSpeedForward,e=this.highSpeedBackward),t>0){const e=(t-this.minSwipeDistance)*i;o&&o(e),this._lastAction={type:"playback",seconds:e}}else{const o=(t+this.minSwipeDistance)*i;e&&e(o),this._lastAction={type:"playback",seconds:o}}}}}if(SpinQuery.any(()=>$(".bilibili-player-video-web-fullscreen"),i=>{if(!i.hasClass("bilibili-player-video-btn")&&$(".bilibili-player-video-btn-fullscreen").data("events")){const t=((i,t)=>i.data("events")[t][0].handler)($(".bilibili-player-video-btn-fullscreen"),"click");i.detach().insertAfter(".bilibili-player-video-btn-widescreen").addClass("bilibili-player-video-btn").on("click",t)}}),SpinQuery.any(()=>$(".bilibili-player-iconfont,.bilibili-player-video-quality-menu"),i=>i.unbind("click")),SpinQuery.count(()=>$(".bilibili-player-video,video"),2,i=>{if(0===$(".touch-video-box").length){$(".bilibili-player-video-subtitle").before("<div class='touch-video-box-wrapper'>\n <div class='touch-video-box'>\n <div class='touch-video-info'></div>\n <div class='touch-progress'></div>\n </div>\n </div>");const t=$("video"),a=t.prop("duration"),c=new class{constructor(i){this.action=new l(i),this.onTouchStart=void 0,this.onTouchEnd=void 0,this._direction=null,i.addEventListener("touchstart",i=>{this._xDown=i.touches[0].clientX,this._yDown=i.touches[0].clientY,this.onTouchStart&&this.onTouchStart(i)}),i.addEventListener("touchmove",t=>{if(!this._xDown||!this._yDown)return;const e=t.touches[0].clientX,s=t.touches[0].clientY,n=o(i),l={x:(t.touches[0].pageX-n.x)/i.clientWidth,y:(t.touches[0].pageY-n.y)/i.clientHeight,width:i.clientWidth,height:i.clientHeight},a=this._xDown-e,c=this._yDown-s;if(this._direction)"vertical"===this._direction?this.action.startAction(this._direction,c,l):"horizontal"===this._direction&&this.action.startAction(this._direction,-a,l),t.preventDefault();else{let i="";i=Math.abs(a)>Math.abs(c)?"horizontal":"vertical",this._direction=i,t.preventDefault()}}),i.addEventListener("touchend",i=>{this._xDown=null,this._yDown=null,this._direction=null,this.onTouchEnd&&this.onTouchEnd(i)})}}(i.get(0)),h=document.getElementsByClassName("touch-video-info")[0],d=document.getElementsByClassName("touch-video-box")[0];let r=Math.round(100*t.prop("volume"));const u=i=>{(i/=100)<0?i=0:i>1&&(i=1),t.prop("volume",i),$(".bilibili-player-video-volume-num").text(Math.round(100*i)),$(".bui-thumb").css("transform",`translateY(-${48*i}px)`),$(".bui-track-vertical .bui-bar").css("transform",`scaleY(${i})`),0===i?($(".bilibili-player-video-btn-volume").addClass(".video-state-volume-min"),$(".bilibili-player-video-btn-volume").removeClass(".video-state-volume-max"),t.prop("muted",!0)):1===i?($(".bilibili-player-video-btn-volume").removeClass(".video-state-volume-min"),$(".bilibili-player-video-btn-volume").addClass(".video-state-volume-max"),t.prop("muted",!1)):($(".bilibili-player-video-btn-volume").removeClass(".video-state-volume-min"),$(".bilibili-player-video-btn-volume").removeClass(".video-state-volume-max"),t.prop("muted",!1)),$(".bpui-slider-progress").css("height",100*i+"%"),$(".bpui-slider-handle").css("bottom",(35+230*i)/3+"%"),0===i?($(".icon-24soundoff").show(),$(".icon-24soundlarge").hide(),$(".icon-24soundsmall").hide()):i>=.5?($(".icon-24soundoff").hide(),$(".icon-24soundlarge").show(),$(".icon-24soundsmall").hide()):($(".icon-24soundoff").hide(),$(".icon-24soundlarge").hide(),$(".icon-24soundsmall").show())};c.action.onActionStart=(()=>{d.style.display="flex",h.innerHTML="",r=Math.round(100*t.prop("volume"))});const p=i=>o=>{const l=t.prop("currentTime");let c=`<div class='touch-row'><span class='touch-speed'>${i}速</span><span class='touch-info'>进度: ${o>0?"+":"-"}`;const d="</span></div><div class='touch-row'><div class='videoshot'></div><span class='touch-result'>",r=l+o;let u="0%";r>a?(u="100%",c+=`${s(a-l)}${d}${n(l)} → ${n(a)} (${u})`):r<0?(u="0%",c+=`${s(l)}${d}${n(l)} → ${n(0)} (${u})`):(u=e(100*r/a)+"%",c+=`${s(o)}${d}${n(l)} → ${n(r)} (${u})`),h.innerHTML=c+"</span></div><div class='touch-progress'></div>",$(".touch-progress").css("width",u)};c.action.lowSpeedBackward=p("低"),c.action.lowSpeedForward=p("低"),c.action.mediumSpeedBackward=p("中"),c.action.mediumSpeedForward=p("中"),c.action.highSpeedBackward=p("高"),c.action.highSpeedForward=p("高");const v=i=>t=>{let o=`<div class='touch-row'><span class='touch-speed'>${i}速</span><span class='touch-info'>音量: ${t>0?"+":"-"}`;const e="</span></div><div class='touch-row'><span class='touch-result'>",s=r+t;s>100?(o+=`${100-r}${e}${r} → 100`,u(100),$(".touch-progress").css("width","100%")):s<0?(o+=`${r}${e}${r} → 0`,u(0),$(".touch-progress").css("width","0%")):(o+=`${Math.abs(t)}${e}${r} → ${s}`,u(s),$(".touch-progress").css("width",s+"%")),h.innerHTML=o+"</span></div><div class='touch-progress'></div>"};c.action.lowVolumeUp=v("低"),c.action.lowVolumeDown=v("低"),c.action.mediumVolumeUp=v("中"),c.action.mediumVolumeDown=v("中"),c.action.highVolumeUp=v("高"),c.action.highVolumeDown=v("高"),c.action.speedCancel=(()=>{h.innerHTML="松开手指,取消进退"}),c.action.volumeCancel=(()=>{h.innerHTML="松开手指,取消调整",u(r)}),c.action.onActionEnd=(i=>{if(d.style.display="none",h.innerHTML="",i&&"playback"===i.type){let o=t.prop("currentTime");(o+=i.seconds)<0?o=0:o>a&&(o=a),t.prop("currentTime",o)}})}}),0===$("#bilibili-touch-video-player").length){const i=t.getStyle("touchPlayerStyle","bilibili-touch-video-player");$("body").after(i)}})(); |