mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
1 line
11 KiB
JavaScript
1 line
11 KiB
JavaScript
(()=>{return(t,i)=>{const e=(t,i)=>{return t.data("events")[i][0].handler};const s=t=>{let i=0;let e=0;while(t&&!isNaN(t.offsetLeft)&&!isNaN(t.offsetTop)){i+=t.offsetLeft-t.scrollLeft;e+=t.offsetTop-t.scrollTop;t=t.offsetParent}return{x:i,y:e}};const o=(t,i=1)=>{const e=t.toString();const s=e.indexOf(".");if(s!==-1){if(e.length-s>i+1){return e.substring(0,s+i+1)}else{return e}}else{return e+".0"}};const n=t=>{t=Math.abs(t);const i=Math.floor(t/3600);const e=Math.floor((t-i*3600)/60);const s=t-i*3600-e*60;let n=o(s)+"秒";if(e>0){n=e+"分"+n}if(i>0){n=i+"时"+n}return n};const l=t=>{t=Math.abs(t);const i=Math.floor(t/3600);const e=Math.floor((t-i*3600)/60);const s=t-i*3600-e*60;let n=(s<10?"0":"")+o(s);n=(e<10?"0":"")+e+":"+n;n=(i<10?"0":"")+i+":"+n;return n};class a{constructor(t){this.action=new c(t);this.onTouchStart=null;this.onTouchEnd=null;this._direction=null;t.addEventListener("touchstart",t=>{this._xDown=t.touches[0].clientX;this._yDown=t.touches[0].clientY;if(this.onTouchStart){this.onTouchStart(t)}});t.addEventListener("touchmove",i=>{if(!this._xDown||!this._yDown){return}const e=i.touches[0].clientX;const o=i.touches[0].clientY;const n=s(t);const l={x:(i.touches[0].pageX-n.x)/t.clientWidth,y:(i.touches[0].pageY-n.y)/t.clientHeight,width:t.clientWidth,height:t.clientHeight};const a=this._xDown-e;const c=this._yDown-o;if(!this._direction){let t="";if(Math.abs(a)>Math.abs(c)){t="horizontal"}else{t="vertical"}this._direction=t;i.preventDefault()}else{if(this._direction==="vertical"){this.action.startAction(this._direction,c,l)}else if(this._direction==="horizontal"){this.action.startAction(this._direction,-a,l)}i.preventDefault()}});t.addEventListener("touchend",t=>{this._xDown=null;this._yDown=null;this._direction=null;if(this.onTouchEnd){this.onTouchEnd(t)}})}}class c{constructor(t){this.lowSpeedForward=null;this.lowSpeedBackward=null;this.mediumSpeedForward=null;this.mediumSpeedBackward=null;this.highSpeedForward=null;this.highSpeedBackward=null;this.lowVolumeUp=null;this.lowVolumeDown=null;this.mediumVolumeUp=null;this.mediumVolumeDown=null;this.highVolumeUp=null;this.highVolumeDown=null;this.speedCancel=null;this.volumeCancel=null;this.minSwipeDistance=20;this.onActionStart=null;this.onActionEnd=null;this._element=t;this._touchStart=false;this._startPosition=null;this._lastAction=null;t.addEventListener("touchstart",t=>{this._touchStart=true});t.addEventListener("touchend",t=>{this._startPosition=null;this.onActionEnd&&this.onActionEnd(this._lastAction);this._lastAction=null})}startAction(t,i,e){if(this._touchStart){this.onActionStart&&this.onActionStart();this._startPosition=e;this._touchStart=false}if(t==="vertical"){if(Math.abs(i)<this.minSwipeDistance){this.volumeCancel&&this.volumeCancel();this._lastAction=null}else{let t=0;let s=undefined;let o=undefined;if(this._startPosition.x<1/3){t=.4;s=this.lowVolumeUp;o=this.lowVolumeDown}else if(this._startPosition.x>=1/3&&this._startPosition.x<=2/3){t=1;s=this.mediumVolumeUp;o=this.mediumVolumeDown}else{t=2;s=this.highVolumeUp;o=this.highVolumeDown}if(i>0){const o=Math.round(t*100*(i-this.minSwipeDistance)/(1.5*e.height));s&&s(o);this._lastAction={type:"volume",volume:o}}else{const s=Math.round(t*100*(i+this.minSwipeDistance)/(1.5*e.height));o&&o(s);this._lastAction={type:"volume",volume:s}}}}else if(t==="horizontal"){if(e.y<1/3&&(e.x<.1||e.x>.9)||Math.abs(i)<this.minSwipeDistance){this.speedCancel&&this.speedCancel();this._lastAction=null}else{let t=0;let e=undefined;let s=undefined;if(this._startPosition.y<1/3){t=.05;e=this.lowSpeedForward;s=this.lowSpeedBackward}else if(this._startPosition.y>=1/3&&this._startPosition.y<=2/3){t=.2;e=this.mediumSpeedForward;s=this.mediumSpeedBackward}else{t=1;e=this.highSpeedForward;s=this.highSpeedBackward}if(i>0){const s=(i-this.minSwipeDistance)*t;e&&e(s);this._lastAction={type:"playback",seconds:s}}else{const e=(i+this.minSwipeDistance)*t;s&&s(e);this._lastAction={type:"playback",seconds:e}}}}}}class r{constructor(){const t=window.location.href;const i=t.match(/av([\d]+)/);this.aid=i[1];const e=t.match(/p=([\d]+)/);this.page=e?e[1]:1;this.pagesData=null;this.cidMap={};this.cidData={};this.supportWebp=r.supportWebp;downloadText(t,t=>this.findCid(t))}findCid(t){const i=t.match(/"pages":(\[[^\0]*\]),"embedPlayer"/);if(i){this.pagesData=JSON.parse(i[1]);this.pagesData.forEach(t=>{this.cidMap[t.page]=t.cid})}}getVideoshot(t,i){if(!this.cidData[this.page]){downloadText(`https://api.bilibili.com/x/player/videoshot?aid=${this.aid}&cid=${this.cidMap[this.page]}&index=1`,e=>{this.cidData[this.page]=JSON.parse(e).data;this.getVideoshot(t,i)})}else{const e=this.cidData[this.page];const s=e.index;let o=0;for(let i=0;i<s.length-2;i++){if(t>=s[i]&&t<s[i+1]){o=i;break}}let n=e.image;if(this.supportWebp){n=n.map(t=>t.replace(".jpg",".jpg@.webp"))}const l=parseInt(e.pv_x_len)||10;const a=parseInt(e.pv_y_len)||10;const c=parseInt(e.pv_x_size)||160;const r=parseInt(e.pv_y_size)||90;const h=-(o%100%l)*c;const d=-Math.floor(o%100/a)*r;i({width:c,height:r,backgroundImage:`url(${n[Math.floor(o/100)]})`,backgroundPosition:`${h}px ${d}px`})}}static get supportWebp(){try{const t=document.createElement("canvas");if(t.getContext&&t.getContext("2d"))try{return t.toDataURL("image/webp").indexOf("data:image/webp")===0}catch(t){return false}else return false}catch(t){return false}}}SpinQuery.any(()=>$(".bilibili-player-video-web-fullscreen"),t=>{if(!t.hasClass("bilibili-player-video-btn")&&$(".bilibili-player-video-btn-fullscreen").data("events")){const i=e($(".bilibili-player-video-btn-fullscreen"),"click");t.detach().insertAfter(".bilibili-player-video-btn-widescreen").addClass("bilibili-player-video-btn").on("click",i)}});SpinQuery.any(()=>$(".bilibili-player-iconfont,.bilibili-player-video-quality-menu"),t=>t.unbind("click"));new SpinQuery(()=>$(".bilibili-player-video"),t=>t.length>0&&$("video").length>0&&$("video").prop("duration"),t=>{if($(".touch-video-box").length===0){$(".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 i=$("video");const e=i.prop("duration");const s=new a(t.get(0));const c=document.getElementsByClassName("touch-video-info")[0];const h=document.getElementsByClassName("touch-video-box")[0];let d=Math.round(i.prop("volume")*100);const u=t=>{t/=100;if(t<0){t=0}else if(t>1){t=1}i.prop("volume",t);$(".bilibili-player-video-volume-num").text(Math.round(t*100));$(".bui-thumb").css("transform",`translateY(-${48*t}px)`);$(".bui-track-vertical .bui-bar").css("transform",`scaleY(${t})`);if(t===0){$(".bilibili-player-video-btn-volume").addClass(".video-state-volume-min");$(".bilibili-player-video-btn-volume").removeClass(".video-state-volume-max");i.prop("muted",true)}else if(t===1){$(".bilibili-player-video-btn-volume").removeClass(".video-state-volume-min");$(".bilibili-player-video-btn-volume").addClass(".video-state-volume-max");i.prop("muted",false)}else{$(".bilibili-player-video-btn-volume").removeClass(".video-state-volume-min");$(".bilibili-player-video-btn-volume").removeClass(".video-state-volume-max");i.prop("muted",false)}$(".bpui-slider-progress").css("height",t*100+"%");$(".bpui-slider-handle").css("bottom",(35+t*230)/3+"%");if(t===0){$(".icon-24soundoff").show();$(".icon-24soundlarge").hide();$(".icon-24soundsmall").hide()}else if(t>=.5){$(".icon-24soundoff").hide();$(".icon-24soundlarge").show();$(".icon-24soundsmall").hide()}else{$(".icon-24soundoff").hide();$(".icon-24soundlarge").hide();$(".icon-24soundsmall").show()}};s.action.onActionStart=(()=>{h.style.transform="rotateY(0deg)";c.innerHTML="";d=Math.round(i.prop("volume")*100)});const p=new r;const m=t=>{return s=>{const a=i.prop("currentTime");let r=a+s;let h=o(100*r/e);let d=s;if(r>e){r=e;h=100;d=e-a}else if(r<0){r=0;h=0;d=a}const u=`${l(a)} →<br/>${l(r)} (${h}%)`;const m=`\n <div class='touch-row'>\n <div class='touch-row-item'>\n <span class='touch-speed'>${t}速</span>\n </div>\n <div class='touch-row-item-wide'>\n <span class='touch-info'>进度: ${s>0?"+":"-"}${n(d)}</span>\n </div>\n </div>\n <div class='touch-row'>\n <div class='videoshot-wrapper touch-row-item'>\n <div class='videoshot'></div>\n </div>\n <div class='touch-row-item-wide'>\n <span class='touch-result'>${u}</span>\n </div>\n </div>\n `;c.innerHTML=m;p.getVideoshot(r,t=>$(".videoshot").css(t));$(".touch-progress").css("transform",`scaleX(${h/100})`)}};s.action.lowSpeedBackward=m("低");s.action.lowSpeedForward=m("低");s.action.mediumSpeedBackward=m("中");s.action.mediumSpeedForward=m("中");s.action.highSpeedBackward=m("高");s.action.highSpeedForward=m("高");const v=t=>{return i=>{let e=d+i;let s=Math.abs(i);if(e>100){e=100;s=100-d}else if(e<0){e=0;s=d}const o=`${d} → ${e}`;u(e);const n=`\n <div class='touch-row'>\n <div class='touch-row-item'>\n <span class='touch-speed'>${t}速</span>\n </div>\n <div class='touch-row-item-wide'>\n <span class='touch-info'>音量: ${i>0?"+":"-"}${s}</span>\n </div>\n </div>\n <div class='touch-row'>\n <div class='touch-row-item'>\n <span class='touch-result'>${o}</span>\n </div>\n </div>\n `;c.innerHTML=n;$(".touch-progress").css("transform",`scaleX(${e/100})`)}};s.action.lowVolumeUp=v("低");s.action.lowVolumeDown=v("低");s.action.mediumVolumeUp=v("中");s.action.mediumVolumeDown=v("中");s.action.highVolumeUp=v("高");s.action.highVolumeDown=v("高");s.action.speedCancel=(()=>{c.innerHTML=`松开手指,取消进退`;$(".touch-progress").css("transform","scaleX(0)")});s.action.volumeCancel=(()=>{c.innerHTML=`松开手指,取消调整`;$(".touch-progress").css("transform","scaleX(0)");u(d)});s.action.onActionEnd=(t=>{h.style.transform="rotateY(90deg)";c.innerHTML="";if(t){if(t.type==="playback"){let s=i.prop("currentTime");s+=t.seconds;if(s<0){s=0}else if(s>e){s=e}i.prop("currentTime",s)}}})}}).start();i.applyStyle("touchPlayerStyle","bilibili-touch-video-player")}})(); |