Skip to content

Commit 38a33b1

Browse files
committed
✨ 开启开关单独控制隐身模式与主窗口 #571
1 parent 1d139aa commit 38a33b1

2 files changed

Lines changed: 30 additions & 9 deletions

File tree

src/app/service/service_worker/runtime.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff 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) {

src/pkg/config/config.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff 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) {

0 commit comments

Comments
 (0)