Skip to content

Commit

Permalink
fix code format bug (#200)
Browse files Browse the repository at this point in the history
* update README.md

* tset

* test

* test

* update

* 使用.editorconfig 指定code格式化规则

* 调整表述

* update
  • Loading branch information
jingjingxyk authored Dec 6, 2023
1 parent ae1743f commit 2a6fa7e
Show file tree
Hide file tree
Showing 37 changed files with 1,362 additions and 1,245 deletions.
34 changes: 34 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# EditorConfig is awesome: https://EditorConfig.org
# https://github.com/editorconfig/editorconfig/wiki/Projects-Using-EditorConfig

root = true

[*]
insert_final_newline = true
charset = utf-8
trim_trailing_whitespace = true
end_of_line = lf

[*.{js,json,ts,tsx,yml,yaml}]
indent_style = space
indent_size = 2

# 4 space indentation
[*.py]
indent_style = space
indent_size = 4

[Makefile]
indent_style = tab

[*.{md,markdown,txt}]
trim_trailing_whitespace = false
indent_style = space
indent_size = 4

[*.md]
max_line_length = 120

[*.{html,xml}]
indent_size = 4
indent_style = space
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"trailingComma": "none"
}
2 changes: 1 addition & 1 deletion CHANGELOG-v3-x.x.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## CHANGELOG for v3 0.10.32 [2023-12-05 15:01:00 +0800]

> 1. 新增: 创建 文档目录 `docs`
> 1. 变更: 将辅助工具到扩展目录外
> 1. 变更: 将辅助工具迁移到扩展目录外
> 1. 变更: 将高级功能脚本、规则移动到 `experimental-features` 目录 , 部分实验脚本迁移到 [extension-v3-test](https://github.com/jingjingxyk/extension-v3-test.git) 仓库
## CHANGELOG for v3 0.10.31 [2023-12-02 22:01:00 +0800]
Expand Down
54 changes: 22 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,29 @@

> 借助浏览器提供的API,实现请求地址重定向。
>
> - [浏览器 V2 API](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/webRequest)
> - [浏览器 V3 API](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/declarativeNetRequest)
> - [浏览器 V2 API](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/webRequest)
> - [浏览器 V3 API](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/declarativeNetRequest)
>
> 默认未启用的规则, 如需启用请到扩展选项页自行打开
此插件/扩展可以将以下的 CDN 资源替换为国内的:

1. `ajax.googleapis.com` - 前端公共库,替换为 `ajax.loli.net`
1. `fonts.googleapis.com` - 免费字体库,替换为 `fonts.googleapis.cn`
1. `themes.googleusercontent.com` - fonts 有时会使用到这个里面的资源,替换为
`themes.loli.net`
1. `themes.googleusercontent.com` - fonts 有时会使用到这个里面的资源,替换为`themes.loli.net`
1. `fonts.gstatic.com` - 免费字体库,替换为 `fonts.gstatic.cn`
1. `www.google.com/recaptcha` - Google 图像验证库,替换为
`www.recaptcha.net/recaptcha`
1. `www.google.com/recaptcha` - Google 图像验证库,替换为`www.recaptcha.net/recaptcha`
1. `secure.gravatar.com` - gravatar 头像,替换为 `gravatar.loli.net`
1. `maxcdn.bootstrapcdn.com/bootstrap` - bootstrap 框架使用的 CDN,替换为
`lib.baomitu.com/twitter-bootstrap/`
1. `code.jquery.com/jquery-(version)(suffix)` - jquery 框架使用的 CDN,替换为
`https://fastly.jsdelivr.net/npm/jquery@$verson/dist/jquery$suffix`
1. `cdnjs.cloudflare.com` - 替换为 `cdnjs.loli.net` 默认未启用,
如需启用请到扩展选项页自行打开
1. `maxcdn.bootstrapcdn.com/bootstrap` - bootstrap 框架使用的 CDN,替换为`lib.baomitu.com/twitter-bootstrap/`
1. `code.jquery.com/jquery-(version)(suffix)` - jquery 框架使用的 CDN,替换为`https://fastly.jsdelivr.net/npm/jquery@$verson/dist/jquery$suffix`
1. `cdnjs.cloudflare.com` - 替换为 `cdnjs.loli.net` 默认未启用, 如需启用请到扩展选项页自行打开
1. `cdn.jsdelivr.net` - 替换为 `fastly.jsdelivr.net`
1. `developers.google.com` - 替换为 `developers.google.cn` 默认未启用,
如需启用请到扩展选项页自行打开
1. `developer.android.com` - 替换为 `developer.android.google.cn` 默认未启用,
如需启用请到扩展选项页自行打开
1. `source.android.com` - 替换为 `source.android.google.cn` 默认未启用,
如需启用请到扩展选项页自行打开
1. `www.gstatic.com` - 替换为 `www.gstatic.cn` 默认未启用,
如需启用请到扩展选项页自行打开
1. `developers.google.com` - 替换为 `developers.google.cn` 默认未启用, 如需启用请到扩展选项页自行打开
1. `developer.android.com` - 替换为 `developer.android.google.cn` 默认未启用, 如需启用请到扩展选项页自行打开
1. `source.android.com` - 替换为 `source.android.google.cn` 默认未启用, 如需启用请到扩展选项页自行打开
1. `www.gstatic.com` - 替换为 `www.gstatic.cn` 默认未启用, 如需启用请到扩展选项页自行打开
1. `lh3.googleusercontent.com` 默认未启用, 如需启用请到扩展选项页自行打开
1. `cdn.sstatic.net`- 替换为 `sstatic.net` 默认未启用,
如需启用请到扩展选项页自行打开
1. `cdn.sstatic.net`- 替换为 `sstatic.net` 默认未启用,如需启用请到扩展选项页自行打开

## 扩展选项页使用简述

Expand All @@ -61,8 +51,8 @@

## 功能变更记录

- v3 功能变更记录[`CHANGELOG-v3-x.x.x`](CHANGELOG-v3-x.x.x.md)
- v2 功能变更记录[`CHANGELOG-v2-x.x.x`](CHANGELOG-v2-x.x.x.md)
- v3 功能变更记录[`CHANGELOG-v3-x.x.x`](CHANGELOG-v3-x.x.x.md)
- v2 功能变更记录[`CHANGELOG-v2-x.x.x`](CHANGELOG-v2-x.x.x.md)

## 效果

Expand All @@ -81,7 +71,7 @@
| ------------------------ | ------------------------------ | -------: | -------: | ---------: | -------: |
| jquery.min.js | ajax.googleapis.com | 0 | 26 | - | - |
| stub.en.js | cdn.sstatic.net | 18.0 | 293 | 61.4 | 18% |
| **jquery.min.js** | **ajax.loli.net** ⚡️ | **33.1** | **95** | **348.4** | **100%** |
| **jquery.min.js** | **ajax.loli.net** ⚡️ | **33.1** | **95** | **348.4** | **100%** |
| clc.min.js | cdn.sstatic.net | 4.2 | 399 | 10.5 | 30% |
| full.en.js | cdn.sstatic.net | 99.6 | 534 | 186.5 | 54% |
| gpt.js | securepubads.g.doubleclick.net | 21.3 | 85 | 250.6 | 72% |
Expand Down Expand Up @@ -114,9 +104,9 @@ bash release-archive-v3.sh

### 在线安装

- [Chrome](https://chrome.google.com/webstore/detail/replace-google-cdn/kpampjmfiopfpkkepbllemkibefkiice)
- [Firefox](https://addons.mozilla.org/zh-CN/firefox/addon/google-cdn-replace/)
- [Edge](https://microsoftedge.microsoft.com/addons/detail/replace-google-cdn/cojepngjobmaiajphkijbdcdjnnjhpjc)
- [Chrome](https://chrome.google.com/webstore/detail/replace-google-cdn/kpampjmfiopfpkkepbllemkibefkiice)
- [Firefox](https://addons.mozilla.org/zh-CN/firefox/addon/google-cdn-replace/)
- [Edge](https://microsoftedge.microsoft.com/addons/detail/replace-google-cdn/cojepngjobmaiajphkijbdcdjnnjhpjc)

### 手动安装:

Expand Down Expand Up @@ -175,7 +165,7 @@ https://www.jingjingxyk.com/chromium-extension/ReplaceGoogleCDN-v3.zip

## 文档

- [declarative_net_reques 规则配置示例](extension/rules/README.md)
- [测试用例](test/README.md)
- [公共 CDN 静态资源库](public-cdn.md)
- [网络拨测工具 (测试 公共 CDN 静态资源库 区域可用性)](tools/net-detect.md)
- [declarative_net_reques 规则配置示例](extension/rules/README.md)
- [测试用例](test/README.md)
- [公共 CDN 静态资源库](public-cdn.md)
- [网络拨测工具 (测试 公共 CDN 静态资源库 区域可用性)](tools/net-detect.md)
8 changes: 3 additions & 5 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
## v2 版本 与 v3 最大的区别:

> V2 版本允许使用 javascript 脚本 动态修改 HTTP请求的 请求头 和 响应头 ,V3
> 版本禁止使用
>
> V3 使用声明式规则 实现 对HTTP请求的 请求头 和 响应头的修改,不支持使用
> javascript 动态修改
> V2 版本允许使用 javascript 脚本 动态修改 HTTP请求的 请求头 和 响应头
> V3 使用声明式规则 实现 对HTTP请求的 请求头 和 响应头的修改,不支持使用 javascript 动态修改
## 浏览器 V2 API

Expand Down
2 changes: 1 addition & 1 deletion docs/advanced/README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#
#
4 changes: 2 additions & 2 deletions docs/tools/tools.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# 工具介绍

##
##

##
##
2 changes: 1 addition & 1 deletion experimental-features/READEM.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# 试验特性介绍

##
##
32 changes: 16 additions & 16 deletions experimental-features/v2/js/background-advance.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const remove_csp_item = [
"cross-origin-embedder-policy",
"cross-origin-opener-policy",
"cross-origin-opener-policy-report-only",
"cross-origin-embedder-policy-report-only",
"cross-origin-embedder-policy-report-only"
];

/**
Expand All @@ -70,7 +70,7 @@ const remove_csp_urls = [
"*://developers.redhat.com/*",
"*://*.githubusercontent.com/*",
"*://pub.dev/*",
"*://stackoverflow.com/*",
"*://stackoverflow.com/*"
];

//console.log(chrome.app.getDetails().version);
Expand All @@ -94,7 +94,7 @@ let web_request_resource_types = [
"other",
"csp_report",
"media",
"websocket",
"websocket"
];

if (chrome_ersion < 58) {
Expand All @@ -109,7 +109,7 @@ if (chrome_ersion < 58) {
"object",
"xmlhttprequest",
"ping",
"other",
"other"
];
}

Expand Down Expand Up @@ -144,15 +144,15 @@ chrome.webRequest.onHeadersReceived.addListener(
*/

return {
responseHeaders: details.responseHeaders,
responseHeaders: details.responseHeaders
};
},
{
// urls: ["<all_urls>"],
urls: [
...remove_csp_urls, //需要移除CSP自己添加url
...remove_csp_urls //需要移除CSP自己添加url
],
types: web_request_resource_types,
types: web_request_resource_types
},
["blocking", "responseHeaders"]
);
Expand Down Expand Up @@ -225,7 +225,7 @@ let opensource_google_urls = [
let test_urls = [
...opensource_google_urls,
"*://*.google.com/*",
"*://github.com/*",
"*://github.com/*"
];

/**
Expand Down Expand Up @@ -257,7 +257,7 @@ let block_domains = [
"example-example.com",
"test1-example.com",
"test2-example.com",
"test3-example.com",
"test3-example.com"
];
let block_domain_urls = [];
block_domains.forEach((value, index, array) => {
Expand Down Expand Up @@ -364,8 +364,8 @@ chrome.webRequest.onBeforeRequest.addListener(
"*://source.android.com/*",
"*://www.gstatic.com/*",
//...test_urls, // 高级玩法的测试用例
...block_domain_urls, //阻止域名请求
],
...block_domain_urls //阻止域名请求
]
},
["blocking"]
);
Expand Down Expand Up @@ -449,15 +449,15 @@ chrome.webRequest.onBeforeSendHeaders.addListener(
if (urlObj.host.indexOf("proxy.xiaoshuogeng.com") !== -1) {
details.requestHeaders.push({
name: "x-user-id",
value: "8feed7c8-fe26-11ec-acc8-d34ecdbd4e54",
value: "8feed7c8-fe26-11ec-acc8-d34ecdbd4e54"
});
details.requestHeaders.push({
name: "x-auth-token",
value: "89b71a78-fe26-11ec-a410-9f2dc97caf21",
value: "89b71a78-fe26-11ec-a410-9f2dc97caf21"
});
details.requestHeaders.push({
name: "x-permissions-id",
value: "b5c7d018-fe2a-11ec-9cc1-ab39db39504a",
value: "b5c7d018-fe2a-11ec-9cc1-ab39db39504a"
});
}
//console.log(details.requestHeaders)
Expand All @@ -467,8 +467,8 @@ chrome.webRequest.onBeforeSendHeaders.addListener(
urls: [
//"*://*.baidu.com/*", //例子 移除请求头携带的cookie和修改User-Agent
//"*://*.proxy.xiaoshuogeng.com/*", // 高级玩法的测试用例
"*://example-example.com/*",
],
"*://example-example.com/*"
]
},
["blocking", "requestHeaders"]
//["blocking", "requestHeaders", "extraHeaders"]
Expand Down
10 changes: 5 additions & 5 deletions experimental-features/v2/test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

## 高级玩法测试例子

- https://gerrit.googlesource.com/gerrit
- https://www.chromium.org
- https://chromium.googlesource.com/
- https://source.chromium.org/chromium
- https://cs.opensource.google/
- https://gerrit.googlesource.com/gerrit
- https://www.chromium.org
- https://chromium.googlesource.com/
- https://source.chromium.org/chromium
- https://cs.opensource.google/

### 让 XP 系统下的 chrome 49 能使用本扩展

Expand Down
24 changes: 12 additions & 12 deletions experimental-features/v3/rules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
```json
{
"id": "ruleset_advance_redirect_1",
"enabled": true,
"path": "rules/advance/rules_advance_redirect_1.json"
"id": "ruleset_advance_redirect_1",
"enabled": true,
"path": "rules/advance/rules_advance_redirect_1.json"
}
```

Expand All @@ -32,28 +32,28 @@
```json
{
"id": "ruleset_advance_redirect_2",
"enabled": true,
"path": "rules/advance/rules_advance_redirect_2.json"
"id": "ruleset_advance_redirect_2",
"enabled": true,
"path": "rules/advance/rules_advance_redirect_2.json"
}
```

### 阻止指定域名 (拦截请求)

```json
{
"id": "ruleset_block_header_1",
"enabled": true,
"path": "rules/rules_block_request.json"
"id": "ruleset_block_header_1",
"enabled": true,
"path": "rules/rules_block_request.json"
}
```

### 修改 http 请求头或者响应头

```json
{
"id": "ruleset_remove_header_1",
"enabled": true,
"path": "rules/rules_append_header_1.json"
"id": "ruleset_remove_header_1",
"enabled": true,
"path": "rules/rules_append_header_1.json"
}
```
12 changes: 6 additions & 6 deletions extension-v2/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ chrome.webRequest.onHeadersReceived.addListener(
!remove_csp_item.includes(response_header.name.toLowerCase())
);
return {
responseHeaders: details.responseHeaders,
responseHeaders: details.responseHeaders
};
},
{
// urls: ["<all_urls>"],
urls: [
...remove_csp_urls, //需要移除 Content-Security-Policy 的URL地址
...remove_csp_urls //需要移除 Content-Security-Policy 的URL地址
],
types: [
"main_frame",
Expand All @@ -75,8 +75,8 @@ chrome.webRequest.onHeadersReceived.addListener(
"object",
"xmlhttprequest",
"ping",
"other",
],
"other"
]
},
["blocking", "responseHeaders"]
);
Expand Down Expand Up @@ -134,8 +134,8 @@ chrome.webRequest.onBeforeRequest.addListener(
"*://maxcdn.bootstrapcdn.com/bootstrap/*",
"*://cdn.jsdelivr.net/*",
"*://code.jquery.com/jquery-*",
"*://code.jquery.com/ui/*",
],
"*://code.jquery.com/ui/*"
]
},
["blocking"]
);
Loading

0 comments on commit 2a6fa7e

Please sign in to comment.