From 603d7e3f2d91a0b4c08fdc7702d09f3fe32d793e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A5=BD=E5=90=A7=EF=BC=8C=E4=BD=A0=E6=83=B3=E8=AF=B4?= =?UTF-8?q?=E5=95=A5?= Date: Thu, 2 Feb 2023 22:15:15 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=84=E5=88=99=E5=88=97=E8=A1=A8=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E9=A2=9C=E8=89=B2=E5=8C=BA=E5=9D=97=EF=BC=8C=E5=8A=A0?= =?UTF-8?q?=E4=BB=A5=E5=8C=BA=E5=88=86=E4=B8=8D=E5=90=8C=E5=8C=BA=E9=97=B4?= =?UTF-8?q?=E8=A7=84=E5=88=99=E5=92=8C=E4=BF=AE=E6=94=B9=E8=A7=84=E5=88=99?= =?UTF-8?q?=E5=8C=BA=E9=97=B4=E7=9B=B8=E5=85=B3=E6=8F=8F=E8=BF=B0=20(#150)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG-0.10.x.md | 2 +- extension/options_ui/README.md | 18 +++---- extension/options_ui/css/app.css | 50 +++++++++++++++++++ extension/options_ui/js/component/common.js | 10 ++++ .../options_ui/js/component/show-rule.js | 44 ++++++++++++++-- .../tools/download-chromium-extension.sh | 17 +++++-- extension/tools/download-firefox.sh | 8 ++- 7 files changed, 128 insertions(+), 21 deletions(-) diff --git a/CHANGELOG-0.10.x.md b/CHANGELOG-0.10.x.md index bcd51678..b22d76c8 100644 --- a/CHANGELOG-0.10.x.md +++ b/CHANGELOG-0.10.x.md @@ -9,7 +9,7 @@ > 1. 移除无效的静态资源库 [辉哥博客&蓝易云安全](https://www.haah.net/archives/7885.html) > 1. `fonts.googleapis.com` 重定向到 `fonts.googleapis.cn` > 1. `fonts.gstatic.com` 重定向到 `fonts.gstatic.cn` -> 1. 新增使用扩展的修改相应头和请求头的功能解决跨域的例子 (CORS.json) +> 1. 新增使用扩展的修改响应头和请求头的功能解决跨域的例子 (CORS.json) > 1. 新增解决 stackoverflow.com 网站下 cdn.sstatic.net 域下静态资源加载慢的例子 (sstatic.net-stackoverflow.com.json) > 1. 修改演示例子里地址链接 diff --git a/extension/options_ui/README.md b/extension/options_ui/README.md index a54c24fc..350f323c 100644 --- a/extension/options_ui/README.md +++ b/extension/options_ui/README.md @@ -86,17 +86,17 @@ chrome.declarativeNetRequest.updateDynamicRules( ## 按照规则来源划分规则 ID 区间段 -| 规则来源 | 对应选项页选项 | ID 区间段 | 区间名称 | 作用 | 与删除选项的关系) | -| :--------------------- | :--------------------------------------------------------------------------------- | :-------------------------: | :------------------- | :------------------------------------------------------- | :--------------------------- | -| 固定配置 | 默认侯选项切换 | ID 编号<10000 | 默认侯选项切换 | 改变默认规则候选项 | 删除规则只删除对应区间的规则 | -| 自定义 | 选项三:自定义规则 -- 新增特制规则 | 10000>=规则 ID 编号<=19999 | 自定义特制规则编号 | 自己定义规则 特制规则 | 删除规则只删除对应区间的规则 | -| 自定义 | 选项三:自定义规则 -- 新增普通规则 | 20000>=规则 ID 编号<=29999 | 自定义普通规则编号 | 自己定义规则 普通规则 | 删除规则只删除对应区间的规则 | -| 同步远端配置的静态规则 | 选项一:全局动态规则处理 -- 同步远端仓库最新静态规则到本地,并停用本地默认静态规则 | 30000<=规则 ID 编号<=39999 | 同步远端静态规则编号 | 实现不更新扩展,更新默认规则,取代本地已有的默认静态规则 | 删除规则只删除对应区间的规则 | -| 同步远端动态规则 | 选项二:同步远端配置规则 -- 同步远端配置规则 | 40000<=规则 ID 编号<=320000 | 同步远端动态规则 | 同步指定仓库地址的规则, 实现不更新扩展,更新规则 | 删除规则只删除对应区间的规则 | -| 未定义 | 无 | 无 | 无 | 无 | 无 | +| 规则来源 | 对应选项页选项 | ID 区间段 | 区间名称 | 作用 | 与删除选项的关系) | +| :--------------------- | :--------------------------------------------------------------------------------- | :-------------------------: | :----------------- | :------------------------------------------------------- | :--------------------------- | +| 固定配置 | 默认侯选项切换 | ID 编号<10000 | 默认侯选项切换规则 | 改变默认规则候选项 | 删除规则只删除对应区间的规则 | +| 自定义 | 选项三:自定义规则 -- 新增特制规则 | 10000>=规则 ID 编号<=19999 | 自定义特制规则 | 自己定义 特制规则 | 删除规则只删除对应区间的规则 | +| 自定义 | 选项三:自定义规则 -- 新增普通规则 | 20000>=规则 ID 编号<=29999 | 自定义普通规则 | 自己定义 普通规则 | 删除规则只删除对应区间的规则 | +| 同步远端配置的静态规则 | 选项一:全局动态规则处理 -- 同步远端仓库最新静态规则到本地,并停用本地默认静态规则 | 30000<=规则 ID 编号<=39999 | 同步远端静态规则 | 实现不更新扩展,更新默认规则,取代本地已有的默认静态规则 | 删除规则只删除对应区间的规则 | +| 同步远端动态规则 | 选项二:同步远端配置规则 -- 同步远端配置规则 | 40000<=规则 ID 编号<=320000 | 同步远端动态规则 | 同步指定仓库地址的规则, 实现不更新扩展,更新规则 | 删除规则只删除对应区间的规则 | +| 未定义 | 无 | 无 | 无 | 无 | 无 | ```text -默认侯选项切换规则编号(固定编号): 编号<=10000 +默认侯选项切换规则编号(固定编号): 编号<=9999 自定义特制规则编号: 10000>=编号<=19999 diff --git a/extension/options_ui/css/app.css b/extension/options_ui/css/app.css index 817130e9..f4d963a6 100644 --- a/extension/options_ui/css/app.css +++ b/extension/options_ui/css/app.css @@ -121,6 +121,14 @@ font-size: 1.3rem; font-weight: 800; } +/* +#jsoneditor { + width: 600px; + height: 500px; +} + + */ + .placeholder-box { display: inline-block; margin-left: 2rem; @@ -171,3 +179,45 @@ font-size: 1.3rem; line-height: 1.5; color: red; } + +/* + 配色参考: https://c.runoob.com/more/colorpad/tradcnc.html + + */ + +.single_rule { + background-color: #732e7e; +} + +.self_define_special_rule { + background-color: #808883; +} + +.self_define_rule { + background-color: #9db1a0; +} + +.sync_remote_static_rule { + background-color: #8b8bdd; +} + +.sync_remote_rule { + background-color: #d2ae8c; +} + +.all_dynamic_rule { + background-color: #58665e; +} + +.all_dynamic_rule_test { + /* + background-color: #1a638a; + background-color: #10da5a; + background-color: #04a4ff; + background-color: #027a7a; + background-color: #9c27b0; + background-color: #8b8bdd; + background-color: #efefef; + background-color: #bd7a07; + */ +} diff --git a/extension/options_ui/js/component/common.js b/extension/options_ui/js/component/common.js index dd1a60b1..d3ab3bba 100644 --- a/extension/options_ui/js/component/common.js +++ b/extension/options_ui/js/component/common.js @@ -1,12 +1,21 @@ import * as utils from "/third_party/jingjingxyk/frontend-utils/utils.js"; import { showRuleList } from "./show-rule.js"; let id_ranges = { + single_rule: [1, 9999], self_define_special_rule: [10000, 19999], self_define_rule: [20000, 29999], sync_remote_static_rule: [30000, 39999], sync_remote_rule: [40000, 320000], all_dynamic_rule: [0, Infinity], }; +let id_ranges_name = { + single_rule: "默认侯选项规则", + self_define_special_rule: "自定义特制规则", + self_define_rule: "自定义普通规则", + sync_remote_static_rule: "同步远端静态规则", + sync_remote_rule: "同步远端动态规则", + all_dynamic_rule: "所有动态规则", +}; let deleteDynamicRules = (type, id = 0) => { chrome.declarativeNetRequest.getDynamicRules((rules) => { let del_ids = []; @@ -96,5 +105,6 @@ export { deleteDynamicRules, backupDynamicRules, id_ranges, + id_ranges_name, enableStaticRules, }; diff --git a/extension/options_ui/js/component/show-rule.js b/extension/options_ui/js/component/show-rule.js index 920a415c..6abc0d5e 100644 --- a/extension/options_ui/js/component/show-rule.js +++ b/extension/options_ui/js/component/show-rule.js @@ -1,4 +1,9 @@ -import { deleteDynamicRules, id_ranges, utils } from "./common.js"; +import { + deleteDynamicRules, + id_ranges, + id_ranges_name, + utils, +} from "./common.js"; let showRuleJSON = (rule) => { let local_manifest = chrome.runtime.getManifest(); @@ -25,24 +30,53 @@ let showRuleJSON = (rule) => { } }; +let getRuleClassName = (id) => { + id = parseInt(id); + let name = ""; + for (let i in id_ranges) { + if (id_ranges[i][0] <= id && id <= id_ranges[i][1]) { + name = i; + break; + } + } + //console.log(id,name, id_ranges[name]); + return name; +}; + +let rule_action_types = { + redirect: "URI重定向", + modifyHeaders: "修改请求头或者响应头", + block: "阻止请求", +}; + +/** + * 显示规则集 + */ let showRuleList = () => { + //动态规则集 chrome.declarativeNetRequest.getDynamicRules((rules) => { //console.log(rules); let list_box = document.querySelector(".rule_dynamic_set_list"); let list = ""; rules.forEach((value, key, array) => { //console.log(value.id, value); - list += `
  • ${ + )}" title="规则来源:${show_id_range_name}">规则来源:${show_id_range_name};编号为:  ${ value.id - }            ❌
  • `; + }" title="删除本条规则">    ❌`; }); list_box.innerHTML = list; }); + //静态规则集,也就是manifest.json 配置信息 chrome.declarativeNetRequest.getEnabledRulesets((rulesetIds) => { console.log(rulesetIds); /* diff --git a/extension/tools/download-chromium-extension.sh b/extension/tools/download-chromium-extension.sh index 1f7d4920..776096ba 100644 --- a/extension/tools/download-chromium-extension.sh +++ b/extension/tools/download-chromium-extension.sh @@ -34,12 +34,21 @@ test -d temp && rm -rf temp mkdir -p temp cd ${__DIR__}/temp - +# google translate extension_id=aapbdbdomjkkjkaonfhkkikfgjllcleb +file_name='google-translate' + +# Clear Site Data +extension_id=aihgofjefdlhpnmeakpnjjeajofpcbhj +file_name='Clear-Site-Data' + +# Multi Elasticsearch Head +extension_id=cpmmilfkofbeimbmgiclohpodggeheim +file_name='Multi-Elasticsearch-Head' -download_url='https://clients2.google.com/service/update2/crx?response=redirect&prodversion=106.0.0.0&acceptformat=crx2,crx3&x=id%3Daapbdbdomjkkjkaonfhkkikfgjllcleb%26uc&nacl_arch=x86-64' +download_url="https://clients2.google.com/service/update2/crx?response=redirect&prodversion=109.0.5414.119&acceptformat=crx2,crx3&x=id%3D${extension_id}%26uc&nacl_arch=x86-64" -curl -Lo google-translate.crx $download_url +curl -Lo "${file_name}.crx" $download_url unset http_proxy unset https_proxy @@ -52,7 +61,7 @@ unset no_proxy # curl --proxy "socks5h://127.0.0.1:2000" -Lo google-translate.crx $download_url set +e -unzip -d google-translate google-translate.crx +unzip -d ${file_name} "${file_name}.crx" set -e cd ${__DIR__}/ diff --git a/extension/tools/download-firefox.sh b/extension/tools/download-firefox.sh index c309e93f..694ed8a6 100644 --- a/extension/tools/download-firefox.sh +++ b/extension/tools/download-firefox.sh @@ -11,6 +11,10 @@ cd ${__DIR__} # downloaf firefox # https://archive.mozilla.org/pub/firefox/releases/ +# firefox manifest-v3-migration-guide +# https://extensionworkshop.com/documentation/develop/manifest-v3-migration-guide/ +# MV3 扩展在 Firefox 109(2023 年 1 月 17 日)的全面发布中发布 +# https://blog.mozilla.org/addons/2022/11/17/manifest-v3-signing-available-november-21-on-firefox-nightly/ -curl -Lo firefox-108.tar.bz2 https://archive.mozilla.org/pub/firefox/releases/108.0b9/linux-x86_64/en-US/firefox-108.0b9.tar.bz2 -tar -jxvf firefox-108.tar.bz2 \ No newline at end of file +curl -Lo firefox-109.0b9.tar.bz2 https://archive.mozilla.org/pub/firefox/releases/109.0b9/linux-x86_64/en-US/firefox-109.0b9.tar.bz2 +tar -jxvf firefox-109.0b9.tar.bz2 \ No newline at end of file