Skip to content

Commit d08d6b6

Browse files
committed
Support merge subdomains when popup page open (#161)
1 parent e91cc78 commit d08d6b6

File tree

6 files changed

+33
-4
lines changed

6 files changed

+33
-4
lines changed

global.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ declare namespace timer {
3737
* @since 1.2.5
3838
*/
3939
weekStart: WeekStartOption
40+
/**
41+
* Whether to merge domain by default
42+
*
43+
* @since 1.3.2
44+
*/
45+
defaultMergeDomain: boolean
4046
}
4147

4248
/**

src/app/components/option/components/popup.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ import { ALL_DIMENSIONS } from "@util/stat"
1818
import { locale } from "@util/i18n"
1919
import { rotate } from "@util/array"
2020

21+
const mergeDomain = (option: UnwrapRef<timer.option.PopupOption>) => h(ElSwitch, {
22+
modelValue: option.defaultMergeDomain,
23+
onChange: (newVal: boolean) => {
24+
option.defaultMergeDomain = newVal
25+
optionService.setPopupOption(option)
26+
}
27+
})
28+
2129
const popupMaxInput = (option: UnwrapRef<timer.option.PopupOption>) => h(ElInputNumber, {
2230
modelValue: option.popupMax,
2331
size: 'small',
@@ -83,6 +91,7 @@ const defaultDurationLabel = t(msg => msg.option.popup.duration[defaultPopOption
8391
const displayDefaultLabel = `${defaultDurationLabel}/${defaultTypeLabel}`
8492

8593
function copy(target: timer.option.PopupOption, source: timer.option.PopupOption) {
94+
target.defaultMergeDomain = source.defaultMergeDomain
8695
target.defaultDuration = source.defaultDuration
8796
target.defaultType = source.defaultType
8897
target.displaySiteName = source.displaySiteName
@@ -102,6 +111,13 @@ const _default = defineComponent({
102111
}
103112
})
104113
return () => h('div', [
114+
renderOptionItem({
115+
input: mergeDomain(option),
116+
},
117+
msg => msg.popup.defaultMergeDomain,
118+
t(msg => msg.option.no)
119+
),
120+
h(ElDivider),
105121
renderOptionItem({
106122
duration: durationSelect(option),
107123
type: typeSelect(option)

src/app/locale/components/option.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export type OptionMessage = {
1414
popup: {
1515
title: string
1616
max: string
17+
defaultMergeDomain: string
1718
defaultDisplay: string
1819
displaySiteName: string
1920
duration: PopupDurationMessage
@@ -93,12 +94,13 @@ const _default: Messages<OptionMessage> = {
9394
popup: {
9495
title: '弹窗页',
9596
max: '只显示前 {input} 条数据,剩下的条目合并显示',
97+
defaultMergeDomain: '{input} 打开时合并子域名',
9698
defaultDisplay: "打开时显示 {duration} {type}",
9799
displaySiteName: '{input} 显示时是否使用 {siteName} 来代替域名',
98100
duration: popupDurationMessages.zh_CN,
99101
durationWidth: "80px",
100102
weekStart: "每周的第一天 {input}",
101-
weekStartAsNormal: '按照惯例'
103+
weekStartAsNormal: '按照惯例',
102104
},
103105
appearance: {
104106
title: '外观',
@@ -174,6 +176,7 @@ const _default: Messages<OptionMessage> = {
174176
popup: {
175177
title: '彈窗頁',
176178
max: '隻顯示前 {input} 條數據,剩下的條目合並顯示',
179+
defaultMergeDomain: '{input} 打開時合併子域名',
177180
defaultDisplay: "打開時顯示 {duration} {type}",
178181
displaySiteName: '{input} 顯示時是否使用 {siteName} 來代替域名',
179182
duration: popupDurationMessages.zh_CN,
@@ -254,7 +257,8 @@ const _default: Messages<OptionMessage> = {
254257
popup: {
255258
title: 'Popup Page',
256259
max: 'Show the first {input} data items',
257-
defaultDisplay: "Show {duration} {type} when opened",
260+
defaultMergeDomain: '{input} Merge subdomains on open',
261+
defaultDisplay: "Show {duration} {type} on open",
258262
displaySiteName: '{input} Whether to display {siteName} instead of URL',
259263
duration: popupDurationMessages.en,
260264
durationWidth: "110px",
@@ -335,6 +339,7 @@ const _default: Messages<OptionMessage> = {
335339
popup: {
336340
title: 'ポップアップページ',
337341
max: '最初の {input} 個のデータのみを表示し、残りのエントリは結合されます',
342+
defaultMergeDomain: '{input} オープン時にサブドメインをマージ',
338343
defaultDisplay: "開くと {duration} {type} が表示されます",
339344
displaySiteName: '{input} ホストの代わりに {siteName} を表示するかどうか',
340345
duration: popupDurationMessages.ja,

src/popup/components/footer/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class FooterWrapper {
8383
const option = await optionService.getAllOption()
8484
this.timeSelectWrapper.init(option.defaultDuration)
8585
this.typeSelectWrapper.init(option.defaultType)
86-
this.mergeHostWrapper.init()
86+
this.mergeHostWrapper.init(option.defaultMergeDomain)
8787
this.query()
8888
}
8989

src/popup/components/footer/merge-host.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class MergeHostWrapper {
1919
this.handleChanged = handleChanged
2020
}
2121

22-
init() {
22+
init(initialVal: boolean) {
2323
this.mergeHostSwitch = document.getElementById('merge-host-switch')
2424
this.mergeHostPopup = document.getElementById('merge-host-popup-container')
2525
this.mergeHostPopupInfo = document.getElementById('merge-host-popup-info')
@@ -35,6 +35,7 @@ class MergeHostWrapper {
3535
}
3636
this.handleChanged?.()
3737
}
38+
initialVal && this.mergeHostSwitch.click()
3839
}
3940

4041
mergedHost() {

src/util/constant/option.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export function defaultPopup(): timer.option.PopupOption {
1616
*/
1717
displaySiteName: true,
1818
weekStart: 'default',
19+
defaultMergeDomain: false,
1920
}
2021
}
2122

0 commit comments

Comments
 (0)