Skip to content

Commit

Permalink
maxcdn.bootstrapcdn.com 替换为 lib.baomitu.com ;新增 code.jquery.com 域名下的…
Browse files Browse the repository at this point in the history
… jquery 替换 (#89)

* add func remove CSP

* 新增参考文档

* 添加测试用例

* 添加替换地址为指定服务地址功能,用于查看chromium源码

* add docker run nginx server

* 补上80端口配置

* add opensource.goole url

* add cs.opensource.google  url

* 使用自己架设的 nginx服务地址替换CDN地址

* change CSP variable name

* 添加固定替换CDN地址方法

* 替换指定数目的域名

* 添加测试用例

* 优化nginx 配置

* 优化nginx 配置二

* 优化nginx 配置三

* 优化nginx 配置增加简单权限验证阻止滥用

* 优化nginx 配置五

* 添加测试演示用例

* 添加测试演示用例

* 修改动态地址替换注释

* 修改错误的单词

* 移除与扩展无关的server文件

* 去除普通用户无关的测试脚本以及服务端搭建脚本

* 修改maxcdn.bootstrapcdn.com替换地址

* 替换code.jquery.com 为 ajax.aspnetcdn.com

* code.jquery.com 地址替换

* 1、增加域名替换白名单机制;2、两种地址替换方法,依靠优先级混合使用;3新增code.jquery.com域名下jquery 替换

* delete ytb

* 新增高级玩法

* 新增test service-worker

* change changelog

* add replace jquery-ui
  • Loading branch information
jingjingxyk authored May 5, 2022
1 parent dc8d859 commit 28166eb
Show file tree
Hide file tree
Showing 22 changed files with 439 additions and 63 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ server/conf.d
server/tls/*
!server/tls/.gitkeep
server/*
extension/_metadata/
extension/test/extension-v3-test/_metadata/

15 changes: 0 additions & 15 deletions CHANGELOG-0.1.0.md

This file was deleted.

29 changes: 29 additions & 0 deletions CHANGELOG-0.10.x.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# CHANGELOG


## CHANGELOG for 0.10.2
### 变更
>1. 新增test service-worker `sw.js` 小工具,解决因域名地址替换导致出现的问题;比如 github PJAX 错误
>2. 新增test service-worker `sw.js` 小工具中 `self-define-browser-editor.js` 浏览器当作记事本使用
>3. 新增test service-worker `sw.js` 小工具中 `tools/myscript-tools.js` 开启"上帝"模式,可编辑网页
>4. 新增test service-worker `sw.js` 小工具中 `tools/myscript-tools.js` 查看网页引入的所有域名
>5. 新增 `code.query.com` jquery 地址替换
>6. 解决 0.10.1 版本中 `第10,11条不能共用问题`
>7. 删除 0.10.1 版本中 高级玩法excludedInitiatorDomains错误配置 位于 `rules/rules_advance_redirect_2.json : "excludedInitiatorDomains":[] `
>8. maxcdn.bootstrapcdn.com 替换为 lib.baomitu.com

## CHANGELOG for 0.10.1 新增适配 chromium manifest v3版本
### 变更

>1. `manifest.json -> manifest-v2.json` (已复制保存)
>2. `background.js` 不再使用了
>3. `manifest.json: manifest_version -> 3`
>4. 新增 `chromium manifest v3 declarativeNetRequest rules `
>5. 新增 `v3 redirect url rule (rules/rules_redirect_1.json)`
>6. 新增 `v3 remove response header rule` 可以移除CSP选项 ` (rules/rules_remove_header_1.json)`
>7. 新增 `v3 append request header rule` 可向请求头添加内容 `(rules/rules_append_header_1.json)`
>8. 新增 `v3 block request header rule` 锁请求 `(rules/rules_block_1.json)`
>9. 新增 v3 固定替换地址 rule `(rules/rules_advance_redirect_1.json)`
>10. 新增 v3 动态替换地址 rule ` (rules/rules_advance_redirect_2.json)`
>11. 上述第9-10条不能同时使用,会产生冲突
10 changes: 6 additions & 4 deletions extension/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ let use_nginx_proxy = (details, proxy_provider) => {
return "https://" + dot_nums + '_' + host + proxy_provider + query_string;
}

//你的支持泛解析的域名
// 你的支持泛解析的域名
let suffix_domain = '.proxy.domain.com'

// 指定匹配域名
let need_replace_cdn_urls = [
'ajax.googleapis.com',
'fonts.googleapis.com',
Expand Down Expand Up @@ -210,8 +210,10 @@ chrome.webRequest.onBeforeRequest.addListener(
url = url.replace("secure.gravatar.com", "gravatar.loli.net");
url = url.replace("www.gravatar.com", "gravatar.loli.net");
url = url.replace(
"maxcdn.bootstrapcdn.com/bootstrap/",
"cdn.bootcdn.net/ajax/libs/twitter-bootstrap/"
/maxcdn\.bootstrapcdn\.com\/bootstrap\/(\d{1,4}\.\d{1,4}\.\d{1,4})\/(.*?)/g,
//"cdn.bootcdn.net/ajax/libs/twitter-bootstrap/"
//"cdn.jsdelivr.net/npm/bootstrap@$1/dist/$2"
"lib.baomitu.com/twitter-bootstrap/$1/$2"
);
return { redirectUrl: url };
},
Expand Down
5 changes: 5 additions & 0 deletions extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
"enabled": true,
"path": "rules/rules_redirect_1.json"
},
{
"id": "ruleset_jquery_redirect_1",
"enabled": true,
"path": "rules/rules-code-jquery-redirect.json"
},
{
"id": "ruleset_remove_header_1",
"enabled": true,
Expand Down
31 changes: 28 additions & 3 deletions extension/rules/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
# manifest.json declarative_net_reques 配置示例

## 网络拨测工具 测试 公共 CDN 静态资源库 区域可用性
1. [网络拨测工具](https://zijian.aliyun.com/detect/http)
2. [网站诊断分析工具](https://zijian.aliyun.com/)


## 公共 CDN 静态资源库

1. [360 奇舞团](https://cdn.baomitu.com/)
2. [又拍云](http://jscdn.upai.com/)
3. [BootCDN](https://www.bootcdn.cn/)
4. [字节跳动静态资源公共库](http://cdn.bytedance.com/)
5. [Microsoft Ajax Content Delivery Network](https://docs.microsoft.com/en-us/aspnet/ajax/cdn/overview)
6. [jsdelivr](https://www.jsdelivr.com/)
7. [unpkg](https://unpkg.com/)
8. [cloudflare ](https://cdnjs.com/)
9. [google libraries](https://developers.google.com/speed/libraries)



## 高级玩法
> 使用时,请把 proxy.domain.com 更换为你自己的域名
> 固定地址替换 rules_advance_redirect_1.json
> 动态地址替换 rules_advance_redirect_2.json
> 移除CSP rules_remove_header_1.json

Expand Down Expand Up @@ -39,7 +59,9 @@
```

### 指定匹配域名
> github.com -> github-com.proxy.domain.com

> https://github.com -> https://github-com.proxy.domain.com
```json

{
Expand All @@ -50,7 +72,8 @@

```
## 动态匹配域名
> www.google.com -> https://2_www_xn--3px_google_xn--3px_com.proxy.domain.com/

> https://www.chromium.org/ -> https://2_www_xn--3px_chromium_xn--3px_org.proxy.domain.com/
```json
{
Expand All @@ -69,4 +92,6 @@
"path": "rules/rules_block_1.json"
}

```
```


42 changes: 42 additions & 0 deletions extension/rules/rules-code-jquery-redirect.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[
{
"id": 1,
"priority": 99,
"action": {
"type": "redirect",
"redirect": {
"regexSubstitution": "lib.baomitu.com/jquery/\\1/jquery\\2"
}
},
"condition": {
"regexFilter": "code.jquery.com/jquery-(\\d{1,4}\\.\\d{1,4}\\.\\d{1,4})(.*?)",
"requestDomains":[
"code.jquery.com"
],
"resourceTypes": [
"main_frame", "sub_frame", "stylesheet", "script", "image", "font",
"object", "xmlhttprequest", "ping", "csp_report", "media", "websocket",
"webtransport", "webbundle", "other"
] }
},
{
"id": 2,
"priority": 99,
"action": {
"type": "redirect",
"redirect": {
"regexSubstitution": "ajax.aspnetcdn.com/ajax/jquery.ui/\\1/\\2"
}
},
"condition": {
"regexFilter": "code.jquery.com/ui/(\\d{1,4}\\.\\d{1,4}\\.\\d{1,4})/(.*?)",
"requestDomains":[
"code.jquery.com"
],
"resourceTypes": [
"main_frame", "sub_frame", "stylesheet", "script", "image", "font",
"object", "xmlhttprequest", "ping", "csp_report", "media", "websocket",
"webtransport", "webbundle", "other"
] }
}
]
4 changes: 2 additions & 2 deletions extension/rules/rules_advance_redirect_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
"id": 1,
"priority": 2,
"note": "符合条件的请求都添加一个认证 token ,用于阻止滥用,没有权限认证,一定会被滥用",
"action": {
"type": "modifyHeaders",
"requestHeaders": [
Expand Down Expand Up @@ -61,8 +62,7 @@
"ssl.gstatic.com",
"www.gstatic.com",
"secure.gravatar.com",
"maxcdn.bootstrapcdn.com",
"www.google.com"
"maxcdn.bootstrapcdn.com"
],
"resourceTypes": [
"main_frame", "sub_frame", "stylesheet", "script", "image", "font",
Expand Down
21 changes: 11 additions & 10 deletions extension/rules/rules_advance_redirect_2.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
"id": 1,
"priority": 2,
"note": "符合条件的请求都添加一个认证 token ,用于阻止滥用,没有权限认证,一定会被滥用",
"action": {
"type": "modifyHeaders",
"requestHeaders": [
Expand Down Expand Up @@ -29,8 +30,8 @@
"condition": {
"regexFilter": "^https://([\\w|-]+?)\\.(\\w+?)/(.*?)",
"requireCapturing": true,
"excludedInitiatorDomains":[
"proxy.domain.com"
"requestDomains":[
"example.com"
],
"excludedRequestDomains":[
"proxy.domain.com"
Expand All @@ -53,8 +54,8 @@
},
"condition": {
"regexFilter": "^https://([\\w|-]+?)\\.([\\w|-]+?)\\.(\\w+?)/(.*?)",
"excludedInitiatorDomains":[
"proxy.domain.com"
"requestDomains":[
"example.com"
],
"excludedRequestDomains":[
"proxy.domain.com"
Expand All @@ -77,8 +78,8 @@
},
"condition": {
"regexFilter": "^https://([\\w|-]+?)\\.([\\w|-]+?)\\.([\\w|-]+?)\\.(\\w+?)/(.*?)",
"excludedInitiatorDomains":[
"proxy.domain.com"
"requestDomains":[
"example.com"
],
"excludedRequestDomains":[
"proxy.domain.com"
Expand All @@ -101,8 +102,8 @@
},
"condition": {
"regexFilter": "^https://([\\w|-]+?)\\.([\\w|-]+?)\\.([\\w|-]+?)\\.([\\w|-]+?)\\.(\\w+?)/(.*?)",
"excludedInitiatorDomains":[
"proxy.domain.com"
"requestDomains":[
"example.com"
],
"excludedRequestDomains":[
"proxy.domain.com"
Expand All @@ -125,8 +126,8 @@
},
"condition": {
"regexFilter": "^https://([\\w|-]+?)\\.([\\w|-]+?)\\.([\\w|-]+?)\\.([\\w|-]+?)\\.([\\w|-]+?)\\.(\\w+?)/(.*?)",
"excludedInitiatorDomains":[
"proxy.domain.com"
"requestDomains":[
"example.com"
],
"excludedRequestDomains":[
"proxy.domain.com"
Expand Down
4 changes: 2 additions & 2 deletions extension/rules/rules_redirect_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@
"action": {
"type": "redirect",
"redirect": {
"regexSubstitution": "cdn.bootcdn.net/ajax/libs/bootstrap/\\1"
"regexSubstitution" : "lib.baomitu.com/twitter-bootstrap/\\1/\\2"
}
},
"condition": {
"regexFilter": "maxcdn.bootstrapcdn.com/bootstrap/(.*?)",
"regexFilter": "maxcdn.bootstrapcdn.com/bootstrap/(\\d{1,4}\\.\\d{1,4}\\.\\d{1,4})/(.*?)",
"resourceTypes": [
"main_frame", "sub_frame", "stylesheet", "script", "image", "font",
"object", "xmlhttprequest", "ping", "csp_report", "media", "websocket",
Expand Down
2 changes: 1 addition & 1 deletion extension/test/extension-v3-test/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## chromium extension v3

> 一个完整的 测试
# 修改 manifest.json 文件测试配置,结果如下:
```text
Expand Down
16 changes: 16 additions & 0 deletions extension/test/extension-v3-test/css/my.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
自定义样式
*/




/*
一句话网页变灰 -css
*/

/*
html { filter: grayscale(100%); }
*/
3 changes: 3 additions & 0 deletions extension/test/extension-v3-test/js/myscript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"use strict"

console.log('注入js,css 代码',window.location)
51 changes: 51 additions & 0 deletions extension/test/extension-v3-test/js/sw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

// * chrome - the global namespace for Chrome's extension APIs
// * runtime – the namespace of the specific API we want to use
// * onInstalled - the event we want to subscribe to
// * addListener - what we want to do with this event

chrome.runtime.onInstalled.addListener(async () => {
console.log( "onInstalled do nothing ")
console.log(chrome.runtime.getURL("js/sw.js"))
console.log(chrome.runtime.getURL("js/myscript.js"))
console.log(chrome.runtime.getURL("js/tools/self-define-browser-editor.js"))
console.log(chrome.runtime.getURL("js/tools/myscript-tools.js"))

});

chrome.tabs.onUpdated.addListener( (tabId, changeInfo, tab) => {
console.log( "oonUpdated do nothing ")

if (changeInfo.status === 'complete' && /^http/.test(tab.url)) {

// 注入JS 或者CSS 解决 PJAX 不可用问题等问题
console.log(tab.url)
try{
chrome.scripting.executeScript(
{
target: {tabId: tabId},
files: ["js/myscript.js"]
},
(injectionResults=null) => {

}
)
chrome.scripting.insertCSS(
{
target: {tabId: tabId},
files: ["css/my.css"]
},
(injectionResults=null) => {

}
)
}catch(error){
console.log(error)
}finally {
if (chrome.runtime.lastError) {
message.innerText = 'There was an error : \n' + chrome.runtime.lastError.message;
}
}
}

});
Loading

0 comments on commit 28166eb

Please sign in to comment.