File tree Expand file tree Collapse file tree
app/service/service_worker Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -179,14 +179,21 @@ export class RuntimeService {
179179 } ) ;
180180 } ) ;
181181
182- this . systemConfig . addListener ( "enable_script" , ( enable ) => {
183- this . isEnableUserscribe = enable ;
184- if ( enable ) {
185- this . registerUserscripts ( ) ;
186- } else {
187- this . unregisterUserscripts ( ) ;
182+ this . systemConfig . addListener (
183+ "enable_script" + ( chrome . extension . inIncognitoContext ? "_incognito" : "" ) ,
184+ async ( enable ) => {
185+ this . isEnableUserscribe = await this . systemConfig . getEnableScript ( ) ;
186+ if ( chrome . extension . inIncognitoContext ) {
187+ // 隐身窗口不对注册了的脚本进行实际操作
188+ return ;
189+ }
190+ if ( enable ) {
191+ this . registerUserscripts ( ) ;
192+ } else {
193+ this . unregisterUserscripts ( ) ;
194+ }
188195 }
189- } ) ;
196+ ) ;
190197 // 检查是否开启
191198 this . isEnableUserscribe = await this . systemConfig . getEnableScript ( ) ;
192199 if ( this . isEnableUserscribe ) {
@@ -380,6 +387,9 @@ export class RuntimeService {
380387 }
381388
382389 async pageLoad ( _ : any , sender : GetSender ) {
390+ if ( ! this . isEnableUserscribe ) {
391+ return { flag : "" , scripts : [ ] } ;
392+ }
383393 // 判断是否黑名单
384394 const isBlack = this . blackMatch . match ( sender . getSender ( ) . url ! ) ;
385395 if ( isBlack . length > 0 ) {
Original file line number Diff line number Diff line change @@ -274,11 +274,22 @@ export class SystemConfig {
274274 }
275275
276276 setEnableScript ( enable : boolean ) {
277+ if ( chrome . extension . inIncognitoContext ) {
278+ return this . set ( "enable_script_incognito" , enable ) ;
279+ }
277280 this . set ( "enable_script" , enable ) ;
278281 }
279282
280- getEnableScript ( ) : Promise < boolean > {
281- return this . get ( "enable_script" , true ) ;
283+ async getEnableScript ( ) : Promise < boolean > {
284+ const enableScript = await this . get ( "enable_script" , true ) ;
285+ if ( chrome . extension . inIncognitoContext ) {
286+ // 如果是隐身窗口,主窗口设置为false,直接返回false
287+ if ( enableScript === false ) {
288+ return false ;
289+ }
290+ return this . get ( "enable_script_incognito" , true ) ;
291+ }
292+ return enableScript ;
282293 }
283294
284295 setBlacklist ( blacklist : string ) {
You can’t perform that action at this time.
0 commit comments