Skip to content

Commit 7b321a8

Browse files
committed
feat: simplify URL configuration for time limit rules (#424)
1 parent 0fc3d74 commit 7b321a8

File tree

30 files changed

+641
-887
lines changed

30 files changed

+641
-887
lines changed

.github/workflows/end-to-end-tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ jobs:
1212
- name: Install dependencies
1313
run: npm install
1414
- name: Install http-server
15-
run: npm install -g http-server
15+
run: npm install -g http-server pm2
1616
- name: Build e2e outputs
1717
run: npm run dev:e2e
1818
- name: Build production outputs
1919
run: npm run build
2020

2121
- name: Start up mock server
2222
run: |
23-
nohup http-server ./test-e2e/example -p 12345 -s > test.log 2>&1 &
24-
nohup http-server ./test-e2e/example -p 12346 -s > test.log 2>&1 &
23+
pm2 start 'http-server ./test-e2e/example -p 12345'
24+
pm2 start 'http-server ./test-e2e/example -p 12346'
2525
2626
- name: Run tests
2727
env:

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"rtlcss",
4141
"selectchanged",
4242
"sheepzh",
43+
"subpages",
4344
"Treemap",
4445
"Vnode",
4546
"vueuse",

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
"@babel/plugin-transform-modules-commonjs": "^7.26.3",
3232
"@babel/preset-env": "^7.26.9",
3333
"@crowdin/crowdin-api-client": "^1.42.0",
34-
"@rsdoctor/webpack-plugin": "^1.0.1",
35-
"@swc/core": "^1.11.20",
34+
"@rsdoctor/webpack-plugin": "^1.0.2",
35+
"@swc/core": "^1.11.21",
3636
"@swc/jest": "^0.2.37",
3737
"@types/chrome": "0.0.315",
3838
"@types/decompress": "^4.2.7",
@@ -47,7 +47,7 @@
4747
"copy-webpack-plugin": "^13.0.0",
4848
"css-loader": "^7.1.2",
4949
"decompress": "^4.2.1",
50-
"eslint": "^9.24.0",
50+
"eslint": "^9.25.0",
5151
"filemanager-webpack-plugin": "^8.0.0",
5252
"generate-json-webpack-plugin": "^2.0.0",
5353
"html-webpack-plugin": "^5.6.3",
@@ -69,15 +69,15 @@
6969
"typescript": "5.8.3",
7070
"url-loader": "^4.1.1",
7171
"web-ext": "^8.5.0",
72-
"webpack": "^5.99.5",
72+
"webpack": "^5.99.6",
7373
"webpack-cli": "^6.0.1"
7474
},
7575
"dependencies": {
7676
"@element-plus/icons-vue": "^2.3.1",
7777
"@vueuse/core": "^13.1.0",
7878
"countup.js": "^2.8.0",
7979
"echarts": "^5.6.0",
80-
"element-plus": "2.9.7",
80+
"element-plus": "2.9.8",
8181
"js-base64": "^3.7.7",
8282
"punycode": "^2.3.1",
8383
"stream-browserify": "^3.0.0",

src/background/migrator/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { type Migrator } from "./common"
1111
import HostMergeInitializer from "./host-merge-initializer"
1212
import LocalFileInitializer from "./local-file-initializer"
1313
import WhitelistInitializer from "./whitelist-initializer"
14+
import LimitRuleMigrator from "./limit-rule-migrator"
1415

1516
/**
1617
* Version manager
@@ -26,6 +27,7 @@ class VersionManager {
2627
new LocalFileInitializer(),
2728
new WhitelistInitializer(),
2829
new CateInitializer(),
30+
new LimitRuleMigrator(),
2931
)
3032
}
3133

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import limitService from "@service/limit-service"
2+
import { cleanCond } from "@util/limit"
3+
import type { Migrator } from "./common"
4+
5+
export default class LimitRuleMigrator implements Migrator {
6+
onInstall(): void {
7+
}
8+
9+
async onUpdate(_version: string): Promise<void> {
10+
const rules = await limitService.select()
11+
if (!rules?.length) return
12+
const needUpdate: timer.limit.Rule[] = []
13+
const needRemoved: timer.limit.Rule[] = []
14+
rules.forEach(async rule => {
15+
const { cond } = rule
16+
let changed = false
17+
const newCond: string[] = []
18+
cond?.forEach(url => {
19+
const clean = cleanCond(url)
20+
changed = changed || clean !== url
21+
clean && newCond.push(clean)
22+
})
23+
if (!changed) return
24+
if (rule.cond.length) {
25+
rule.cond = newCond
26+
needUpdate.push(rule)
27+
} else {
28+
needRemoved.push(rule)
29+
}
30+
31+
})
32+
needRemoved.length && await limitService.remove(...needRemoved)
33+
needUpdate.length && await limitService.update(...needUpdate)
34+
}
35+
}

src/database/site-database.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ function cvt2Entry({ alias, iconUrl, cate, run }: timer.site.SiteInfo): _Entry {
8181
return entry
8282
}
8383

84-
function cvt2SiteInfo(key: timer.site.SiteKey, entry: _Entry): timer.site.SiteInfo {
85-
const { a, i, c, r } = entry
84+
function cvt2SiteInfo(key: timer.site.SiteKey, entry: _Entry | undefined): timer.site.SiteInfo {
85+
const { a, i, c, r } = entry || {}
8686
const siteInfo: timer.site.SiteInfo = { ...key }
8787
siteInfo.alias = a
8888
siteInfo.cate = c

src/i18n/message/app/limit-resource.json

Lines changed: 13 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"zh_CN": {
33
"filterDisabled": "过滤无效规则",
4+
"wildcardTip": "您可以使用通配符来匹配子域名或子页面!",
45
"item": {
56
"name": "规则名称",
67
"condition": "限制网址",
@@ -27,10 +28,8 @@
2728
},
2829
"button": {
2930
"test": "网址测试",
30-
"option": "全局设置",
31-
"parseUrl": "解析 URL"
31+
"option": "全局设置"
3232
},
33-
"useWildcard": "是否使用通配符",
3433
"message": {
3534
"noUrl": "未配置限制网址",
3635
"noRule": "未填写任何规则",
@@ -43,7 +42,6 @@
4342
"rulesMatched": "该网址命中以下规则:",
4443
"timeout": "倒计时已结束 XD"
4544
},
46-
"urlPlaceholder": "请输入你想要限制的网址,然后点击解析按钮",
4745
"verification": {
4846
"inputTip": "规则已触发或者被锁定,如要继续操作,请在 {second} 秒内输入以下问题的答案:{prompt}",
4947
"inputTip2": "时限规则已触发或者被锁定,如要继续操作,请于 {second} 秒内在下列输入框中原样输入:{answer}",
@@ -82,10 +80,8 @@
8280
"rule": "規則設定"
8381
},
8482
"button": {
85-
"test": "測試網址",
86-
"parseUrl": "解析網址"
83+
"test": "測試網址"
8784
},
88-
"useWildcard": "是否使用萬用字元",
8985
"message": {
9086
"noUrl": "未填寫限制網址",
9187
"noRule": "未設定任何規則",
@@ -95,7 +91,6 @@
9591
"noRuleMatched": "此網址未符合任何規則",
9692
"rulesMatched": "此網址符合以下規則:"
9793
},
98-
"urlPlaceholder": "請輸入要限制的網址,然後點擊解析按鈕",
9994
"verification": {
10095
"inputTip": "規則已觸發或鎖定,請於 {second} 秒內回答:{prompt}",
10196
"inputTip2": "規則已觸發或鎖定。請在 {second} 秒內輸入:{answer}",
@@ -110,6 +105,7 @@
110105
},
111106
"en": {
112107
"filterDisabled": "Only enabled",
108+
"wildcardTip": "You can use wildcards to match subdomains or subpages!",
113109
"item": {
114110
"name": "Rule name",
115111
"condition": "Restricted URL",
@@ -135,10 +131,8 @@
135131
"rule": "Config rule"
136132
},
137133
"button": {
138-
"test": "Test URL",
139-
"parseUrl": "Parse URL"
134+
"test": "Test URL"
140135
},
141-
"useWildcard": "Whether to use wildcard",
142136
"message": {
143137
"noUrl": "No restriction URLs configured",
144138
"noRule": "No rules filled in",
@@ -150,7 +144,6 @@
150144
"rulesMatched": "The URL hits the following rules:",
151145
"timeout": "Time is up! XD"
152146
},
153-
"urlPlaceholder": "Please enter the URL you want to restrict and click the Parse button",
154147
"verification": {
155148
"inputTip": "The rule has been triggered or locked. To continue, please enter the answer to the following question within {second} seconds: {prompt}",
156149
"inputTip2": "The rule has been triggered or locked. To continue, please enter it as it is within {second} seconds: {answer}",
@@ -189,10 +182,8 @@
189182
"rule": "設定ルール"
190183
},
191184
"button": {
192-
"test": "テストURL",
193-
"parseUrl": "解析 URL"
185+
"test": "テストURL"
194186
},
195-
"useWildcard": "ワイルドカードを使用するかどうか",
196187
"message": {
197188
"noUrl": "埋められていない制限URL",
198189
"noRule": "ルールが記入されていません",
@@ -202,7 +193,6 @@
202193
"noRuleMatched": "URL がどのルールとも一致しません",
203194
"rulesMatched": "URL は次のルールに一致します。"
204195
},
205-
"urlPlaceholder": "制限したいURLを入力して解析ボタンをクリックしてください",
206196
"verification": {
207197
"inputTip": "ルールがトリガーされたかロックされました。続行するには、次の質問に対する回答を {second} 秒以内に入力してください: {prompt}",
208198
"inputTip2": "ルールがトリガーされたかロックされました。続行するには、{second} 秒以内にそのまま入力してください: {answer}",
@@ -241,10 +231,8 @@
241231
"rule": "Configurar regra"
242232
},
243233
"button": {
244-
"test": "Testar URL",
245-
"parseUrl": "Analisar"
234+
"test": "Testar URL"
246235
},
247-
"useWildcard": "Se deseja usar caractere curinga",
248236
"message": {
249237
"noUrl": "URL limitada não preenchida",
250238
"noRule": "Nenhuma regra preenchida",
@@ -254,7 +242,6 @@
254242
"noRuleMatched": "O URL não atinge nenhuma regra",
255243
"rulesMatched": "A URL atinge as seguintes regras:"
256244
},
257-
"urlPlaceholder": "Insira o URL que deseja restringir e clique no botão Analisar",
258245
"verification": {
259246
"inputTip": "A regra foi acionada ou bloqueada. Para continuar, introduza a resposta à seguinte questão em {second} segundos: {prompt}",
260247
"inputTip2": "A regra foi acionada ou bloqueada. Para continuar, digite-o tal como está em {segundos} segundos: {resposta}",
@@ -293,10 +280,8 @@
293280
"rule": "Правило конфігурації"
294281
},
295282
"button": {
296-
"test": "Тестова URL-адреса",
297-
"parseUrl": "Обробити URL"
283+
"test": "Тестова URL-адреса"
298284
},
299-
"useWildcard": "Використовувати символ підставлення",
300285
"message": {
301286
"noUrl": "Не заповнена обмежена URL-адреса",
302287
"noRule": "Не заповнено жодного правила",
@@ -306,7 +291,6 @@
306291
"noRuleMatched": "URL не відповідає жодному правилу",
307292
"rulesMatched": "URL-адреса отримує такі правила:"
308293
},
309-
"urlPlaceholder": "Введіть URL-адресу, яку ви хочете обмежити, а потім натисніть кнопку Обробити",
310294
"verification": {
311295
"inputTip": "Правило було запущено або заблоковано. Щоб продовжити, введіть відповідь на таке запитання протягом {second} секунд: {prompt}",
312296
"inputTip2": "Правило було запущено або заблоковано. Щоб продовжити, введіть його таким, яким він є, протягом {second} секунд: {answer}",
@@ -341,10 +325,8 @@
341325
"rule": "Configurar regla"
342326
},
343327
"button": {
344-
"test": "Probar URL",
345-
"parseUrl": "Analizar URL"
328+
"test": "Probar URL"
346329
},
347-
"useWildcard": "Cuando usar un comodín",
348330
"message": {
349331
"noUrl": "URL restringida sin completar",
350332
"noRule": "No hay reglas llenadas",
@@ -354,7 +336,6 @@
354336
"noRuleMatched": "La URL no sigue ninguna regla",
355337
"rulesMatched": "La URL sigue las siguientes reglas:"
356338
},
357-
"urlPlaceholder": "Ingrese la URL que desea restringir y haga clic en el botón Analizar",
358339
"verification": {
359340
"inputTip": "La regla se ha activado o bloqueado. Para continuar, responda la siguiente pregunta en menos de {second} segundos: {prompt}",
360341
"inputTip2": "La regla se ha activado o bloqueado. Para continuar, introdúzcala en {second} segundos: {answer}",
@@ -388,10 +369,8 @@
388369
"rule": "Konfiguration Regel"
389370
},
390371
"button": {
391-
"test": "Test-URL",
392-
"parseUrl": "URL analysieren"
372+
"test": "Test-URL"
393373
},
394-
"useWildcard": "Ob Platzhalter verwendet wird",
395374
"message": {
396375
"noUrl": "Nicht ausgefüllte eingeschränkte URL",
397376
"noRule": "Keine Regeln ausgefüllt",
@@ -401,7 +380,6 @@
401380
"noRuleMatched": "Die URL entspricht keinen Regeln",
402381
"rulesMatched": "Die URL erfüllt die folgenden Regeln:"
403382
},
404-
"urlPlaceholder": "Geben Sie bitte die URL ein, die Sie einschränken möchten, und klicken Sie auf die Schaltfläche „URL analysieren“",
405383
"verification": {
406384
"inputTip": "Die Regel wurde ausgelöst oder gesperrt. Um fortzufahren, geben Sie bitte innerhalb von {second} Sekunden die Antwort auf die folgende Frage ein: {prompt}",
407385
"inputTip2": "Die Regel wurde ausgelöst oder gesperrt. Um fortzufahren, geben Sie sie bitte innerhalb von {second} Sekunden unverändert ein: {answer}",
@@ -434,10 +412,8 @@
434412
"rule": "Règle de configuration"
435413
},
436414
"button": {
437-
"test": "Test URL",
438-
"parseUrl": "Parse URL"
415+
"test": "Test URL"
439416
},
440-
"useWildcard": "Utiliser des caractères génériques",
441417
"message": {
442418
"noUrl": "Aucune URL de restriction configurée",
443419
"noRule": "Aucune règle remplie",
@@ -447,7 +423,6 @@
447423
"noRuleMatched": "L'URL ne correspond à aucune règle",
448424
"rulesMatched": "L'URL atteint les règles suivantes :"
449425
},
450-
"urlPlaceholder": "Veuillez entrer l'URL que vous voulez restreindre et cliquez sur le bouton Analyser",
451426
"verification": {
452427
"inputTip": "La règle a été déclenchée ou verrouillée. Pour continuer, veuillez répondre à la question suivante dans un délai de {second} secondes : {prompt}",
453428
"inputTip2": "La règle a été déclenchée ou verrouillée. Pour continuer, veuillez la saisir telle quelle dans un délai de {second} secondes : {answer}",
@@ -481,10 +456,8 @@
481456
"rule": "Установить правило"
482457
},
483458
"button": {
484-
"test": "Тестовый URL",
485-
"parseUrl": "Анализ URL"
459+
"test": "Тестовый URL"
486460
},
487-
"useWildcard": "Использовать ли подстановку",
488461
"message": {
489462
"noUrl": "Ограничение URL-адресов не настроено",
490463
"noRule": "Нет заполненных правил",
@@ -494,7 +467,6 @@
494467
"noRuleMatched": "URL не содержит правил",
495468
"rulesMatched": "URL попадает в следующие правила:"
496469
},
497-
"urlPlaceholder": "Пожалуйста, введите URL, который вы хотите ограничить и нажмите на кнопку \"Анализ\"",
498470
"verification": {
499471
"inputTip": "Правило было активировано или заблокировано. Чтобы продолжить, введите ответ на следующий вопрос в течение {second} секунд: {prompt}",
500472
"inputTip2": "Правило было запущено или заблокировано. Чтобы продолжить, введите его как есть в течение {second} секунд: {answer}",
@@ -527,10 +499,8 @@
527499
"rule": "قاعدة التكوين"
528500
},
529501
"button": {
530-
"test": "اختبار عنوان URL",
531-
"parseUrl": "تحليل عنوان URL"
502+
"test": "اختبار عنوان URL"
532503
},
533-
"useWildcard": "هل يجب استخدام الأحرف البدل",
534504
"message": {
535505
"noUrl": "لم يتم تكوين عناوين URL الخاصة بالقيود",
536506
"noRule": "لم يتم ملء أي قواعد",
@@ -540,7 +510,6 @@
540510
"noRuleMatched": "عنوان URL لا يصطدم بأي قواعد",
541511
"rulesMatched": "يتوافق عنوان URL مع القواعد التالية:"
542512
},
543-
"urlPlaceholder": "الرجاء إدخال عنوان URL الذي تريد تقييده ثم انقر فوق الزر \"تحليل\"",
544513
"verification": {
545514
"inputTip": "تم تفعيل القاعدة أو قفلها. للمتابعة، يُرجى إدخال إجابة السؤال التالي خلال {second} ثانية: {prompt}",
546515
"inputTip2": "تم تفعيل القاعدة أو قفلها. للمتابعة، يُرجى إدخالها كما هي خلال {second} ثانية: {answer}",

src/i18n/message/app/limit.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import resource from './limit-resource.json'
99

1010
export type LimitMessage = {
1111
filterDisabled: string
12-
useWildcard: string
13-
urlPlaceholder: string
12+
wildcardTip: string
1413
step: {
1514
base: string
1615
url: string
@@ -37,7 +36,6 @@ export type LimitMessage = {
3736
}
3837
button: {
3938
test: string
40-
parseUrl: string
4139
}
4240
message: {
4341
noUrl: string

src/i18n/message/common/button-resource.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"en": {
33
"create": "New",
4+
"add": "Add",
45
"delete": "Delete",
56
"batchDelete": "Batch Delete",
67
"modify": "Edit",
@@ -22,6 +23,7 @@
2223
},
2324
"zh_CN": {
2425
"create": "新建",
26+
"add": "添加",
2527
"delete": "删除",
2628
"batchDelete": "批量删除",
2729
"modify": "编辑",

0 commit comments

Comments
 (0)