@@ -2,8 +2,8 @@ import { initializePanel } from './panel';
22
33import logger from './utils/logger' ;
44import { isVideoPage } from './utils/checker' ;
5- import { copyToClipboard } from './utils/browser' ;
65import { sleep , matchRoute } from './utils/global' ;
6+ import { copyToClipboard , loadUrlQuery } from './utils/browser' ;
77
88class App {
99 getNamespace ( ) {
@@ -41,7 +41,7 @@ class App {
4141 const pluginLoader = require . context ( './plugins' , true , / \/ i n d e x \. j s $ / ) ;
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 }
0 commit comments