Fix video change listener

This commit is contained in:
the1812 2019-02-07 19:55:55 +08:00
parent 264a941005
commit e8ac722ad6
23 changed files with 114 additions and 50 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
// ==UserScript==
// @name Bilibili Evolved (Preview)
// @version 1.7.3
// @version 1.7.4
// @description Bilibili Evolved 的预览版, 可以抢先体验新功能.
// @author Grant Howard, Coulomb-G
// @copyright 2019, Grant Howrad (https://github.com/the1812) & Coulomb-G (https://github.com/Coulomb-G)
@ -949,6 +949,11 @@
attributes: true,
});
}
static async videoChange(callback)
{
await SpinQuery.select(() => document.querySelector("#bilibiliPlayer"));
return Observer.childList("#bofqi,#bilibiliPlayer", callback);
}
}
class SpinQuery
{

View File

@ -1,6 +1,6 @@
// ==UserScript==
// @name Bilibili Evolved
// @version 1.7.3
// @version 1.7.4
// @description 增强哔哩哔哩Web端体验: 下载视频, 封面, 弹幕; 自定义播放器的画质, 模式, 布局; 删除广告, 使用夜间模式, 修复界面瑕疵; 以及增加对触屏设备的支持等.
// @author Grant Howard, Coulomb-G
// @copyright 2019, Grant Howrad (https://github.com/the1812) & Coulomb-G (https://github.com/Coulomb-G)
@ -949,6 +949,11 @@
attributes: true,
});
}
static async videoChange(callback)
{
await SpinQuery.select(() => document.querySelector("#bilibiliPlayer"));
return Observer.childList("#bofqi,#bilibiliPlayer", callback);
}
}
class SpinQuery
{

View File

@ -1 +1 @@
(()=>{return(i,t)=>{function e(i){const t=/((\d)*:)?(\d)*:(\d)*/g;const e=i.text();const n=e.match(t);if(!n){return}const r=n[0].split(":");const o=(()=>{if(r.length===3){const[i,t,e]=r.map(i=>parseInt(i));return i*60*60+t*60+e}else if(r.length===2){const[i,t]=r.map(i=>parseInt(i));return i*60+t}else{logError(`解析历史时间发生错误: historyTime=${JSON.stringify(r)}`);return NaN}})();const s=i.parent();const l=document.querySelector("video");if(o<l.duration){l.currentTime=o;l.play();s.find(".bilibili-player-video-toast-item-jump").remove();const t=$(`<div class="bilibili-player-video-toast-item-jump">从头开始</div>`);t.appendTo(s).on("click",()=>l.currentTime=0);i.html(`<span>已跳转到上次历史记录</span><span>${n[0]}</span>`)}else{s.find(".bilibili-player-video-toast-item-close").get(0).click()}}function n(){SpinQuery.condition(()=>$(".bilibili-player-video-toast-item-text"),i=>i.text().indexOf("上次看到")!==-1,i=>e(i.filter((i,t)=>t.innerText.indexOf("上次看到")!==-1)))}Observer.childList("#bofqi",n)}})();
(()=>{return(e,i)=>{function t(e){const i=/((\d)*:)?(\d)*:(\d)*/g;const t=e.text();const n=t.match(i);if(!n){return}const r=n[0].split(":");const o=(()=>{if(r.length===3){const[e,i,t]=r.map(e=>parseInt(e));return e*60*60+i*60+t}else if(r.length===2){const[e,i]=r.map(e=>parseInt(e));return e*60+i}else{logError(`解析历史时间发生错误: historyTime=${JSON.stringify(r)}`);return NaN}})();const s=e.parent();const l=document.querySelector("video");if(o<l.duration){l.currentTime=o;l.play();s.find(".bilibili-player-video-toast-item-jump").remove();const i=$(`<div class="bilibili-player-video-toast-item-jump">从头开始</div>`);i.appendTo(s).on("click",()=>l.currentTime=0);e.html(`<span>已跳转到上次历史记录</span><span>${n[0]}</span>`)}else{s.find(".bilibili-player-video-toast-item-close").get(0).click()}}function n(){SpinQuery.condition(()=>$(".bilibili-player-video-toast-item-text"),e=>e.text().indexOf("上次看到")!==-1,e=>t(e.filter((e,i)=>i.innerText.indexOf("上次看到")!==-1)))}if(Observer.videoChange){Observer.videoChange(n)}else{Observer.childList("#bofqi",n)}}})();

View File

@ -1 +1 @@
(()=>{return(r,i)=>{Observer.childList("#bofqi",()=>{SpinQuery.count(()=>$(".bui-slider .bui-track.bui-track-video-progress,.bilibili-player-video-control-bottom"),2,r=>{if(!r.hasClass("video-control-blur-container")){r.addClass("video-control-blur-container");r.prepend(`<div class="video-control-blur-layer"></div>`)}})});i.applyStyle("blurVideoControlStyle")}})();
(()=>{return(e,r)=>{const i=()=>{SpinQuery.count(()=>$(".bui-slider .bui-track.bui-track-video-progress,.bilibili-player-video-control-bottom"),2,e=>{if(!e.hasClass("video-control-blur-container")){e.addClass("video-control-blur-container");e.prepend(`<div class="video-control-blur-layer"></div>`)}})};if(Observer.videoChange){Observer.videoChange(i)}else{Observer.childList("#bofqi",i)}r.applyStyle("blurVideoControlStyle")}})();

View File

@ -1 +1 @@
(()=>{return(e,i)=>{const n=[{name:"常规",action:()=>{}},{name:"宽屏",action:()=>{$(".bilibili-player-video-btn-widescreen").click()}},{name:"网页全屏",action:()=>{$(".bilibili-player-video-web-fullscreen").click()}}];let t=()=>{};async function l(){if(e.autoLightOff){await SpinQuery.unsafeJquery();const e=await SpinQuery.any(()=>unsafeWindow.$(".bilibili-player-video-btn-setting"));if(!e){return}e.mouseover().mouseout();t=(()=>{SpinQuery.any(()=>$(".bilibili-player-video-btn-setting-panel-others-content-lightoff .bui-checkbox-input"),e=>{const i=e[0];i.checked=true;raiseEvent(i,"change")})})}}async function a(){await l();await SpinQuery.condition(()=>$(".bilibili-player-video,.bilibili-player-video-btn-start,.bilibili-player-area"),e=>e.length===3&&$("video").length>0&&$("video").prop("duration"));const i=document.querySelector("video");if(!i){return}const a=n.find(i=>i.name===e.defaultPlayerMode);if(a.name==="全屏"){const e=await SpinQuery.unsafeJquery();const i=document.querySelector(".bilibili-player-video-btn-start");const n=()=>{const t=e(".bilibili-player-video-btn-fullscreen").data("events");if(t.click&&t.click[0]&&t.click[0].handler){const i=e(".bilibili-player-video-btn-fullscreen").data("events").click[0].handler;console.log(i);i()}i.removeEventListener("click",n)};i.addEventListener("click",n)}else{const n=()=>{if(a&&$("#bilibiliPlayer[class*=mode-]").length===0){a.action()}t();if(e.applyPlayerModeOnPlay){i.removeEventListener("play",n)}};if(e.applyPlayerModeOnPlay){i.addEventListener("play",n)}else{n()}}}Observer.childList("#bofqi",()=>a())}})();
(()=>{return(e,i)=>{const n=[{name:"常规",action:()=>{}},{name:"宽屏",action:()=>{$(".bilibili-player-video-btn-widescreen").click()}},{name:"网页全屏",action:()=>{$(".bilibili-player-video-web-fullscreen").click()}}];let l=()=>{};async function t(){if(e.autoLightOff){await SpinQuery.unsafeJquery();const e=await SpinQuery.any(()=>unsafeWindow.$(".bilibili-player-video-btn-setting"));if(!e){return}e.mouseover().mouseout();l=(()=>{SpinQuery.any(()=>$(".bilibili-player-video-btn-setting-panel-others-content-lightoff .bui-checkbox-input"),e=>{const i=e[0];i.checked=true;raiseEvent(i,"change")})})}}async function a(){await t();await SpinQuery.condition(()=>$(".bilibili-player-video,.bilibili-player-video-btn-start,.bilibili-player-area"),e=>e.length===3&&$("video").length>0&&$("video").prop("duration"));const i=document.querySelector("video");if(!i){return}const a=n.find(i=>i.name===e.defaultPlayerMode);if(a.name==="全屏"){const e=await SpinQuery.unsafeJquery();const i=document.querySelector(".bilibili-player-video-btn-start");const n=()=>{const l=e(".bilibili-player-video-btn-fullscreen").data("events");if(l.click&&l.click[0]&&l.click[0].handler){const i=e(".bilibili-player-video-btn-fullscreen").data("events").click[0].handler;console.log(i);i()}i.removeEventListener("click",n)};i.addEventListener("click",n)}else{const n=()=>{if(a&&$("#bilibiliPlayer[class*=mode-]").length===0){a.action()}l();if(e.applyPlayerModeOnPlay){i.removeEventListener("play",n)}};if(e.applyPlayerModeOnPlay){i.addEventListener("play",n)}else{n()}}}if(Observer.videoChange){Observer.videoChange(a)}else{Observer.childList("#bofqi",()=>a())}}})();

View File

@ -1 +1 @@
(()=>{return(e,a)=>{const t=[{name:"1080P60",value:116},{name:"1080P+",value:112},{name:"1080P",value:80},{name:"720P60",value:74},{name:"720P",value:64},{name:"480P",value:32},{name:"360P",value:15},{name:"自动",value:0}];async function i(){const a=await SpinQuery.any(()=>$(".bilibili-player-video-quality-menu .bui-select-list>li.bui-select-item"));if(!a){return}const i=(e,a)=>a-e;const[l]=a.toArray().map(e=>parseInt(e.getAttribute("data-value"))).sort(i);const[n]=t.filter(a=>a.name===e.defaultVideoQuality).map(e=>e.value).sort(i);const[u]=t.map(e=>e.value).filter(e=>e<=Math.min(n,l)).sort(i);console.info(`[Video Quality] availableHighestQualities=${l}`);console.info(`[Video Quality] targetQuality=${n}`);console.info(`[Video Quality] finalQuality=${u}`);const o=await SpinQuery.select(()=>document.querySelector("video"));function s(){a.each((e,a)=>{if(parseInt(a.getAttribute("data-value"))===u){a.click()}});this.removeEventListener("play",s)}o.addEventListener("play",s)}Observer.childList("#bofqi",()=>i())}})();
(()=>{return(e,a)=>{const t=[{name:"1080P60",value:116},{name:"1080P+",value:112},{name:"1080P",value:80},{name:"720P60",value:74},{name:"720P",value:64},{name:"480P",value:32},{name:"360P",value:15},{name:"自动",value:0}];async function i(){const a=await SpinQuery.any(()=>$(".bilibili-player-video-quality-menu .bui-select-list>li.bui-select-item"));if(!a){return}const i=(e,a)=>a-e;const[n]=a.toArray().map(e=>parseInt(e.getAttribute("data-value"))).sort(i);const[l]=t.filter(a=>a.name===e.defaultVideoQuality).map(e=>e.value).sort(i);const[o]=t.map(e=>e.value).filter(e=>e<=Math.min(l,n)).sort(i);console.info(`[Video Quality] availableHighestQualities=${n}`);console.info(`[Video Quality] targetQuality=${l}`);console.info(`[Video Quality] finalQuality=${o}`);const u=await SpinQuery.select(()=>document.querySelector("video"));function r(){a.each((e,a)=>{if(parseInt(a.getAttribute("data-value"))===o){a.click()}});this.removeEventListener("play",r)}u.addEventListener("play",r)}if(Observer.videoChange){Observer.videoChange(i)}else{Observer.childList("#bofqi",()=>i())}}})();

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
(()=>{return()=>{Observer.childList("#bofqi",()=>{SpinQuery.any(()=>$(".bui-collapse-header"),e=>{if(parseInt($(".bui-collapse-body").css("height"))===0&&$(".bui-collapse-arrow-text").text()==="展开"){e.click()}})})}})();
(()=>{return()=>{const e=()=>{SpinQuery.any(()=>$(".bui-collapse-header"),e=>{if(parseInt($(".bui-collapse-body").css("height"))===0&&$(".bui-collapse-arrow-text").text()==="展开"){e.click()}})};if(Observer.videoChange){Observer.videoChange(e)}else{Observer.childList("#bofqi",e)}}})();

View File

@ -1 +1 @@
(()=>{return(e,t)=>{async function c(){const e=await SpinQuery.select(()=>document.querySelector("video"));e.addEventListener("ended",async()=>{const e=await SpinQuery.select(()=>document.querySelector(".bilibili-player-electric-panel-jump"));e&&e.click()})}SpinQuery.select(()=>document.querySelector("#bofqi")).then(()=>{Observer.childList("#bofqi",()=>c())})}})();
(()=>{return(e,i)=>{async function n(){const e=await SpinQuery.select(()=>document.querySelector("video"));e.addEventListener("ended",async()=>{const e=await SpinQuery.select(()=>document.querySelector(".bilibili-player-electric-panel-jump"));e&&e.click()})}if(Observer.videoChange){Observer.videoChange(n)}else{Observer.childList("#bofqi",n)}}})();

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
(()=>{return(e,t)=>{const n=t.attributes.videoInfo.export.VideoInfo;class i{constructor(e){this.url=e;if($(".image-viewer").length===0){this.createDom()}this.viewer=$(".image-viewer-container");this.downloadImage()}createDom(){$("body").append(t.data.imageViewerDom.text);$(".image-viewer-container .close").on("click",()=>this.hide());t.applyStyle("imageViewerStyle")}downloadImage(){const e=new XMLHttpRequest;e.open("GET",this.url.replace("http:","https:"),true);e.responseType="blob";e.onload=(()=>{const t=document.title.replace("_哔哩哔哩 (゜-゜)つロ 干杯~-bilibili","").replace("_番剧_bilibili_哔哩哔哩","");const n=URL.createObjectURL(e.response);this.imageData=n;this.viewer.find(".download").attr("href",n).attr("download",t);this.viewer.find(".image").prop("src",n)});e.send()}show(){this.viewer.addClass("opened")}hide(){this.viewer.removeClass("opened")}}if($("meta[itemprop='image'],meta[property='og:image']").length>0){return{widget:{content:`\n <button\n class="gui-settings-flat-button"\n id="view-cover">\n <i class="icon-view"></i>\n <span>查看封面</span>\n </button>`,condition:async()=>{const e=await SpinQuery.select(()=>(unsafeWindow||window).aid);return Boolean(e)},success:async()=>{async function e(){const e=(unsafeWindow||window).aid;const t=new n(e);await t.fetchInfo();return t.coverUrl}let t=new i(await e());$("#view-cover").on("click",()=>{t.show()});Observer.childList("#bofqi",async()=>{t=new i(await e())})}}}}else{return{widget:{content:`\n <button\n class="gui-settings-flat-button"\n id="view-cover">\n <i class="icon-view"></i>\n <span>查看封面</span>\n </button>`,condition:async()=>{const e=await SpinQuery.select(()=>document.querySelector(".header-info-ctnr .room-cover"));return Boolean(e)},success:async()=>{const e=$(".header-info-ctnr .room-cover");const t=e.attr("href").match(/space\.bilibili\.com\/([\d]+)/);if(t&&t[1]){const e=t[1];const n=`https://api.live.bilibili.com/room/v1/Room/getRoomInfoOld?mid=${e}`;const o=await downloadText(n);const s=JSON.parse(o).data.cover;const a=new i(s);$("#view-cover").on("click",()=>{a.show()})}}}}}}})();
(()=>{return(e,t)=>{const n=t.attributes.videoInfo.export.VideoInfo;class i{constructor(e){this.url=e;if($(".image-viewer").length===0){this.createDom()}this.viewer=$(".image-viewer-container");this.downloadImage()}createDom(){$("body").append(t.data.imageViewerDom.text);$(".image-viewer-container .close").on("click",()=>this.hide());t.applyStyle("imageViewerStyle")}downloadImage(){const e=new XMLHttpRequest;e.open("GET",this.url.replace("http:","https:"),true);e.responseType="blob";e.onload=(()=>{const t=document.title.replace("_哔哩哔哩 (゜-゜)つロ 干杯~-bilibili","").replace("_番剧_bilibili_哔哩哔哩","");const n=URL.createObjectURL(e.response);this.imageData=n;this.viewer.find(".download").attr("href",n).attr("download",t);this.viewer.find(".image").prop("src",n)});e.send()}show(){this.viewer.addClass("opened")}hide(){this.viewer.removeClass("opened")}}if($("meta[itemprop='image'],meta[property='og:image']").length>0){return{widget:{content:`\n <button\n class="gui-settings-flat-button"\n id="view-cover">\n <i class="icon-view"></i>\n <span>查看封面</span>\n </button>`,condition:async()=>{const e=await SpinQuery.select(()=>(unsafeWindow||window).aid);return Boolean(e)},success:async()=>{async function e(){const e=(unsafeWindow||window).aid;const t=new n(e);await t.fetchInfo();return t.coverUrl}let t=new i(await e());$("#view-cover").on("click",()=>{t.show()});const o=async()=>{t=new i(await e())};if(Observer.videoChange){Observer.videoChange(o)}else{Observer.childList("#bofqi",o)}}}}}else{return{widget:{content:`\n <button\n class="gui-settings-flat-button"\n id="view-cover">\n <i class="icon-view"></i>\n <span>查看封面</span>\n </button>`,condition:async()=>{const e=await SpinQuery.select(()=>document.querySelector(".header-info-ctnr .room-cover"));return Boolean(e)},success:async()=>{const e=$(".header-info-ctnr .room-cover");const t=e.attr("href").match(/space\.bilibili\.com\/([\d]+)/);if(t&&t[1]){const e=t[1];const n=`https://api.live.bilibili.com/room/v1/Room/getRoomInfoOld?mid=${e}`;const o=await downloadText(n);const s=JSON.parse(o).data.cover;const a=new i(s);$("#view-cover").on("click",()=>{a.show()})}}}}}}})();

View File

@ -2,7 +2,7 @@
{
return (_, resources) =>
{
Observer.childList("#bofqi", () =>
const blur = () =>
{
SpinQuery.count(
() => $(".bui-slider .bui-track.bui-track-video-progress,.bilibili-player-video-control-bottom"),
@ -15,7 +15,13 @@
containers.prepend(`<div class="video-control-blur-layer"></div>`);
}
});
});
};
if (Observer.videoChange)
{
Observer.videoChange(blur);
}
else
{ Observer.childList("#bofqi", blur); }
resources.applyStyle("blurVideoControlStyle");
};
})();

View File

@ -577,7 +577,7 @@
}
}
function main()
const main = () =>
{
SpinQuery.any(
() => $(".bilibili-player-iconfont,.bilibili-player-video-quality-menu"),
@ -599,8 +599,12 @@
).start();
}
}
Observer.childList("#bofqi", () => main());
if (Observer.videoChange)
{
Observer.videoChange(main);
}
else
{ Observer.childList("#bofqi", () => main()); }
resources.applyStyle("touchPlayerStyle");
};
})();

View File

@ -1 +1 @@
1.7.3
1.7.4

View File

@ -54,6 +54,11 @@
it => continuePlay(it.filter((_, e) => e.innerText.indexOf("上次看到") !== -1)),
);
}
Observer.childList("#bofqi", findHistoryToast);
if (Observer.videoChange)
{
Observer.videoChange(findHistoryToast);
}
else
{ Observer.childList("#bofqi", findHistoryToast); }
};
})();

View File

@ -106,6 +106,11 @@
}
}
}
Observer.childList("#bofqi", () => main());
if (Observer.videoChange)
{
Observer.videoChange(main);
}
else
{ Observer.childList("#bofqi", () => main()); }
};
})();

View File

@ -75,6 +75,11 @@
}
video.addEventListener("play", onplay);
}
Observer.childList("#bofqi", () => applyQuality());
if (Observer.videoChange)
{
Observer.videoChange(applyQuality);
}
else
{ Observer.childList("#bofqi", () => applyQuality()); }
};
})();

View File

@ -359,7 +359,12 @@
.prependTo(list);
});
};
Observer.childList("#bofqi", loadQualities);
if (Observer.videoChange)
{
Observer.videoChange(loadQualities);
}
else
{ Observer.childList("#bofqi", loadQualities); }
const getVideoInfo = () => selectedFormat.downloadInfo().catch(error =>
{
pageData.entity.addError();

View File

@ -2,7 +2,7 @@
{
return () =>
{
Observer.childList("#bofqi", () =>
const expand = () =>
{
SpinQuery.any(
() => $(".bui-collapse-header"),
@ -15,6 +15,12 @@
}
}
);
});
};
if (Observer.videoChange)
{
Observer.videoChange(expand);
}
else
{ Observer.childList("#bofqi", expand); }
};
})();

View File

@ -11,9 +11,11 @@
jumpButton && jumpButton.click();
});
}
SpinQuery.select(() => document.querySelector("#bofqi")).then(() =>
if (Observer.videoChange)
{
Observer.childList("#bofqi", () => skipChargeList());
});
Observer.videoChange(skipChargeList);
}
else
{ Observer.childList("#bofqi", skipChargeList); }
};
})();

View File

@ -83,10 +83,16 @@
{
imageViewer.show();
});
Observer.childList("#bofqi", async () =>
const updateImage = async () =>
{
imageViewer = new ImageViewer(await getUrl());
});
};
if (Observer.videoChange)
{
Observer.videoChange(updateImage);
}
else
{ Observer.childList("#bofqi", updateImage); }
},
},
};