From 4009bf9d54f9bf26c5d44b32b7f11b1880b2dce7 Mon Sep 17 00:00:00 2001 From: the1812 Date: Fri, 31 Dec 2021 09:11:32 +0800 Subject: [PATCH 01/10] Add disableWindowScroll --- .../components/video/player/default-mode.js | 2 +- .../video/player/default-mode/index.ts | 4 ++-- src/core/utils/index.ts | 20 ++++++++++++++++++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/registry/dist/components/video/player/default-mode.js b/registry/dist/components/video/player/default-mode.js index 2d695506f..7fabea35c 100644 --- a/registry/dist/components/video/player/default-mode.js +++ b/registry/dist/components/video/player/default-mode.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["video/player/default-mode"]=t():e["video/player/default-mode"]=t()}(self,(function(){return function(){"use strict";var e={d:function(t,n){for(var o in n)e.o(n,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:n[o]})},o:function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}},t={};e.d(t,{component:function(){return s}});var n=coreApis.componentApis.video.playerAgent,o=coreApis.spinQuery,l=coreApis.utils,r=coreApis.utils.urls;let a;!function(e){e.Normal="常规",e.Wide="宽屏",e.WebFullscreen="网页全屏",e.Fullscreen="全屏"}(a||(a={}));const s={name:"defaultPlayerMode",displayName:"默认播放器模式",entry:async({settings:{options:e}})=>{if((0,l.isEmbeddedPlayer)())return;await(0,l.playerReady)();const t=new Map([[a.Normal,none],[a.Wide,()=>{n.playerAgent.widescreen()}],[a.WebFullscreen,()=>{n.playerAgent.webFullscreen()}],[a.Fullscreen,async()=>{null!==await(0,o.sq)((()=>dq(n.playerAgent.query.video.element.selector)),(e=>null!==e&&4===e.readyState&&"complete"===document.readyState&&document.hasFocus()))?n.playerAgent.fullscreen():console.warn("[默认播放器模式] 未能应用全屏模式, 等待超时.")}]]),r=await n.playerAgent.query.video.element();if(!r)return;const s=t.get(e.mode);e.applyOnPlay&&!n.playerAgent.isAutoPlay()?r.addEventListener("play",s,{once:!0}):s()},tags:[componentsTags.video],description:{"zh-CN":"控制是否使用默认播放器模式, 可以为`常规`, `宽屏`, `网页全屏`或`全屏`. 注意: 不能和其他影响定位的功能一同使用, 例如播放器定位. (相关讨论: [#483](https://github.com/the1812/Bilibili-Evolved/issues/483))","en-US":"Set the default player mode. Could be `Normal`, `Widescreen`, `Web fullscreen` or `Fullscreen`.","ja-JP":"デフォルト・プレーヤー・モードが使用するかどうかを制御する、 例えば`常规`、`宽屏`、 `网页全屏`か`全屏`."},options:{mode:{defaultValue:a.Normal,displayName:"模式选择",dropdownEnum:a},applyOnPlay:{defaultValue:!1,displayName:"播放时应用"}},urlInclude:r.allVideoUrls,commitHash:"beff4ce3953287b6ef3ece1e3499db247bd15c3a"};return t=t.component}()})); \ No newline at end of file +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["video/player/default-mode"]=t():e["video/player/default-mode"]=t()}(self,(function(){return function(){"use strict";var e={d:function(t,n){for(var o in n)e.o(n,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:n[o]})},o:function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}},t={};e.d(t,{component:function(){return i}});var n=coreApis.componentApis.video.playerAgent,o=coreApis.spinQuery,l=coreApis.utils,r=coreApis.utils.urls;let a;!function(e){e.Normal="常规",e.Wide="宽屏",e.WebFullscreen="网页全屏",e.Fullscreen="全屏"}(a||(a={}));const i={name:"defaultPlayerMode",displayName:"默认播放器模式",entry:async({settings:{options:e}})=>{if((0,l.isEmbeddedPlayer)())return;await(0,l.playerReady)();const t=new Map([[a.Normal,none],[a.Wide,()=>{(0,l.disableWindowScroll)((()=>n.playerAgent.widescreen()))}],[a.WebFullscreen,()=>{n.playerAgent.webFullscreen()}],[a.Fullscreen,async()=>{null!==await(0,o.sq)((()=>dq(n.playerAgent.query.video.element.selector)),(e=>null!==e&&4===e.readyState&&"complete"===document.readyState&&document.hasFocus()))?n.playerAgent.fullscreen():console.warn("[默认播放器模式] 未能应用全屏模式, 等待超时.")}]]),r=await n.playerAgent.query.video.element();if(!r)return;const i=t.get(e.mode);e.applyOnPlay&&!n.playerAgent.isAutoPlay()?r.addEventListener("play",i,{once:!0}):i()},tags:[componentsTags.video],description:{"zh-CN":"控制是否使用默认播放器模式, 可以为`常规`, `宽屏`, `网页全屏`或`全屏`. 注意: 不能和其他影响定位的功能一同使用, 例如播放器定位. (相关讨论: [#483](https://github.com/the1812/Bilibili-Evolved/issues/483))","en-US":"Set the default player mode. Could be `Normal`, `Widescreen`, `Web fullscreen` or `Fullscreen`.","ja-JP":"デフォルト・プレーヤー・モードが使用するかどうかを制御する、 例えば`常规`、`宽屏`、 `网页全屏`か`全屏`."},options:{mode:{defaultValue:a.Normal,displayName:"模式选择",dropdownEnum:a},applyOnPlay:{defaultValue:!1,displayName:"播放时应用"}},urlInclude:r.allVideoUrls,commitHash:"9637948c303b59793929e67434b13afb995509d6"};return t=t.component}()})); \ No newline at end of file diff --git a/registry/lib/components/video/player/default-mode/index.ts b/registry/lib/components/video/player/default-mode/index.ts index 9232e7a6a..f17e0431a 100644 --- a/registry/lib/components/video/player/default-mode/index.ts +++ b/registry/lib/components/video/player/default-mode/index.ts @@ -1,7 +1,7 @@ import { ComponentMetadata, ComponentEntry } from '@/components/types' import { playerAgent } from '@/components/video/player-agent' import { sq } from '@/core/spin-query' -import { isEmbeddedPlayer, playerReady } from '@/core/utils' +import { disableWindowScroll, isEmbeddedPlayer, playerReady } from '@/core/utils' import { allVideoUrls } from '@/core/utils/urls' export enum PlayerModes { @@ -18,7 +18,7 @@ const entry: ComponentEntry = async ({ settings: { options } }) => { const actions: Map void | Promise> = new Map([ [PlayerModes.Normal, none], [PlayerModes.Wide, () => { - playerAgent.widescreen() + disableWindowScroll(() => playerAgent.widescreen()) }], [PlayerModes.WebFullscreen, () => { playerAgent.webFullscreen() diff --git a/src/core/utils/index.ts b/src/core/utils/index.ts index b714143d3..9205384d2 100644 --- a/src/core/utils/index.ts +++ b/src/core/utils/index.ts @@ -195,7 +195,7 @@ export const createHook = (type[target] = original as any) } /** * 阻止元素的对特定类型事件 (非 capture 类) 的处理 @@ -416,3 +416,21 @@ export const waitForForeground = (action: () => void) => { } document.addEventListener('visibilitychange', runAction) } +/** + * 暂时或永久禁用滚动 (window.scrollTo) + * - 暂时: 传入 `action` 时会在 `action` 执行完毕后解除禁用 + * - 永久: 不传入 `action`, 返回一个解除禁用的函数可供调用 + * @param action 需要在禁止滚动时进行的操作 + */ +export const disableWindowScroll = async (action?: () => unknown | Promise) => { + // eslint-disable-next-line prefer-arrow-callback + const restore = createHook(unsafeWindow, 'scrollTo', function hook() { + return false + }) + if (action) { + await action() + restore() + return none + } + return restore +} From 9a3c840cab021aaad95fc1ae3cec82a43e21383e Mon Sep 17 00:00:00 2001 From: the1812 Date: Sun, 2 Jan 2022 16:02:38 +0800 Subject: [PATCH 02/10] Fix categories url (fix #2774) --- src/components/utils/categories/data.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/utils/categories/data.ts b/src/components/utils/categories/data.ts index 9edaed953..2ac02e643 100644 --- a/src/components/utils/categories/data.ts +++ b/src/components/utils/categories/data.ts @@ -51,7 +51,7 @@ const secondaryCategories = rawData[3] const generalCategories: Record = {} // const cinemaMerge = ['纪录片', '电影', '电视剧'] mainCategories.forEach(it => { - const mainUrl = urlNormalize(`https://www.bilibili.com/v/${it.route}/`) + const mainUrl = urlNormalize(it.url || `https://www.bilibili.com/v/${it.route}/`) generalCategories[it.name] = { icon: it.route, code: it.tid, From c6e1eecc42ac5fb421ca78502206145bcce1a9fb Mon Sep 17 00:00:00 2001 From: the1812 Date: Tue, 4 Jan 2022 08:31:55 +0800 Subject: [PATCH 03/10] Add 'video/' in url (fix #2779) --- src/components/feeds/VideoCard.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/feeds/VideoCard.vue b/src/components/feeds/VideoCard.vue index d7b44bb97..fc4e3d8e2 100644 --- a/src/components/feeds/VideoCard.vue +++ b/src/components/feeds/VideoCard.vue @@ -2,7 +2,7 @@
From 238ed281cd285c6cd509013046e5b8dd7432d4e5 Mon Sep 17 00:00:00 2001 From: the1812 Date: Tue, 4 Jan 2022 08:56:25 +0800 Subject: [PATCH 04/10] Only trigger in master --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b6c47dd4a..df3c823ea 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -5,7 +5,7 @@ name: Build # Controls when the action will run. Triggers the workflow on push or pull request on: push: - branches: [ master, preview ] + branches: [ master ] # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: From ed61eea287ddb176a36efe4c2ff3c717a72df2aa Mon Sep 17 00:00:00 2001 From: the1812 Date: Tue, 4 Jan 2022 09:00:05 +0800 Subject: [PATCH 05/10] logError in core watchlater --- .../video/outer-watchlater/OuterWatchlater.vue | 15 +++++---------- src/components/video/watchlater.ts | 8 ++++++-- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/registry/lib/components/video/outer-watchlater/OuterWatchlater.vue b/registry/lib/components/video/outer-watchlater/OuterWatchlater.vue index 41fcefa2b..a57a839e2 100644 --- a/registry/lib/components/video/outer-watchlater/OuterWatchlater.vue +++ b/registry/lib/components/video/outer-watchlater/OuterWatchlater.vue @@ -14,7 +14,6 @@