Skip to content

Commit 9b75bb8

Browse files
committed
feat: countdown
1 parent 254428c commit 9b75bb8

19 files changed

Lines changed: 648 additions & 25 deletions

File tree

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,27 @@
3030
"license": "MIT",
3131
"devDependencies": {
3232
"@commitlint/types": "^21.2.0",
33-
"@crowdin/crowdin-api-client": "^1.56.3",
33+
"@crowdin/crowdin-api-client": "^1.56.4",
3434
"@emotion/babel-plugin": "^11.13.5",
3535
"@rsdoctor/rspack-plugin": "^1.6.3",
36-
"@rspack/cli": "^2.2.0",
37-
"@rspack/core": "^2.2.0",
36+
"@rspack/cli": "^2.2.1",
37+
"@rspack/core": "^2.2.1",
3838
"@rstest/core": "^0.11.10",
3939
"@rstest/coverage-istanbul": "^0.11.10",
4040
"@types/chrome": "0.2.7",
4141
"@types/decompress": "^4.2.7",
4242
"@types/firefox-webext-browser": "^143.0.0",
43-
"@types/node": "^26.3.0",
43+
"@types/node": "^26.4.0",
4444
"@vue/babel-plugin-jsx": "^3.0.0",
4545
"babel-loader": "^10.1.1",
4646
"commitlint": "^21.2.2",
47-
"css-loader": "^7.1.4",
47+
"css-loader": "^7.1.5",
4848
"decompress": "^4.2.1",
4949
"fake-indexeddb": "^6.2.5",
5050
"husky": "^9.1.7",
5151
"jsdom": "^30.0.1",
5252
"jszip": "^3.10.1",
53-
"knip": "^6.32.2",
53+
"knip": "^6.33.0",
5454
"postcss": "^8.5.26",
5555
"postcss-loader": "^8.2.1",
5656
"postcss-rtlcss": "^6.0.0",
@@ -67,8 +67,8 @@
6767
"element-plus": "2.14.5",
6868
"qrcode-generator": "^2.0.4",
6969
"typescript-guard": "0.2.6",
70-
"vue": "^3.5.41",
71-
"vue-router": "^5.2.0"
70+
"vue": "^3.5.42",
71+
"vue-router": "^5.3.0"
7272
},
7373
"engines": {
7474
"node": ">=22"

src/background/limit-processor.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
import { listTabs, sendMsg2Tab } from "@api/chrome/tab"
9+
import optionHolder from '@service/components/option-holder'
910
import { getSite } from '@service/site-service'
1011
import { matches } from "@util/limit"
1112
import { extractHostname } from '@util/pattern'
@@ -25,6 +26,18 @@ function initDailyBroadcast() {
2526
)
2627
}
2728

29+
function initCountdownBroadcast() {
30+
optionHolder.addChangeListener(async (newVal, oldVal) => {
31+
if (newVal.limitCountdown === oldVal.limitCountdown) return
32+
const tabs = await listTabs()
33+
for (const { id: tabId } of tabs) {
34+
try {
35+
tabId && await sendMsg2Tab(tabId, 'limitCountdownChanged')
36+
} catch { }
37+
}
38+
})
39+
}
40+
2841
const processAskHitVisit = async (item: tt4b.limit.Item) => {
2942
let tabs = await listTabs()
3043
const { cond } = item
@@ -55,6 +68,7 @@ async function querySummary(): Promise<tt4b.limit.Summary | undefined> {
5568

5669
export default function init(dispatcher: MessageDispatcher) {
5770
initDailyBroadcast()
71+
initCountdownBroadcast()
5872

5973
dispatcher
6074
.register('limit.list', selectLimit)

src/background/service/components/option-holder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class OptionHolder {
2727
}
2828

2929
addChangeListener(listener: ChangeListener) {
30-
listener && this.#listeners.push(listener)
30+
this.#listeners.push(listener)
3131
}
3232

3333
async set(option: Partial<tt4b.option.AllOption>): Promise<void> {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export const ICON_SIZE = 40
2+
export const HALF_SIZE = ICON_SIZE / 2
3+
export const TIMER_INTERVAL = 1000
4+
5+
export type Position = { x: number, y: number }
6+
7+
export type Dimension = 'daily' | 'weekly' | 'visit'
8+
9+
export type RemainingItem = {
10+
remaining: number
11+
total: number
12+
dimension: Dimension
13+
name: string
14+
}
15+
16+
export type CountdownData = RemainingItem & { all: RemainingItem[] }

0 commit comments

Comments
 (0)