Skip to content

Commit

Permalink
Support strict mode for time limit (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheepzh committed Jan 24, 2024
1 parent 354340d commit b3c9620
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 15 deletions.
14 changes: 13 additions & 1 deletion src/app/components/Option/components/LimitOption/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { t } from "@app/locale"
import { locale } from "@i18n"
import optionService from "@service/option-service"
import { defaultDailyLimit } from "@util/constant/option"
import { ElInput, ElOption, ElSelect } from "element-plus"
import { ElInput, ElMessageBox, ElOption, ElSelect } from "element-plus"
import { defineComponent, reactive, unref, UnwrapRef, ref, Ref, watch } from "vue"
import { OptionItem } from "../../common"
import "./limit-option.sass"
Expand All @@ -25,6 +25,7 @@ const ALL_LEVEL: timer.limit.RestrictionLevel[] = [
'nothing',
'verification',
'password',
'strict',
]

const ALL_DIFF: timer.limit.VerificationDifficulty[] = [
Expand Down Expand Up @@ -61,6 +62,16 @@ function reset(target: timer.option.DailyLimitOption) {
Object.entries(defaultValue).forEach(([key, val]) => target[key] = val)
}

const confirm4Strict = async (): Promise<void> => {
const title = t(msg => msg.option.dailyLimit.level.strictTitle)
const content = t(msg => msg.option.dailyLimit.level.strictContent)
await ElMessageBox.confirm(content, title, {
type: "warning",
confirmButtonText: t(msg => msg.button.confirm),
cancelButtonText: t(msg => msg.button.cancel),
})
}

const _default = defineComponent((_, ctx) => {
const option: UnwrapRef<timer.option.DailyLimitOption> = reactive(defaultDailyLimit())
const verified = ref(false)
Expand Down Expand Up @@ -93,6 +104,7 @@ const _default = defineComponent((_, ctx) => {
size="small"
class={`option-daily-limit-level-select ${locale}`}
onChange={(val: timer.limit.RestrictionLevel) => verifyTriggered(option, verified)
.then(() => val === "strict" ? confirm4Strict() : Promise.resolve())
.then(() => option.limitLevel = val)
.catch(console.log)
}
Expand Down
10 changes: 10 additions & 0 deletions src/app/util/limit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ const AnswerCanvas = defineComponent({
*/
export async function processVerification(option: timer.option.DailyLimitOption): Promise<void> {
const { limitLevel, limitPassword, limitVerifyDifficulty } = option
if (limitLevel === "strict") {
return new Promise(
(_, reject) => ElMessageBox({
boxType: 'alert',
type: 'warning',
title: '',
message: <div>{t(msg => msg.limit.verification.strictTip)}</div>,
}).then(reject).catch(reject)
)
}
let answerValue: string
let messageNode: VNode | string | Element
let incorrectMessage: string
Expand Down
6 changes: 4 additions & 2 deletions src/content-script/limit/modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ function isSameReason(a: LimitReason, b: LimitReason): boolean {
return same
}

const canDelay = ({ allowDelay, type }: LimitReason) => allowDelay && (type === "DAILY" || type === "VISIT")
const canDelay = ({ allowDelay, type }: LimitReason, options: timer.option.DailyLimitOption) => allowDelay
&& (type === "DAILY" || type === "VISIT")
&& options.limitLevel !== "strict"

class ModalInstance implements MaskModal {
url: string
Expand Down Expand Up @@ -164,7 +166,7 @@ class ModalInstance implements MaskModal {
this.mask.append(document.createElement("br"))
this.mask.append(link2Setup(url))

if (canDelay(reason)) {
if (canDelay(reason, this.options)) {
const delayConfirm = new DelayConfirm(this.options)
const delayButton = new DelayButton(
() => delayConfirm.doConfirm().then(() => this.delayHandlers?.forEach?.(h => h?.()))
Expand Down
21 changes: 12 additions & 9 deletions src/i18n/message/app/limit-resource.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@
},
"urlPlaceholder": "请直接粘贴网址 ➡️",
"verification": {
"inputTip": "该规则已超时,如要继续操作,请输入以下问题的答案:{prompt}",
"inputTip2": "该规则已超时,如要继续操作,请在下列输入框中原样输入:{answer}",
"pswInputTip": "该规则已超时,如要继续操作,所以请在下列输入框中输入您的解锁密码",
"inputTip": "时限规则已触发,如要继续操作,请输入以下问题的答案:{prompt}",
"inputTip2": "时限规则已触发,如要继续操作,请在下列输入框中原样输入:{answer}",
"pswInputTip": "时限规则已触发,如要继续操作,所以请在下列输入框中输入您的解锁密码",
"strictTip": "时限规则已触发,不允许手动解锁!",
"incorrectPsw": "密码错误",
"incorrectAnswer": "回答错误",
"pi": "圆周率 π 的小数部分第 {startIndex} 位到第 {endIndex} 位的共 {digitCount} 位数字",
Expand Down Expand Up @@ -76,9 +77,10 @@
},
"urlPlaceholder": "請直接粘貼網址 ➡️",
"verification": {
"inputTip": "此規則已逾時,如要繼續操作,請輸入以下問題的答案:{prompt}",
"inputTip2": "此規則已逾時,如要繼續操作,請在下列輸入框中原樣輸入:{answer}",
"pswInputTip": "此規則已逾時,如要繼續操作,所以請在下列輸入框中輸入您的解鎖密碼",
"inputTip": "時限規則已觸發,如要繼續操作,請輸入以下問題的答案:{prompt}",
"inputTip2": "時限規則已觸發,如要繼續操作,請在下列輸入框中原樣輸入:{answer}",
"pswInputTip": "時限規則已觸發,如要繼續操作,所以請在下列輸入框中輸入您的解鎖密碼",
"strictTip": "時限規則已觸發,不允許手動解鎖!",
"incorrectPsw": "密碼錯誤",
"incorrectAnswer": "答案不正確",
"pi": "圓周率 π 的小數部分第 {startIndex} 位到第 {endIndex} 位的共 {digitCount} 位數字",
Expand Down Expand Up @@ -122,9 +124,10 @@
},
"urlPlaceholder": "Please paste the URL directly ➡️",
"verification": {
"inputTip": "This rule has already been triggered. To continue, please enter the answer to the following prompt: {prompt}",
"inputTip2": "This rule has already been triggered. To continue, please enter it as it is: {answer}",
"pswInputTip": "This rule has already been triggered. To continue, please enter your unlock password",
"inputTip": "Limit rule has already been triggered. To continue, please enter the answer to the following prompt: {prompt}",
"inputTip2": "Limit rule has already been triggered. To continue, please enter it as it is: {answer}",
"pswInputTip": "Limit rule has already been triggered. To continue, please enter your unlock password",
"strictTip": "Limit rule has already been triggered and manual unlocking is not allowed!",
"incorrectPsw": "Incorrect password",
"incorrectAnswer": "Incorrect answer",
"pi": "{digitCount} digits from {startIndex} to {endIndex} of the decimal part of π",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/message/app/limit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export type LimitMessage = {
inputTip: string
inputTip2: string
pswInputTip: string
strictTip: string
incorrectPsw: string
incorrectAnswer: string
pi: string
Expand Down
15 changes: 12 additions & 3 deletions src/i18n/message/app/option-resource.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@
"easy": "简单",
"hard": "困难",
"disgusting": "折磨"
}
},
"strict": "不允许手动解锁",
"strictTitle": "危险操作",
"strictContent": "当您选择这个选项之后,如果某个站点触发了每日限制,除了等到第二天自动解锁以外,不允许您手动解锁。如果规则设置不当,很有可能会阻碍您的日常工作!"
}
},
"backup": {
Expand Down Expand Up @@ -189,7 +192,10 @@
"easy": "簡單",
"hard": "困難",
"disgusting": "噁心"
}
},
"strict": "不允許手動解鎖",
"strictTitle": "危險操作",
"strictContent": "當您選擇這個選項之後,如果某個網站觸發了每日限制,除了等到第二天自動解鎖以外,不允許您手動解鎖。 如果規則設定不當,很有可能會阻礙您的日常工作!"
}
},
"backup": {
Expand Down Expand Up @@ -309,7 +315,10 @@
"easy": "Easy",
"hard": "Hard",
"disgusting": "Disgusting"
}
},
"strict": "Not allow unlocking anyway",
"strictTitle": "Operation confirm",
"strictContent": "When you select this option, if a site triggers daily limit, you will not be allowed to manually unblock it other than waiting until the next day. If rules are not set up properly, they can very well hinder your routines!"
}
},
"backup": {
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/message/app/option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ export type OptionMessage = {
verificationDifficulty: {
[diff in timer.limit.VerificationDifficulty]: string
}
strictTitle: string
strictContent: string
}
}
backup: {
Expand Down
2 changes: 2 additions & 0 deletions types/timer/limit.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ declare namespace timer.limit {
| 'password'
// Verification code input required to lock or modify restricted rule
| 'verification'
// Not allowed to unlock manually
| 'strict'
/**
* @since 1.9.0
*/
Expand Down

0 comments on commit b3c9620

Please sign in to comment.