Skip to content

Commit ff20e2e

Browse files
committed
feat: 添加对 leetcode.cn 域名的支持
1 parent 6e2d081 commit ff20e2e

File tree

6 files changed

+17
-15
lines changed

6 files changed

+17
-15
lines changed

public/manifest-dev.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"128": "icons/icon-128.png"
1010
},
1111
"content_security_policy": {
12-
"extension_pages": "default-src 'self' http://localhost:9100; script-src 'self' http://localhost:9100; script-src-elem 'self' http://localhost:9100; style-src 'self' 'unsafe-inline'; connect-src 'self' ws://localhost:9100 http://localhost:9100 https://leetcode-rating-predictor.herokuapp.com https://leetcode-predictor.herokuapp.com https://leetcode-cn.com"
12+
"extension_pages": "default-src 'self' http://localhost:9100; script-src 'self' http://localhost:9100; script-src-elem 'self' http://localhost:9100; style-src 'self' 'unsafe-inline'; connect-src 'self' ws://localhost:9100 http://localhost:9100 https://leetcode-rating-predictor.herokuapp.com https://leetcode-predictor.herokuapp.com https://leetcode-cn.com https://leetcode.cn"
1313
},
1414
"permissions": ["scripting"],
1515
"web_accessible_resources": [
@@ -21,23 +21,24 @@
2121
"/*.map",
2222
"/file-icons/*.svg"
2323
],
24-
"matches": ["*://leetcode-cn.com/*"]
24+
"matches": ["*://leetcode-cn.com/*", "*://leetcode.cn/*"]
2525
}
2626
],
2727
"host_permissions": [
2828
"https://leetcode-cn.com/*",
29+
"https://leetcode.cn/*",
2930
"http://localhost:9100/*",
3031
"https://leetcode-rating-predictor.herokuapp.com/*",
3132
"https://leetcode-predictor.herokuapp.com/*"
3233
],
3334
"content_scripts": [
3435
{
35-
"matches": ["https://leetcode-cn.com/*"],
36+
"matches": ["https://leetcode-cn.com/*", "https://leetcode.cn/*"],
3637
"js": ["content-load.bundle.js"]
3738
}
3839
],
3940
"background": { "service_worker": "background.bundle.js" },
4041
"externally_connectable": {
41-
"matches": ["https://leetcode-cn.com/*"]
42+
"matches": ["https://leetcode-cn.com/*", "https://leetcode.cn/*"]
4243
}
4344
}

public/manifest.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,29 @@
99
"128": "icons/icon-128.png"
1010
},
1111
"content_security_policy": {
12-
"extension_pages": "default-src 'self'; script-src 'self'; script-src-elem 'self'; style-src 'self' 'unsafe-inline'; connect-src 'self' https://leetcode-rating-predictor.herokuapp.com https://leetcode-predictor.herokuapp.com https://leetcode-cn.com"
12+
"extension_pages": "default-src 'self'; script-src 'self'; script-src-elem 'self'; style-src 'self' 'unsafe-inline'; connect-src 'self' https://leetcode-rating-predictor.herokuapp.com https://leetcode-predictor.herokuapp.com https://leetcode-cn.com https://leetcode.cn"
1313
},
1414
"permissions": [],
1515
"web_accessible_resources": [
1616
{
1717
"resources": ["/content.bundle.js", "/*.map", "/file-icons/*.svg"],
18-
"matches": ["*://leetcode-cn.com/*"]
18+
"matches": ["*://leetcode-cn.com/*", "*://leetcode.cn/*"]
1919
}
2020
],
2121
"host_permissions": [
2222
"https://leetcode-cn.com/*",
23+
"https://leetcode.cn/*",
2324
"https://leetcode-rating-predictor.herokuapp.com/*",
2425
"https://leetcode-predictor.herokuapp.com/*"
2526
],
2627
"content_scripts": [
2728
{
28-
"matches": ["https://leetcode-cn.com/*"],
29+
"matches": ["https://leetcode-cn.com/*", "https://leetcode.cn/*"],
2930
"js": ["content-load.bundle.js"]
3031
}
3132
],
3233
"background": { "service_worker": "background.bundle.js" },
3334
"externally_connectable": {
34-
"matches": ["https://leetcode-cn.com/*"]
35+
"matches": ["https://leetcode-cn.com/*", "https://leetcode.cn/*"]
3536
}
3637
}

src/background/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export async function getContest(
5858
region: 'local' | 'global' = 'local',
5959
retry = 1
6060
): Promise<RankingDataType> {
61-
const url = `https://leetcode-cn.com/contest/api/ranking/${contestId}/?pagination=${page}&region=${region}`
61+
const url = `https://leetcode.com/contest/api/ranking/${contestId}/?pagination=${page}&region=${region}`
6262
const res = await fetch(url)
6363
if (res.status === 200) {
6464
return res.json()
@@ -71,7 +71,7 @@ export async function getMyRanking(
7171
contestId: string,
7272
retry = 1
7373
): Promise<MyRankingType> {
74-
const url = `https://leetcode-cn.com/contest/api/myranking/${contestId}/`
74+
const url = `https://leetcode.com/contest/api/myranking/${contestId}/`
7575
const res = await fetch(url)
7676

7777
if (res.status === 200) return res.json()

src/content/pages/problems/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ async function load() {
2222
}
2323
}
2424

25-
if (/https:\/\/leetcode-cn\.com\/problems\//.test(location.href)) {
25+
if (/\/problems\//.test(location.pathname)) {
2626
load()
2727
}

src/content/pages/problems/leetcode-api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ class LeetCodeApi {
364364
runtimeDistribution?: { lang: string; distribution: [string, number][] }
365365
memoryDistribution?: { lang: string; distribution: [string, number][] }
366366
}> {
367-
if (/leetcode-cn\.com/.test(this.REGION_URL)) {
367+
if (/(leetcode-cn\.com)|(leetcode\.cn)/.test(this.REGION_URL)) {
368368
const data = await this.getSubmissionDetailByLocal(submissionId)
369369
const { runtimeDistribution, memoryDistribution } =
370370
await this.getDistributionLocal(submissionId)

src/content/pages/ranking/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ async function changeCompleted() {
103103
})
104104
}
105105

106-
const urlMatchReg = /https:\/\/leetcode-cn\.com\/contest\/([\d\D]+)\/ranking\//
106+
const urlMatchReg = /\/contest\/([\d\D]+)\/ranking\//
107107

108-
if (urlMatchReg.test(location.href)) {
108+
if (urlMatchReg.test(location.pathname)) {
109109
loadPredictor()
110110
loadFileIcon()
111111
}
@@ -126,7 +126,7 @@ window.addEventListener('urlchange', async function () {
126126
* 而第三第四种清理可以不用处理
127127
*/
128128

129-
if (!urlMatchReg.test(location.href)) {
129+
if (!urlMatchReg.test(location.pathname)) {
130130
// 从排名页跳转到比赛主页
131131

132132
// 卸载已加载的 node

0 commit comments

Comments
 (0)