Skip to content

Commit 23e9b19

Browse files
committed
✨ 增加徽标和菜单设置并调整设置页面 #573
1 parent 5910c0b commit 23e9b19

6 files changed

Lines changed: 379 additions & 135 deletions

File tree

src/app/service/service_worker/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export default class ServiceWorkerManager {
6262
scriptDAO
6363
);
6464
runtime.init();
65-
const popup = new PopupService(this.api.group("popup"), this.mq, runtime, scriptDAO);
65+
const popup = new PopupService(this.api.group("popup"), this.mq, runtime, scriptDAO, systemConfig);
6666
popup.init();
6767
value.init(runtime, popup);
6868
const synchronize = new SynchronizeService(

src/app/service/service_worker/popup.ts

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@ import {
1616
subscribeScriptRunStatus,
1717
} from "../queue";
1818
import { getStorageName } from "@App/pkg/utils/utils";
19+
import type { SystemConfig } from "@App/pkg/config/config";
1920

2021
// 处理popup页面的数据
2122
export class PopupService {
2223
constructor(
2324
private group: Group,
2425
private mq: MessageQueue,
2526
private runtime: RuntimeService,
26-
private scriptDAO: ScriptDAO
27+
private scriptDAO: ScriptDAO,
28+
private systemConfig: SystemConfig
2729
) {}
2830

2931
genScriptMenuByTabMap(menu: ScriptMenu[]) {
@@ -58,6 +60,11 @@ export class PopupService {
5860
async genScriptMenu(tabId: number) {
5961
// 移除之前所有的菜单
6062
chrome.contextMenus.removeAll();
63+
64+
if ((await this.systemConfig.getScriptMenuDisplayType()) !== "all") {
65+
return;
66+
}
67+
6168
const [menu, backgroundMenu] = await Promise.all([this.getScriptMenu(tabId), this.getScriptMenu(-1)]);
6269
if (!menu.length && !backgroundMenu.length) {
6370
return;
@@ -83,6 +90,10 @@ export class PopupService {
8390
}
8491

8592
async registerMenuCommand(message: ScriptMenuRegisterCallbackValue) {
93+
if ((await this.systemConfig.getScriptMenuDisplayType()) === "none") {
94+
// 如果不显示脚本菜单则不处理
95+
return;
96+
}
8697
// 给脚本添加菜单
8798
return this.txUpdateScriptMenu(message.tabId, async (data) => {
8899
const script = data.find((item) => item.uuid === message.uuid);
@@ -228,6 +239,20 @@ export class PopupService {
228239
data.push(item);
229240
}
230241
});
242+
if ((await this.systemConfig.getBadgeNumberType()) === "script_count") {
243+
chrome.action.setBadgeText({
244+
text: data.length.toString(),
245+
tabId: tabId,
246+
});
247+
chrome.action.setBadgeBackgroundColor({
248+
color: await this.systemConfig.getBadgeBackgroundColor(),
249+
tabId: tabId,
250+
});
251+
chrome.action.setBadgeTextColor({
252+
color: await this.systemConfig.getBadgeTextColor(),
253+
tabId: tabId,
254+
});
255+
}
231256
return data;
232257
});
233258
}
@@ -417,11 +442,14 @@ export class PopupService {
417442
}) => {
418443
this.addScriptRunNumber({ tabId, frameId, scripts });
419444
// 设置角标
445+
if ((await this.systemConfig.getBadgeNumberType()) !== "run_count") {
446+
return;
447+
}
420448
chrome.action.getBadgeText(
421449
{
422450
tabId: tabId,
423451
},
424-
(res: string) => {
452+
async (res: string) => {
425453
const lastError = chrome.runtime.lastError;
426454
if (lastError) {
427455
console.error("chrome.runtime.lastError in chrome.action.getBadgeText:", lastError);
@@ -434,7 +462,11 @@ export class PopupService {
434462
tabId: tabId,
435463
});
436464
chrome.action.setBadgeBackgroundColor({
437-
color: "#4e5969",
465+
color: await this.systemConfig.getBadgeBackgroundColor(),
466+
tabId: tabId,
467+
});
468+
chrome.action.setBadgeTextColor({
469+
color: await this.systemConfig.getBadgeTextColor(),
438470
tabId: tabId,
439471
});
440472
}

src/locales/en-US/translation.json

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,5 +421,34 @@
421421
"ext_update_notification_desc": "Current version: {{version}}, please see the update log for details",
422422
"watch_file_description": "Monitor file changes and automatically update scripts. When using, please make sure the script file path remains unchanged and the page cannot be closed.",
423423
"watch_file": "Watch file",
424-
"stop_watch_file": "Stop watch"
424+
"stop_watch_file": "Stop watch",
425+
"script_menu_display": "Script Registered Menu",
426+
"badge_type_none": "None",
427+
"badge_type_run_count": "Run Count",
428+
"badge_type_script_count": "Script Count",
429+
"menu_display_none": "None",
430+
"menu_display_no_browser": "No Browser Display",
431+
"menu_display_all": "Show All",
432+
"interface_settings": "Interface",
433+
"select_interface_language": "Select interface display language",
434+
"extension_icon_badge": "Extension Icon Badge",
435+
"display_type": "Display Type",
436+
"extension_icon_badge_type": "Number type displayed on extension icon",
437+
"background_color": "Background Color",
438+
"badge_background_color_desc": "Badge background color",
439+
"text_color": "Text Color",
440+
"badge_text_color_desc": "Badge text color",
441+
"script_menu": "Script Menu",
442+
"menu_display": "Menu Display",
443+
"control_menu_display_position": "Control menu display position",
444+
"expand_count": "Expand Count",
445+
"auto_collapse_when_exceeds": "Auto collapse when exceeds this number",
446+
"check_frequency": "Check Frequency",
447+
"script_auto_update_frequency": "Script automatic update check frequency",
448+
"update_options": "Update Options",
449+
"control_script_update_behavior": "Control script update behavior",
450+
"blacklist_pages_desc": "Prevent scripts from running on specified pages, supports wildcards",
451+
"development_tools": "Development Tools",
452+
"check_script_code_quality": "Check script code quality and errors",
453+
"custom_eslint_rules_config": "Custom ESLint rules configuration (JSON format)"
425454
}

src/locales/zh-CN/translation.json

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,5 +421,34 @@
421421
"ext_update_notification_desc": "当前版本:{{version}},详情请查看更新日志",
422422
"watch_file_description": "监听文件变动,自动更新脚本,使用时请确保脚本文件路径不变且不能关闭页面",
423423
"watch_file": "监听文件",
424-
"stop_watch_file": "停止监听"
424+
"stop_watch_file": "停止监听",
425+
"script_menu_display": "脚本注册的菜单",
426+
"badge_type_none": "不显示",
427+
"badge_type_run_count": "运行次数",
428+
"badge_type_script_count": "脚本个数",
429+
"menu_display_none": "不显示",
430+
"menu_display_no_browser": "不在浏览器中显示",
431+
"menu_display_all": "全部显示",
432+
"interface_settings": "界面",
433+
"select_interface_language": "选择界面显示语言",
434+
"extension_icon_badge": "扩展图标徽标",
435+
"display_type": "显示类型",
436+
"extension_icon_badge_type": "扩展图标上显示的数字类型",
437+
"background_color": "背景颜色",
438+
"badge_background_color_desc": "徽标背景色",
439+
"text_color": "文字颜色",
440+
"badge_text_color_desc": "徽标文字色",
441+
"script_menu": "脚本菜单",
442+
"menu_display": "菜单显示",
443+
"control_menu_display_position": "控制菜单显示位置",
444+
"expand_count": "展开数量",
445+
"auto_collapse_when_exceeds": "超过此数量时自动折叠",
446+
"check_frequency": "检查频率",
447+
"script_auto_update_frequency": "脚本自动检查更新的频率",
448+
"update_options": "更新选项",
449+
"control_script_update_behavior": "控制脚本更新的行为",
450+
"blacklist_pages_desc": "禁止脚本在指定页面运行,支持通配符",
451+
"development_tools": "开发工具",
452+
"check_script_code_quality": "检查脚本代码质量和错误",
453+
"custom_eslint_rules_config": "自定义 ESLint 规则配置(JSON 格式)"
425454
}

0 commit comments

Comments
 (0)