mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
Fix some features for bpx player (#1992)
This commit is contained in:
parent
39f1c62495
commit
4c7b45e6ac
1
min/bpx-player-adaptor.min.js
vendored
Normal file
1
min/bpx-player-adaptor.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
(()=>(e,t)=>{const n=async()=>{const e=await SpinQuery.select(".bpx-player-container");if(!e){console.warn("[bpx player polyfill] bpxContainer not found");return}Observer.attributes(e,(()=>{const t=e.getAttribute("data-screen");document.body.classList.toggle("player-mode-webfullscreen",t==="full"||t==="web");document.body.classList.toggle("player-mode-widescreen",t==="wide")}))};const i=async()=>{const e=await SpinQuery.select((()=>unsafeWindow.ep));if(!e){console.warn("[bpx player polyfill] ep not found");return}Object.assign(unsafeWindow,{aid:e.aid.toString(),cid:e.cid.toString(),bvid:e.bvid})};const o=async()=>{if(!document.URL.startsWith("https://www.bilibili.com/bangumi/play/")){return}n();i()};return{export:{bpxPlayerPolyfill:o}}})();
|
||||
2
min/gui-settings.min.css
vendored
2
min/gui-settings.min.css
vendored
File diff suppressed because one or more lines are too long
2
min/gui-settings.min.js
vendored
2
min/gui-settings.min.js
vendored
File diff suppressed because one or more lines are too long
2
min/restore-floors.min.js
vendored
2
min/restore-floors.min.js
vendored
@ -1 +1 @@
|
||||
(()=>(t,e)=>{var o;(function(t){t[t["Default"]=1]="Default";t[t["ByTime"]=2]="ByTime";t[t["ByLikes"]=3]="ByLikes"})(o||(o={}));const i=(t,e,i=1)=>{if(e===o.ByTime){return Ajax.getJson(`https://api.bilibili.com/x/v2/reply/main?oid=${t}&type=1&mode=${e}`)}return Ajax.getJson(`https://api.bilibili.com/x/v2/reply/main?oid=${t}&type=1&mode=${e}&next=${i}`)};const n=async t=>{if(document.URL.match(/\/\/www\.bilibili\.com\/(video|bangumi)/)){return await SpinQuery.select((()=>unsafeWindow.aid))}console.error("No oid extract method for current context.",t)};const r=async t=>{const e=await n(t);if(e===undefined){return}const r=dq(t,".hot-sort.on")!==null?o.ByLikes:o.ByTime;let s=1;const a=dq(t,".paging-box .current");if(a!==null){s=parseInt(a.textContent)}const l=await i(e,r,s);if(l.code!==0){console.error("Comment API failed: ",l.message);return}const c=t=>{const e=[{id:t.rpid_str,floor:t.floor}];if(t.replies!==null){e.push(...t.replies.map((t=>({id:t.rpid_str,floor:t.floor}))))}return e};const d=_.flatMap(_.get(l,"data.replies",[]),c);const f=_.get(l,"data.top.upper");if(f){d.push(...c(f))}const u=dqa(t,".reply-wrap[data-id]");const p=u.map((t=>dq(t,".reply-wrap > .con > .info, .reply-wrap > .info")));u.forEach(((t,e)=>{const o=t.getAttribute("data-id");const i=d.find((t=>t.id===o));if(i!==undefined){const t=p[e];if(t.getAttribute("data-restore-floor")===null){t.insertAdjacentHTML("afterbegin",`<span class="floor">#${i.floor}</span>`);t.setAttribute("data-restore-floor",i.floor.toString())}}}))};const s=t=>{const e="comment-loading";if(Array.prototype.some.call(t.children,(t=>t.classList.contains(e)))){const o=Observer.childList(t,(i=>{if(i.some((t=>{Array.prototype.some.call(t.removedNodes,(t=>t.nodeType===Node.ELEMENT_NODE&&t.classList.contains(e)))}))){o.stop();s(t)}}))}else{if(t.getAttribute("data-restore-floor")===null){t.setAttribute("data-restore-floor","true");const e=dq(t,".comment-list");Observer.childList(e,_.debounce((e=>{console.log(e);r(t)}),100))}}};const a=["//www.bilibili.com/video","//www.bilibili.com/bangumi"];if(a.some((t=>document.URL.includes(t)))){fullyLoaded((()=>{const t=_.debounce((()=>dqa(".bb-comment").forEach((t=>s(t)))),200);Observer.childListSubtree(document.body,t)}))}})();
|
||||
(()=>(t,e)=>{var o;(function(t){t[t["Default"]=1]="Default";t[t["ByTime"]=2]="ByTime";t[t["ByLikes"]=3]="ByLikes"})(o||(o={}));const i=(t,e,i=1)=>{if(e===o.ByTime){return Ajax.getJson(`https://api.bilibili.com/x/v2/reply/main?oid=${t}&type=1&mode=${e}`)}return Ajax.getJson(`https://api.bilibili.com/x/v2/reply/main?oid=${t}&type=1&mode=${e}&next=${i}`)};const r=async t=>{if(document.URL.match(/\/\/www\.bilibili\.com\/(video|bangumi)/)){return await SpinQuery.select((()=>unsafeWindow.aid))}console.error("No oid extract method for current context.",t)};const n=async t=>{const e=await r(t);if(!e){return}const n=dq(t,".hot-sort.on")!==null?o.ByLikes:o.ByTime;let s=1;const a=dq(t,".paging-box .current");if(a!==null){s=parseInt(a.textContent)}const l=await i(e,n,s);if(l.code!==0){console.error("Comment API failed: ",l.message);return}const c=t=>{const e=[{id:t.rpid_str,floor:t.floor}];if(t.replies!==null){e.push(...t.replies.map((t=>({id:t.rpid_str,floor:t.floor}))))}return e};const d=_.flatMap(_.get(l,"data.replies",[]),c);const f=_.get(l,"data.top.upper");if(f){d.push(...c(f))}const p=dqa(t,".reply-wrap[data-id]");const u=p.map((t=>dq(t,".reply-wrap > .con > .info, .reply-wrap > .info")));p.forEach(((t,e)=>{const o=t.getAttribute("data-id");const i=d.find((t=>t.id===o));if(i!==undefined){const t=u[e];if(t.getAttribute("data-restore-floor")===null){t.insertAdjacentHTML("afterbegin",`<span class="floor">#${i.floor}</span>`);t.setAttribute("data-restore-floor",i.floor.toString())}}}))};const s=t=>{const e="comment-loading";if(Array.prototype.some.call(t.children,(t=>t.classList.contains(e)))){const o=Observer.childList(t,(i=>{if(i.some((t=>{Array.prototype.some.call(t.removedNodes,(t=>t.nodeType===Node.ELEMENT_NODE&&t.classList.contains(e)))}))){o.stop();s(t)}}))}else{if(t.getAttribute("data-restore-floor")===null){t.setAttribute("data-restore-floor","true");const e=dq(t,".comment-list");Observer.childList(e,_.debounce((e=>{console.log(e);n(t)}),100))}}};const a=["//www.bilibili.com/video","//www.bilibili.com/bangumi"];if(a.some((t=>document.URL.includes(t)))){fullyLoaded((()=>{const t=_.debounce((()=>dqa(".bb-comment").forEach((t=>s(t)))),200);Observer.childListSubtree(document.body,t)}))}})();
|
||||
@ -108,13 +108,13 @@ export class Observer {
|
||||
})
|
||||
cidHooked = true
|
||||
}
|
||||
// callback();
|
||||
const videoContainer = await SpinQuery.select('.bilibili-player-video video')
|
||||
if (videoContainer) {
|
||||
Observer.childList(videoContainer, callback)
|
||||
} else {
|
||||
callback()
|
||||
}
|
||||
callback()
|
||||
// const videoContainer = await SpinQuery.select('.bilibili-player-video video')
|
||||
// if (videoContainer) {
|
||||
// Observer.childList(videoContainer, callback)
|
||||
// } else {
|
||||
// callback()
|
||||
// }
|
||||
videoChangeCallbacks.push(callback)
|
||||
}
|
||||
}
|
||||
|
||||
37
src/utils/bpx-player-adaptor/bpx-player-adaptor.ts
Normal file
37
src/utils/bpx-player-adaptor/bpx-player-adaptor.ts
Normal file
@ -0,0 +1,37 @@
|
||||
|
||||
const playerModePolyfill = async () => {
|
||||
const bpxContainer = await SpinQuery.select('.bpx-player-container') as HTMLElement
|
||||
if (!bpxContainer) {
|
||||
console.warn('[bpx player polyfill] bpxContainer not found')
|
||||
return
|
||||
}
|
||||
Observer.attributes(bpxContainer, () => {
|
||||
const dataScreen = bpxContainer.getAttribute('data-screen')
|
||||
document.body.classList.toggle('player-mode-webfullscreen', dataScreen === 'full' || dataScreen === 'web')
|
||||
document.body.classList.toggle('player-mode-widescreen', dataScreen === 'wide')
|
||||
})
|
||||
}
|
||||
const idPolyfill = async () => {
|
||||
const ep = await SpinQuery.select(() => unsafeWindow.ep)
|
||||
if (!ep) {
|
||||
console.warn('[bpx player polyfill] ep not found')
|
||||
return
|
||||
}
|
||||
Object.assign(unsafeWindow, {
|
||||
aid: ep.aid.toString(),
|
||||
cid: ep.cid.toString(),
|
||||
bvid: ep.bvid,
|
||||
})
|
||||
}
|
||||
export const bpxPlayerPolyfill = async () => {
|
||||
if (!document.URL.startsWith('https://www.bilibili.com/bangumi/play/')) {
|
||||
return
|
||||
}
|
||||
playerModePolyfill()
|
||||
idPolyfill()
|
||||
}
|
||||
export default {
|
||||
export: {
|
||||
bpxPlayerPolyfill,
|
||||
}
|
||||
}
|
||||
@ -173,6 +173,9 @@ function setDisplayNames () {
|
||||
}
|
||||
|
||||
(async () => {
|
||||
import('../bpx-player-adaptor/bpx-player-adaptor').then(({ bpxPlayerPolyfill }) => {
|
||||
bpxPlayerPolyfill()
|
||||
})
|
||||
resources.applyStyle('guiSettingsStyle')
|
||||
// resources.applyStyle('scrollbarStyle')
|
||||
resources.applyImportantStyle('iconsStyle')
|
||||
|
||||
@ -755,6 +755,7 @@ li.category.folded i.icon-arrow {
|
||||
|
||||
/* Fix bangumi and live player z-index */
|
||||
.player-mode-webfullscreen .player-module,
|
||||
.player-mode-webfullscreen .player-module .player-container,
|
||||
.player-full-win .app-content,
|
||||
.player-full-win .live-room-app .app-content {
|
||||
z-index: 100000 !important;
|
||||
|
||||
@ -17,7 +17,7 @@ const getOid = async (commentContainer: HTMLElement) => {
|
||||
}
|
||||
const restore = async (commentContainer: HTMLElement) => {
|
||||
const oid = await getOid(commentContainer)
|
||||
if (oid === undefined) {
|
||||
if (!oid) {
|
||||
return
|
||||
}
|
||||
const mode = dq(commentContainer, '.hot-sort.on') !== null ? CommentSortOrder.ByLikes : CommentSortOrder.ByTime
|
||||
|
||||
Loading…
Reference in New Issue
Block a user