Skip to content

Commit 7a4269a

Browse files
committed
fix: 重新支持 extendContext 方法
1 parent ae7b8c5 commit 7a4269a

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/app.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { initializePanel } from './panel';
22

33
import logger from './utils/logger';
44
import { isVideoPage } from './utils/checker';
5-
import { copyToClipboard } from './utils/browser';
65
import { sleep, matchRoute } from './utils/global';
6+
import { copyToClipboard, loadUrlQuery } from './utils/browser';
77

88
class App {
99
getNamespace() {
@@ -41,7 +41,7 @@ class App {
4141
const pluginLoader = require.context('./plugins', true, /\/index\.js$/);
4242
pluginLoader.keys().forEach((filename) => {
4343
const slug = filename.slice(2, -9);
44-
if (slug === 'example-plugin') {
44+
if (slug.startsWith('example-')) {
4545
return; // 示例插件将不会被加载
4646
}
4747
this.plugins[slug] = pluginLoader(filename);
@@ -56,17 +56,21 @@ class App {
5656
const panel = initializePanel(this.plugins);
5757

5858
// 上下文管理
59-
const context = {
59+
const globalContext = {
6060
panel,
6161
namespace: this.getNamespace(),
6262
clipboard: {
6363
copy: copyToClipboard,
6464
},
65+
query: loadUrlQuery(location.search),
6566
window: unsafeWindow,
6667
document: unsafeWindow.document,
6768
location: unsafeWindow.location,
6869
env: { isVideoPage: isVideoPage() },
6970
loadScript: (link) => this.loadScript(link),
71+
extendContext: (context) => {
72+
Object.assign(globalContext, context);
73+
},
7074
};
7175

7276
// 检查插件队列是否已经清空
@@ -88,7 +92,7 @@ class App {
8892
if (!plugin.loaded) {
8993
// 合成插件上下文
9094
const pluginContext = {
91-
...context,
95+
...globalContext, // 这里每次都需要重新综合一次主 globalContext,因为其可能被插件更新
9296
logger: logger.extends(plugin.slug),
9397
panelInitialize: panel.pluginInitializers[plugin.slug],
9498
};
@@ -119,10 +123,10 @@ class App {
119123
let needSkip = false;
120124
if (!needSkip && plugin.namespace) {
121125
if (plugin.namespace instanceof Array) {
122-
if (!plugin.namespace.includes(context.namespace)) {
126+
if (!plugin.namespace.includes(globalContext.namespace)) {
123127
needSkip = true;
124128
}
125-
} else if (plugin.namespace !== context.namespace) {
129+
} else if (plugin.namespace !== globalContext.namespace) {
126130
needSkip = true;
127131
}
128132
}

src/panel.less

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
// 插件卡片
6060
.zju-helper-plugin {
6161
.zju-helper-plugin-content {
62+
margin-top: -0.75rem;
6263
max-height: 400px;
6364
overflow-y: hidden;
6465
transition: max-height (@duration * 2) cubic-bezier(0, 1, 0, 1);
@@ -81,7 +82,7 @@
8182
:before,
8283
:after {
8384
--_ui5-v2-4-0_card_header_title_font_weight: bold !important;
84-
--_ui5-v2-4-0_card_header_padding: 1rem 1rem 0 1rem !important;
85+
--_ui5-v2-4-0_card_header_padding: 1rem 1rem 0.75rem 1rem !important;
8586
--_ui5-v2-4-0_tl_li_margin_bottom: 0.625rem !important;
8687
--_ui5-v2-4-0_timeline_tli_indicator_before_bottom: -0.625rem !important;
8788
}

0 commit comments

Comments
 (0)