mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
1 line
10 KiB
JavaScript
1 line
10 KiB
JavaScript
(()=>{return(t,i)=>{const e=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 s=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 o=fixed(s)+"秒";if(e>0){o=e+"分"+o}if(i>0){o=i+"时"+o}return o};const o=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 o=(s<10?"0":"")+fixed(s);o=(e<10?"0":"")+e+":"+o;o=(i<10?"0":"")+i+":"+o;return o};class n{constructor(t){this.action=new l(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 s=i.touches[0].clientX;const o=i.touches[0].clientY;const n=e(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-s;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 l{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(t);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 a{constructor(){this.aid=unsafeWindow.aid;this.cid=unsafeWindow.cid;this.cidData=null;this.supportWebp=a.supportWebp}getVideoshot(t,i){if(!(this.aid&&this.cid)){return}if(!this.cidData){Ajax.getText(`https://api.bilibili.com/x/player/videoshot?aid=${this.aid}&cid=${this.cid}&index=1`).then(e=>{this.cidData=JSON.parse(e).data;this.getVideoshot(t,i)})}else{const e=this.cidData;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 d=-(o%100%l)*c;const h=-Math.floor(o%100/a)*r;i({width:c,height:r,backgroundImage:`url(${n[Math.floor(o/100)]})`,backgroundPosition:`${d}px ${h}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}}}function c(t){t.unbind("click")}function r(i){if($(".touch-video-box").length!==0){return}$(".bilibili-player-video-subtitle").before(`\n <div class='touch-video-box-wrapper'>\n <div class='touch-video-box adjust-closed'>\n <div class='touch-video-info'></div>\n <div class='touch-progress'></div>\n </div>\n </div>`);const e=$("video");const l=e.prop("duration");const c=new n(i.get(0));const r=document.getElementsByClassName("touch-video-info")[0];const d=document.getElementsByClassName("touch-video-box")[0];let h=Math.round(e.prop("volume")*100);const u=t=>{t/=100;if(t<0){t=0}else if(t>1){t=1}e.prop("volume",t);const i=JSON.parse(localStorage.bilibili_player_settings);i.video_status.volume=t;localStorage.bilibili_player_settings=JSON.stringify(i);$(".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");e.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");e.prop("muted",false)}else{$(".bilibili-player-video-btn-volume").removeClass("video-state-volume-min");$(".bilibili-player-video-btn-volume").removeClass("video-state-volume-max");e.prop("muted",false)}};if(t.touchVideoPlayerAnimation){d.classList.add("animation")}c.action.onActionStart=(t=>{d.classList.add("adjust-opened");r.innerHTML="";h=Math.round(e.prop("volume")*100)});const p=new a;const m=t=>{return i=>{const n=e.prop("currentTime");const a=fixed(100*n/l);let c=n+i;let d=fixed(100*c/l);let h=i;if(c>l){c=l;d=100;h=l-n}else if(c<0){c=0;d=0;h=n}const u=`${o(n)} (${a}%)<br>👇<br>${o(c)} (${d}%)`;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'>进度: ${i>0?"+":"-"}${s(h)}</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 `;r.innerHTML=m;p.getVideoshot(c,t=>$(".videoshot").css(t));$(".touch-progress").css("transform",`scaleX(${d/100})`)}};c.action.lowSpeedBackward=m("低");c.action.lowSpeedForward=m("低");c.action.mediumSpeedBackward=m("中");c.action.mediumSpeedForward=m("中");c.action.highSpeedBackward=m("高");c.action.highSpeedForward=m("高");const v=t=>{return i=>{let e=h+i;let s=Math.abs(i);if(e>100){e=100;s=100-h}else if(e<0){e=0;s=h}const o=`${h} 👉 ${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 `;r.innerHTML=n;$(".touch-progress").css("transform",`scaleX(${e/100})`)}};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=(()=>{r.innerHTML=`松开手指,取消进退`;$(".touch-progress").css("transform","scaleX(0)")});c.action.volumeCancel=(()=>{r.innerHTML=`松开手指,取消调整`;$(".touch-progress").css("transform","scaleX(0)");u(h)});if(!unsafeWindow.TOUCH_PLAYER_DEBUG){c.action.onActionEnd=(t=>{r.innerHTML="";if(t){if(t.type==="playback"){let i=e.prop("currentTime");i+=t.seconds;if(i<0){i=0}else if(i>l){i=l}e.prop("currentTime",i)}}d.classList.remove("adjust-opened")})}}function d(t){if(!t.hasClass("disable-original-hover")){t.addClass("disable-original-hover");const i=unsafeWindow.$(".bilibili-player-video");const e="touch-video-control-show";const s=i.data("events").click[0].handler;const o=new DoubleClickEvent(t=>s(t),()=>t.toggleClass(e));i.unbind("click");o.bind(i[0])}}const h=()=>{SpinQuery.any(()=>$(".bilibili-player-iconfont,.bilibili-player-video-quality-menu"),c);SpinQuery.condition(()=>$(".bilibili-player-video"),t=>t.length>0&&$("video").length>0&&$("video").prop("duration"),r);if(t.touchVideoPlayerDoubleTapControl){new SpinQuery(()=>$(".bilibili-player-area"),t=>t.length>0&&unsafeWindow.$&&unsafeWindow.$(".bilibili-player-video").data("events"),d).start()}};if(Observer.videoChange){Observer.videoChange(h)}else{Observer.childList("#bofqi",()=>h())}i.applyStyle("touchPlayerStyle")}})(); |