diff --git a/.gitignore b/.gitignore index 60c0e6da..17d926cc 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,8 @@ extension/tools/blocked-domain.py extension/tools/temp/ extension/test/nohup.out extension/tools/git-clean-file-history.sh +extension/tools/local-deploy.sh +extension/tools/web/proxy.pac extension/third_party/ !extension/third_party/README.md @@ -23,4 +25,6 @@ extension/third_party/ dist extension/manifest-backup.json -extension/web/ + + +extension/web-backup/ \ No newline at end of file diff --git a/CHANGELOG-0.10.x.md b/CHANGELOG-0.10.x.md index 74142834..dc311d71 100644 --- a/CHANGELOG-0.10.x.md +++ b/CHANGELOG-0.10.x.md @@ -4,6 +4,10 @@ ## [一个完整的 测试环境例子 可用于查看优秀的源码 ](https://github.com/jingjingxyk/extension-v3-test) +## CHANGELOG for 0.10.12 [2022-11-04 08:10:40 +0800] + +> 1. v2 版本添加域名拦截功能 + ## CHANGELOG for 0.10.11 [2022-10-17 15:10:40 +0800] > 1. 实现不更新扩展的前提下,同步主仓库最新版静态规则 diff --git a/extension-v2/README.md b/extension-v2/README.md index cbe2cffd..e8cf456d 100644 --- a/extension-v2/README.md +++ b/extension-v2/README.md @@ -9,3 +9,7 @@ - https://chromium.googlesource.com/ - https://source.chromium.org/chromium - https://cs.opensource.google/ + +## 发现 v2 版本功能齐全的扩展[HeaderEditor](https://github.com/FirefoxBar/HeaderEditor.git) + +> 没有提供 v3 版本,关键是有 UI,使用的技术都是一样的 diff --git a/extension-v2/js/background.js b/extension-v2/js/background.js index 14f4d1d7..d7dca1d1 100644 --- a/extension-v2/js/background.js +++ b/extension-v2/js/background.js @@ -19,7 +19,7 @@ function hasCSP(headers = []) { ================================================== 功能一: 移除内容安全策略 (content-security-policy) - 实际也可以: + 可以修改响应头 1. 响应头添加键值对 2. 响应头移除键值对 @@ -70,6 +70,7 @@ const remove_csp_urls = [ "*://developers.redhat.com/*", "*://*.githubusercontent.com/*", "*://pub.dev/*", + "*://stackoverflow.com/*", ]; /** @@ -129,22 +130,6 @@ chrome.webRequest.onHeadersReceived.addListener( let suffix_domain = ".proxy.domain.com"; //请把这个换成你自己的域名 //let suffix_domain = ".proxy.xiaoshuogeng.com"; -//Open Source urls 高级玩法测试域名 -let opensource_google_urls = [ - "*://*.chromium.org/*", //Chromium ChromiumOS GN - "*://*.googlesource.com/*", //Chromium - "*://summerofcode.withgoogle.com/*", - "*://cs.opensource.google/*", //Google Open Source - "*://opensource.googleblog.com/*", - "*://opensource.google/*", -]; -// 高级玩法测试域名组 -let test_urls = [ - ...opensource_google_urls, - "*://*.google.com/*", - "*://github.com/*", -]; - /** * 高级玩法一: * 特定域名替换 @@ -166,6 +151,7 @@ let need_replace_cdn_urls = [ "ssl.gstatic.com", "www.gstatic.com", "secure.gravatar.com", + "www.gravatar.com", "maxcdn.bootstrapcdn.com", "github.com", "www.google.com", @@ -186,6 +172,23 @@ let replace_cdn_urls = (details) => { return null; }; +//Open Source urls 高级玩法测试域名 +let opensource_google_urls = [ + "*://*.chromium.org/*", //Chromium ChromiumOS GN + "*://*.googlesource.com/*", //Chromium + "*://summerofcode.withgoogle.com/*", + "*://cs.opensource.google/*", //Google Open Source + "*://opensource.googleblog.com/*", + "*://opensource.google/*", +]; + +// 高级玩法测试域名组 +let test_urls = [ + ...opensource_google_urls, + "*://*.google.com/*", + "*://github.com/*", +]; + /** * 高级玩法二: * 泛域名替换(不限定域名) @@ -210,6 +213,13 @@ let use_nginx_proxy = (details, proxy_provider) => { return "https://" + dot_nums + "_" + host + proxy_provider + query_string; }; +// 被阻止请求的域名列表 +let block_domains = [ + "google-analytics.com", + "example.com", + "googletagmanager.com", +]; + /* 请求地址重定向 参考文档: @@ -232,15 +242,30 @@ chrome.webRequest.onBeforeRequest.addListener( */ /* - - //高级玩法一: - let des_url; - if ((des_url = replace_cdn_urls(details))) { - return { redirectUrl: des_url }; - } - - //高级玩法二: - return { redirectUrl: use_nginx_proxy(details, suffix_domain) }; + //拦截请求域名(也就是广告拦截器原理) 写法一: + let prevent_domins = block_domains.filter( + (domain) => details.url.indexOf(domain) !== -1 + ); + if (prevent_domins.length > 0) { + return { cancel: true }; + } + + //拦截请求域名(也就是广告拦截器原理) 写法二: + if ( + details.url.indexOf("example.com") !== -1 || + details.url.indexOf("google-analytics.com") !== -1 + ) { + return { cancel: true }; + } + + //高级玩法一: + let des_url; + if ((des_url = replace_cdn_urls(details))) { + return { redirectUrl: des_url }; + } + + //高级玩法二: + return { redirectUrl: use_nginx_proxy(details, suffix_domain) }; */ @@ -293,18 +318,29 @@ chrome.webRequest.onBeforeRequest.addListener( "*://developers.google.com/*", "*://code.jquery.com/jquery-*", "*://code.jquery.com/ui/*", + //"*://*.googletagmanager.com/*", + //"*://*.example.com/*", + //"*://*.google-analytics.com/*", //...test_urls, // 高级玩法的测试用例 ], }, ["blocking"] ); +/* +================================================== + + 功能三: 修改请求头 ( modify header) + +================================================== +*/ + /* 请求头添加、移除参数 参考文档: 1. https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/webRequest - 例子1:吸怪 User-Agent + 例子1:请求头修改 User-Agent 例子2:请求头添加参数 例子3:请求头移除参数 移除携带的cookie信息 */ diff --git a/extension/rules/README.md b/extension/rules/README.md index e2d0c2bf..197a32f1 100644 --- a/extension/rules/README.md +++ b/extension/rules/README.md @@ -3,33 +3,30 @@ ## 网络拨测工具 (测试 公共 CDN 静态资源库 区域可用性) 1. [网络拨测工具](https://zijian.aliyun.com/detect/http) -2. [网站诊断分析工具](https://zijian.aliyun.com/) +1. [网站诊断分析工具](https://zijian.aliyun.com/) ## 公共 CDN 静态资源库 1. [前端 CDNJS 库及 Google Fonts、Ajax 和 Gravatar 国内加速服务 http://css.loli.net](https://u.sb/css-cdn/) -2. [360 奇舞团](https://cdn.baomitu.com/) -3. [又拍云](http://jscdn.upai.com/) -4. [BootCDN](https://www.bootcdn.cn/) -5. [字节跳动静态资源公共库](http://cdn.bytedance.com/) -6. [Microsoft Ajax Content Delivery Network](https://docs.microsoft.com/en-us/aspnet/ajax/cdn/overview) -7. [jsdelivr](https://www.jsdelivr.com/) -8. [unpkg](https://unpkg.com/) -9. [cloudflare ](https://cdnjs.com/) -10. [google libraries cn](https://developers.google.cn/speed/libraries) -11. [七牛静态库 Staticfile CDN](http://staticfile.org/) -12. [极客族公共加速服务](https://cdn.geekzu.org/cached.html) -13. [中科大反向代理列表如下:](https://mirrors.ustc.edu.cn/) - -```text -ajax.googleapis.com ajax.proxy.ustclug.org -themes.googleusercontent.com google-themes.proxy.ustclug.org -``` - -15. [CDNJS 南方科技大学](https://mirrors.sustech.edu.cn/help/cdnjs.html) -16. [CDNJS 重庆邮电大学暂时不可用](https://mirrors.cqupt.edu.cn/cdnjs/) -17. [CDNJS mirror list ](https://mirrorz.org/list/cdnjs) -18. [公共 CDN 静态资源加速服务 7ED Services ](https://www.7ed.net/start/public-cdn.html) +1. [360 奇舞团](https://cdn.baomitu.com/) +1. [又拍云](http://jscdn.upai.com/) +1. [BootCDN](https://www.bootcdn.cn/) +1. [字节跳动静态资源公共库](http://cdn.bytedance.com/) +1. [Microsoft Ajax Content Delivery Network](https://docs.microsoft.com/en-us/aspnet/ajax/cdn/overview) +1. [jsdelivr](https://www.jsdelivr.com/) +1. [unpkg](https://unpkg.com/) +1. [cloudflare ](https://cdnjs.com/) +1. [google libraries cn](https://developers.google.cn/speed/libraries) +1. [七牛静态库 Staticfile CDN](http://staticfile.org/) +1. [极客族公共加速服务](https://cdn.geekzu.org/cached.html) +1. [CDNJS 南方科技大学](https://mirrors.sustech.edu.cn/help/cdnjs.html) +1. [CDNJS mirror list ](https://mirrorz.org/list/cdnjs) +1. [公共 CDN 静态资源加速服务 7ED Services ](https://www.7ed.net/start/public-cdn.html) +1. [中科大反向代理列表如下:](https://mirrors.ustc.edu.cn/) + +> ajax.googleapis.com ajax.proxy.ustclug.org + +> themes.googleusercontent.com google-themes.proxy.ustclug.org ## 匹配规则文档: diff --git a/extension/test/remove-csp-test.js b/extension/test/remove-csp-test.js index 970f885b..20652e17 100644 --- a/extension/test/remove-csp-test.js +++ b/extension/test/remove-csp-test.js @@ -15,7 +15,10 @@ //浏览器控制台执行代码, 检验移除CSP是否生效 (() => { let script = document.createElement("script"); - script.setAttribute("src", "https://frontend-inject.xieyaokun.com/main.js"), + script.setAttribute( + "src", + "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.146.0/three.module.min.js" + ), script.setAttribute("type", "application/javascript"), script.setAttribute("charset", "utf-8"), document.body.appendChild(script); @@ -25,7 +28,10 @@ javascript: (() => { let script = document.createElement("script"); - script.setAttribute("src", "https://frontend-inject.xieyaokun.com/main.js"), + script.setAttribute( + "src", + "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.146.0/three.module.min.js" + ), script.setAttribute("type", "application/javascript"), script.setAttribute("charset", "utf-8"), document.body.appendChild(script); diff --git a/extension/tools/download-chromium-extension.sh b/extension/tools/download-chromium-extension.sh new file mode 100644 index 00000000..1f7d4920 --- /dev/null +++ b/extension/tools/download-chromium-extension.sh @@ -0,0 +1,64 @@ +#!/bin/bash +set -exu + +__DIR__=$(cd "$(dirname "$0")";pwd) +cd ${__DIR__} + +if [ ! "$BASH_VERSION" ]; then + echo "Please do not use sh to run this script ($0), just execute it directly" 1>&2 + exit 1 +fi + +# 执行脚本命令 + +# bash extension/tools/download-chromium-extension.sh --proxy 1 + + +# 下载chromium 扩展,并解压 +# 例子 下载 谷歌翻译扩展 +# https://chrome.google.com/webstore/detail/google-translate/aapbdbdomjkkjkaonfhkkikfgjllcleb + + +# 参考文档: https://github.com/tonystark93/crx-download/blob/master/background.js +# 参考文档: https://www.cnblogs.com/jingjingxyk/p/16821342.html + +# `https://clients2.google.com/service/update2/crx?response=redirect&prodversion=${version}&acceptformat=crx2,crx3&x=id%3D${result[1]}%26uc&nacl_arch=${nacl_arch}`; + + +PROXY_URL=${2:+'http://127.0.0.1:8015'} + +export http_proxy=$PROXY_URL +export https_proxy=$PROXY_URL + +test -d temp && rm -rf temp +mkdir -p temp +cd ${__DIR__}/temp + + +extension_id=aapbdbdomjkkjkaonfhkkikfgjllcleb + +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' + +curl -Lo google-translate.crx $download_url + +unset http_proxy +unset https_proxy +unset no_proxy + + +# 使用不同的代理方式 +# proxychains curl -Lo google-translate.crx $download_url +# curl -x "socks5h://127.0.0.1:2000" -Lo google-translate.crx $download_url +# curl --proxy "socks5h://127.0.0.1:2000" -Lo google-translate.crx $download_url + +set +e +unzip -d google-translate google-translate.crx +set -e + +cd ${__DIR__}/ + +exit 0 + + + +test -d temp && rm -rf temp \ No newline at end of file diff --git a/extension/tools/web-server.sh b/extension/tools/web-server.sh new file mode 100644 index 00000000..2b3d3ebd --- /dev/null +++ b/extension/tools/web-server.sh @@ -0,0 +1,30 @@ +#!/bin/bash +set -exu + +__DIR__=$( + cd "$(dirname "$0")" + pwd +) +echo ${__DIR__} + + +__ROOT__=$(readlink -f ${__DIR__}/../../) +echo ${__ROOT__} + + +__WEB_DIR__=$( + cd ${__DIR__}/web/ + pwd +) +echo ${__WEB_DIR__} + + +cd ${__WEB_DIR__} + +# 用于 解决google 翻译不能用的 + +# 原理: https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Proxy_servers_and_tunneling/Proxy_Auto-Configuration_PAC_file + +cp -f proxy.js proxy.pac + +python3 -m http.server 8000 diff --git a/extension/tools/web/proxy.js b/extension/tools/web/proxy.js new file mode 100644 index 00000000..fe48e443 --- /dev/null +++ b/extension/tools/web/proxy.js @@ -0,0 +1,38 @@ +let proxy_domains = ["translate.googleapis.com"]; + +function encodeBase64(str) { + return btoa(encodeURIComponent(str)); +} + +function decodeBase64(encoded) { + return decodeURIComponent(atob(encoded)); +} + +function go_proxy(url, host) { + return proxy_domains.find((currentValue, index, arr) => { + if (host.indexOf(currentValue) !== -1) { + return true; + } + return undefined; + }, host); +} + +function FindProxyForURL(url, host) { + if (isPlainHostName(host)) { + return "DIRECT"; + } + if ( + isInNet(host, "192.168.0.0", "255.255.0.0") || + isInNet(host, "127.0.0.0", "255.0.0.0") || + isInNet(host, "10.0.0.0", "255.0.0.0") || + isInNet(host, "172.16.0.0", "255.240.0.0") + ) { + return "DIRECT"; + } + + if (go_proxy(url, host)) { + return "PROXY 127.0.0.1:8015; SOCKS5 127.0.0.1:2000; DIRECT"; + } + + return "DIRECT"; +}