diff --git a/CHANGELOG-v3-x.x.x.md b/CHANGELOG-v3-x.x.x.md index 0f62effa..2fddbf3b 100644 --- a/CHANGELOG-v3-x.x.x.md +++ b/CHANGELOG-v3-x.x.x.md @@ -1,5 +1,10 @@ # CHANGELOG for v3 +## CHANGELOG for v3 0.11.0 [2023-12-06 21:01:00 +0800] + +> 1. 新增: 新增备份自定义规则功能 +> 1. 变更: 移除备份所有动态规则功能 + ## CHANGELOG for v3 0.10.32 [2023-12-05 15:01:00 +0800] > 1. 新增: 创建 文档目录 `docs` diff --git a/extension/manifest.json b/extension/manifest.json index 0f520086..8c106ef6 100644 --- a/extension/manifest.json +++ b/extension/manifest.json @@ -1,11 +1,11 @@ { "name": "Replace Google CDN", - "version": "0.10.32", + "version": "0.11.0", "manifest_version": 3, "icons": { "128": "icons/128.png" }, - "description": "将 Google CDN 替换为国内镜像 v3 更新日期:2023-12-05", + "description": "将 Google CDN 替换为国内镜像 v3 更新日期:2023-12-06", "background": { "service_worker": "js/background.js", "type": "module" diff --git a/extension/options_ui/advance.html b/extension/options_ui/advance.html index a4930614..76f94c5b 100644 --- a/extension/options_ui/advance.html +++ b/extension/options_ui/advance.html @@ -54,8 +54,8 @@

扩展高级选项设置

选项一:全局动态规则处理

- diff --git a/extension/options_ui/js/AdvanceBundle/Components/globalDynamicRuleMain.js b/extension/options_ui/js/AdvanceBundle/Components/globalDynamicRuleMain.js index da31e5e6..f322d1ce 100644 --- a/extension/options_ui/js/AdvanceBundle/Components/globalDynamicRuleMain.js +++ b/extension/options_ui/js/AdvanceBundle/Components/globalDynamicRuleMain.js @@ -1,7 +1,7 @@ import { deleteDynamicRules, updateDynamicRules, - backupAllDynamicRules, + backupSelfDefinedDynamicRules, utils, enableStaticRules, id_ranges @@ -10,14 +10,15 @@ import { remote_repository_static_urls } from "../Config/rule_example_conf.js"; import showRuleList from "../../CommonBundle/Components/showRuleList.js"; import { showDynamicRules } from "../../CommonBundle/Components/showDynamicRules.js"; -//备份所有动态规则 -let bindBackupAllDynamicRuleEventListener = () => { +//绑定备份自定义动态规则事件 + +let bindBackupSelfDefinedDynamicRuleEventListener = () => { document - .querySelector(".backup-all-dynamic-rule") + .querySelector(".backup-self-defined-dynamic-rule") .addEventListener("click", (event) => { event.stopPropagation(); event.preventDefault(); - backupAllDynamicRules(); + backupSelfDefinedDynamicRules(); }); }; @@ -199,8 +200,8 @@ let get_remote_repository_static_rule = async () => { }; export default () => { - //备份所有动态规则 - bindBackupAllDynamicRuleEventListener(); + //备份自定义规则 + bindBackupSelfDefinedDynamicRuleEventListener(); //删除所有动态规则 bindDeleteAllDynamicRuleEventListener(); diff --git a/extension/options_ui/js/CommonBundle/Components/common.js b/extension/options_ui/js/CommonBundle/Components/common.js index c92a6785..ede6c08c 100644 --- a/extension/options_ui/js/CommonBundle/Components/common.js +++ b/extension/options_ui/js/CommonBundle/Components/common.js @@ -9,6 +9,7 @@ let id_ranges = { sync_remote_rule: [40000, 320000], all_dynamic_rule: [0, Infinity] }; + //区间段名称 let id_range_name_map = { single_rule: "默认候选项规则", @@ -42,6 +43,7 @@ let updateDynamicRules = ( } ); }; + let deleteDynamicRules = (type, id = 0, callback = () => {}, ...args) => { let del_ids = []; let id_range = [0, 0]; @@ -88,19 +90,39 @@ let deleteDynamicRules = (type, id = 0, callback = () => {}, ...args) => { }); }; -let backupAllDynamicRules = () => { +/** + * 备份自定义规则 + */ +let backupSelfDefinedDynamicRules = () => { chrome.declarativeNetRequest.getDynamicRules((rules) => { if (rules.length > 0) { let time = new Date().toISOString(); console.log(time); //time=parseInt(new Date().getTime() / 1000).toString() let filename = - "ReplaceGoogleCDN-backup-all-dynamic-rule-" + time + ".json"; - console.log(filename); - utils.createJSONFile(rules, filename); + "replace-google-cdn-backup-self-defined-dynamic-rule-" + time + ".json"; + + let need_rules = []; + rules.map((rule, index, array) => { + if ( + rule.id >= id_ranges["self_define_rule"][0] && + rule.id <= id_ranges["self_define_rule"][1] + ) { + need_rules.push(rule); + } + + if ( + rule.id >= id_ranges["self_define_special_rule"][0] && + rule.id <= id_ranges["self_define_special_rule"][1] + ) { + need_rules.push(rule); + } + }); + utils.createJSONFile(need_rules, filename); } }); }; + /** * 启用本地默认静态规则 */ @@ -136,7 +158,7 @@ export { utils, updateDynamicRules, deleteDynamicRules, - backupAllDynamicRules, + backupSelfDefinedDynamicRules, id_ranges, id_range_name_map, rule_action_type_map,