Skip to content

Commit e91cc78

Browse files
committed
Support multiple filter types for limit mask (#159)
1 parent 83fed20 commit e91cc78

File tree

6 files changed

+107
-10
lines changed

6 files changed

+107
-10
lines changed

global.d.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,18 @@ declare namespace timer {
8585
* @since 1.1.0
8686
*/
8787
darkMode: DarkMode
88-
8988
/**
9089
* The range of seconds to turn on dark mode. Required if {@param darkMode} is 'timed'
9190
*
9291
* @since 1.1.0
9392
*/
9493
darkModeTimeStart?: number
9594
darkModeTimeEnd?: number
95+
/**
96+
* The filter of limit mark
97+
* @since 1.3.2
98+
*/
99+
limitMarkFilter: limit.FilterType
96100
}
97101

98102
type StatisticsOption = {
@@ -283,6 +287,14 @@ declare namespace timer {
283287
*/
284288
wasteTime: number
285289
}
290+
/**
291+
* @since 1.3.2
292+
*/
293+
type FilterType =
294+
// translucent filter
295+
| 'translucent'
296+
// ground glass filter
297+
| 'groundGlass'
286298
}
287299

288300
namespace period {

src/app/components/option/components/appearance/index.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,24 @@ const locale = (option: UnwrapRef<timer.option.AppearanceOption>) => h(ElSelect,
8080
)
8181
})
8282

83+
const ALL_LIMIT_FILTER_TYPE: timer.limit.FilterType[] = [
84+
'translucent',
85+
'groundGlass',
86+
]
87+
88+
const limitFilterTypeSelect = (option: timer.option.AppearanceOption) => h(ElSelect, {
89+
modelValue: option.limitMarkFilter,
90+
size: 'small',
91+
onChange: (val: timer.limit.FilterType) => {
92+
option.limitMarkFilter = val
93+
optionService.setAppearanceOption(unref(option))
94+
}
95+
}, {
96+
default: () => ALL_LIMIT_FILTER_TYPE.map(item =>
97+
h(ElOption, { value: item, label: t(msg => msg.option.appearance.limitFilterType[item]) })
98+
)
99+
})
100+
83101
function copy(target: timer.option.AppearanceOption, source: timer.option.AppearanceOption) {
84102
target.displayWhitelistMenu = source.displayWhitelistMenu
85103
target.displayBadgeText = source.displayBadgeText
@@ -88,6 +106,7 @@ function copy(target: timer.option.AppearanceOption, source: timer.option.Appear
88106
target.darkMode = source.darkMode
89107
target.darkModeTimeStart = source.darkModeTimeStart
90108
target.darkModeTimeEnd = source.darkModeTimeEnd
109+
target.limitMarkFilter = source.limitMarkFilter
91110
}
92111

93112
const _default = defineComponent({
@@ -143,7 +162,14 @@ const _default = defineComponent({
143162
input: printInConsole(option),
144163
console: tagText(msg => msg.option.appearance.printInConsole.console),
145164
info: tagText(msg => msg.option.appearance.printInConsole.info)
146-
}, msg => msg.appearance.printInConsole.label, t(msg => msg.option.yes))
165+
}, msg => msg.appearance.printInConsole.label, t(msg => msg.option.yes)),
166+
h(ElDivider),
167+
renderOptionItem({
168+
input: limitFilterTypeSelect(option)
169+
},
170+
msg => msg.appearance.limitFilterType.label,
171+
t(msg => msg.option.appearance.limitFilterType[defaultAppearance().limitMarkFilter])
172+
)
147173
])
148174
}
149175
})

src/app/locale/components/option.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ export type OptionMessage = {
5050
timed: string
5151
}
5252
}
53+
limitFilterType: Record<timer.limit.FilterType, string> & {
54+
label: string
55+
}
5356
}
5457
statistics: {
5558
title: string
@@ -123,7 +126,12 @@ const _default: Messages<OptionMessage> = {
123126
off: "始终关闭",
124127
timed: "定时开启"
125128
}
126-
}
129+
},
130+
limitFilterType: {
131+
label: "每日时限的背景风格 {input}",
132+
translucent: "半透明",
133+
groundGlass: "毛玻璃",
134+
},
127135
},
128136
statistics: {
129137
title: '统计',
@@ -199,7 +207,12 @@ const _default: Messages<OptionMessage> = {
199207
off: "始終關閉",
200208
timed: "定時開啟"
201209
}
202-
}
210+
},
211+
limitFilterType: {
212+
label: "每日時限的背景風格 {input}",
213+
translucent: "半透明",
214+
groundGlass: "毛玻璃",
215+
},
203216
},
204217
statistics: {
205218
title: '統計',
@@ -274,7 +287,12 @@ const _default: Messages<OptionMessage> = {
274287
off: "Always off",
275288
timed: "Timed on"
276289
}
277-
}
290+
},
291+
limitFilterType: {
292+
label: "Background style for daily time limit {input}",
293+
translucent: "Translucent",
294+
groundGlass: "Ground Glass",
295+
},
278296
},
279297
statistics: {
280298
title: 'Statistics',
@@ -351,6 +369,11 @@ const _default: Messages<OptionMessage> = {
351369
timed: "時限スタート"
352370
}
353371
},
372+
limitFilterType: {
373+
label: "毎日の時間制限の背景スタイル {input}",
374+
translucent: "半透明",
375+
groundGlass: "すりガラス",
376+
}
354377
},
355378
statistics: {
356379
title: '統計',

src/content-script/limit.ts

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

88
import TimeLimitItem from "@entity/time-limit-item"
9+
import optionService from "@service/option-service"
910
import { t2Chrome } from "@util/i18n/chrome/t"
1011

1112
function moreMinutes(url: string): Promise<timer.limit.Item[]> {
@@ -38,7 +39,16 @@ class _Modal {
3839
this.mask.id = "_timer_mask"
3940
this.mask.append(link2Setup(url))
4041
this.url = url
41-
Object.assign(this.mask.style, maskStyle)
42+
this.initStyle()
43+
}
44+
45+
private async initStyle() {
46+
const filterType = (await optionService.getAllOption())?.limitMarkFilter
47+
const realMaskStyle = {
48+
...maskStyle,
49+
...filterStyle[filterType || 'translucent']
50+
}
51+
Object.assign(this.mask.style, realMaskStyle)
4252
}
4353

4454
showModal(showDelay: boolean) {
@@ -104,17 +114,27 @@ const maskStyle: Partial<CSSStyleDeclaration> = {
104114
height: "100%",
105115
position: "fixed",
106116
zIndex: '99999',
107-
backgroundColor: '#444',
108-
opacity: '0.9',
109117
display: 'block',
110118
top: '0px',
111119
left: '0px',
112120
textAlign: 'center',
113121
paddingTop: '120px'
114122
}
115123

124+
const filterStyle: Record<timer.limit.FilterType, Partial<CSSStyleDeclaration & { backdropFilter: string }>> = {
125+
translucent: {
126+
backgroundColor: '#444',
127+
opacity: '0.9',
128+
color: '#EEE',
129+
},
130+
groundGlass: {
131+
backdropFilter: 'blur(5px)',
132+
color: '#111',
133+
}
134+
}
135+
116136
const linkStyle: Partial<CSSStyleDeclaration> = {
117-
color: '#EEE',
137+
color: 'inherit',
118138
fontFamily: '-apple-system,BlinkMacSystemFont,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Segoe UI","PingFang SC","Hiragino Sans GB","Microsoft YaHei","Helvetica Neue",Helvetica,Arial,sans-serif',
119139
fontSize: '16px !important'
120140
}

src/util/constant/environment.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,32 @@ let isChrome = false
1111
let isEdge = false
1212
let isOpera = false
1313
let isSafari = false
14+
let browserMajorVersion = undefined
1415

1516
if (/Firefox[\/\s](\d+\.\d+)/.test(userAgent)) {
1617
isFirefox = true
18+
browserMajorVersion = /Firefox\/([0-9]+)/.exec(userAgent)?.[1]
1719
} else if (userAgent.includes('Edg')) {
1820
// The Edge implements the chrome
1921
isEdge = true
22+
browserMajorVersion = /Edg\/([0-9]+)/.exec(userAgent)?.[1]
2023
} else if (userAgent.includes("Opera") || userAgent.includes("OPR")) {
2124
// The Opera implements the chrome
2225
isOpera = true
26+
browserMajorVersion = /OPR\/([0-9]+)/.exec(userAgent)?.[1] || /Opera\/([0-9]+)/.exec(userAgent)?.[1]
2327
} else if (userAgent.includes('Safari') && !userAgent.includes('Chrome')) {
2428
// Chrome on macOs includes 'Safari'
2529
isSafari = true
30+
browserMajorVersion = /Safari\/([0-9]+)/.exec(userAgent)?.[1]
2631
} else if (userAgent.includes('Chrome')) {
2732
isChrome = true
33+
browserMajorVersion = /Chrome\/([0-9]+)/.exec(userAgent)?.[1]
2834
}
2935

36+
try {
37+
browserMajorVersion && (browserMajorVersion = Number.parseInt(browserMajorVersion))
38+
} catch (ignored) { }
39+
3040
export const IS_FIREFOX: boolean = isFirefox
3141

3242
export const IS_EDGE: boolean = isEdge
@@ -41,4 +51,9 @@ export const IS_OPERA: boolean = isOpera
4151
/**
4252
* @since 1.3.0
4353
*/
44-
export const IS_SAFARI: boolean = isSafari
54+
export const IS_SAFARI: boolean = isSafari
55+
56+
/**
57+
* @since 1.3.2
58+
*/
59+
export const BROWSER_MAJOR_VERSION = browserMajorVersion

src/util/constant/option.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export function defaultAppearance(): timer.option.AppearanceOption {
3232
darkModeTimeStart: 64800,
3333
// 6*60*60
3434
darkModeTimeEnd: 21600,
35+
limitMarkFilter: 'translucent',
3536
}
3637
}
3738

0 commit comments

Comments
 (0)