Skip to content

Commit

Permalink
v2.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
sheepzh committed Jan 15, 2024
2 parents 33249a9 + 9aa5568 commit fbc5086
Show file tree
Hide file tree
Showing 23 changed files with 412 additions and 199 deletions.
4 changes: 2 additions & 2 deletions script/crowdin/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ export class CrowdinClient {
createStorage = createStorage
/**
* Get the main branch
*
*
* @returns main branch or undefined
*/
getMainBranch = getMainBranch
Expand Down Expand Up @@ -317,7 +317,7 @@ export class CrowdinClient {

/**
* Get the client from environment variable [TIMER_CROWDIN_AUTH]
*
*
* @returns client
*/
export function getClientFromEnv(): CrowdinClient {
Expand Down
20 changes: 8 additions & 12 deletions script/crowdin/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ export const MSG_BASE = path.join(__dirname, '..', '..', 'src', 'i18n', 'message
export const RSC_FILE_SUFFIX = "-resource.json"

/**
* Read all messages from source file
*
* Read all messages from source file
*
* @param dir the directory of messages
* @returns
* @returns
*/
export async function readAllMessages(dir: Dir): Promise<Record<string, Messages<any>>> {
const dirPath = path.join(MSG_BASE, dir)
Expand All @@ -78,7 +78,7 @@ export async function readAllMessages(dir: Dir): Promise<Record<string, Messages

/**
* Merge crowdin message into locale resource json files
*
*
* @param dir dir
* @param filename the name of json file
* @param messages crowdin messages
Expand All @@ -99,15 +99,11 @@ export async function mergeMessage(
Object.entries(messages).forEach(([locale, itemSet]) => {
let existMessage: any = existMessages[locale] || {}
Object.entries(itemSet).forEach(([path, text]) => {
if (!text) {
// Not translated
return
}
// Not translated
if (!text) return
const sourceText = sourceItemSet[path]
if (!sourceText) {
// Deleted key
return
}
// Deleted key
if (!sourceText) return
if (!checkPlaceholder(text, sourceText)) {
console.error(`Invalid placeholder: dir=${dir}, filename=${filename}, path=${path}, source=${sourceText}, translated=${text}`)
return
Expand Down
2 changes: 1 addition & 1 deletion script/crowdin/crowdin.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type ItemSet = {

/**
* The language code of crowdin
*
*
* @see https://developer.crowdin.com/language-codes/
*/
type CrowdinLanguage =
Expand Down
4 changes: 2 additions & 2 deletions script/crowdin/sync-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async function initBranch(client: CrowdinClient): Promise<SourceFilesModel.Branc

/**
* Process strings
*
*
* @param client client
* @param existFile exist crowdin file
* @param fileContent strings
Expand Down Expand Up @@ -55,7 +55,7 @@ async function processByDir(client: CrowdinClient, dir: Dir, branch: SourceFiles
if (!directory) {
directory = await client.createDirectory(dirKey)
}
console.log('Direcotory: ' + JSON.stringify(directory))
console.log('Directory: ' + JSON.stringify(directory))
// 2. iterate all messages
const messages = await readAllMessages(dir)
// 3. list all files in directory
Expand Down
20 changes: 9 additions & 11 deletions src/app/components/limit/table/column/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { defineComponent, h, onMounted, ref, VNode } from "vue"

/**
* Judge wether verification is required
*
*
* @returns T/F
*/
export async function judgeVerificationRequired(item: timer.limit.Item): Promise<boolean> {
Expand All @@ -26,15 +26,13 @@ export async function judgeVerificationRequired(item: timer.limit.Item): Promise
}
// Visit
if (visitTime) {
console.log("visiTime", visitTime)
const hitVisit = await sendMsg2Runtime("askHitVisit", item)
console.log("visiTimeHit", hitVisit)
if (hitVisit) return true
}
return false
}

const PROMT_TXT_CSS: Partial<CSSStyleDeclaration> = {
const PROMPT_TXT_CSS: Partial<CSSStyleDeclaration> = {
userSelect: 'none',
}

Expand Down Expand Up @@ -79,23 +77,23 @@ const AnswerCanvas = defineComponent({
})

/**
* @returns null if verification not required,
* or promise with resolve invocked only if verification code or password correct
* @returns null if verification not required,
* or promise with resolve invoked only if verification code or password correct
*/
export async function processVerification(option: timer.option.DailyLimitOption): Promise<void> {
const { limitLevel, limitPassword, limitVerifyDifficulty } = option
let answerValue: string
let messageNodes: (VNode | string)[]
let incrorectMessage: string
let incorrectMessage: string
if (limitLevel === 'password' && limitPassword) {
answerValue = limitPassword
messageNodes = [t(msg => msg.limit.verification.pswInputTip)]
incrorectMessage = t(msg => msg.limit.verification.incorrectPsw)
incorrectMessage = t(msg => msg.limit.verification.incorrectPsw)
} else if (limitLevel === 'verification') {
const pair: VerificationPair = verificationProcessor.generate(limitVerifyDifficulty, locale)
const { prompt, promptParam, answer } = pair || {}
answerValue = typeof answer === 'function' ? t(msg => answer(msg.limit.verification)) : answer
incrorectMessage = t(msg => msg.limit.verification.incorrectAnswer)
incorrectMessage = t(msg => msg.limit.verification.incorrectAnswer)
if (prompt) {
const promptTxt = typeof prompt === 'function'
? t(msg => prompt(msg.limit.verification), { ...promptParam, answer: answerValue })
Expand All @@ -114,7 +112,7 @@ export async function processVerification(option: timer.option.DailyLimitOption)
boxType: 'prompt',
type: 'warning',
title: '',
message: h('div', { style: PROMT_TXT_CSS }, messageNodes),
message: h('div', { style: PROMPT_TXT_CSS }, messageNodes),
showInput: true,
showCancelButton: true,
showClose: true,
Expand All @@ -123,7 +121,7 @@ export async function processVerification(option: timer.option.DailyLimitOption)
if (value === answerValue) {
return resolve()
}
ElMessage.error(incrorectMessage)
ElMessage.error(incorrectMessage)
}).catch(() => { })
)
: null
Expand Down
7 changes: 4 additions & 3 deletions src/app/locale.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/**
* Copyright (c) 2021 Hengyang Zhang
*
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/

import { I18nKey as _I18nKey, t as _t } from "@i18n"
import { tN as _tN } from "@i18n/i18n-vue"
import { tN as _tN } from "@i18n"
import messages, { AppMessage } from "@i18n/message/app"
import { VNode } from "vue"

export type I18nKey = _I18nKey<AppMessage>

Expand All @@ -25,5 +26,5 @@ export function tWith(key: I18nKey, specLocale: timer.Locale, param?: any) {
}

export function tN(key: I18nKey, param?: any) {
return _tN<AppMessage>(messages, { key, param })
return _tN<AppMessage, VNode>(messages, { key, param })
}
6 changes: 3 additions & 3 deletions src/background/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Copyright (c) 2021 Hengyang Zhang
*
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
Expand All @@ -13,7 +13,7 @@ import VersionManager from "./version-manager"
import ActiveTabListener from "./active-tab-listener"
import badgeTextManager from "./badge-text-manager"
import MessageDispatcher from "./message-dispatcher"
import initLimitProcesser from "./limit-processor"
import initLimitProcessor from "./limit-processor"
import initCsHandler from "./content-script-handler"
import { isBrowserUrl } from "@util/pattern"
import BackupScheduler from "./backup-scheduler"
Expand All @@ -28,7 +28,7 @@ openLog()
const messageDispatcher = new MessageDispatcher()

// Limit processor
initLimitProcesser(messageDispatcher)
initLimitProcessor(messageDispatcher)

// Content-script's request handler
initCsHandler(messageDispatcher)
Expand Down
4 changes: 2 additions & 2 deletions src/content-script/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Copyright (c) 2021 Hengyang Zhang
*
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
Expand Down Expand Up @@ -43,7 +43,7 @@ async function main() {
)
tracker.init()

// Execute only one time
// Execute only one time for each dom
if (getOrSetFlag()) return
if (!host) return

Expand Down
21 changes: 21 additions & 0 deletions src/content-script/limit/delay/button.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { t } from "@src/content-script/locale"
import { LINK_STYLE } from "../modal-style"

export class DelayButton {
public dom: HTMLDivElement

constructor(onClick: () => void) {
this.dom = document.createElement('p')
this.dom.style.marginTop = '100px'

// Only delay-allowed rules exist, can delay
// @since 0.4.0
const link = document.createElement('a')
Object.assign(link.style || {}, LINK_STYLE)
link.setAttribute('href', 'javascript:void(0)')
const text = t(msg => msg.more5Minutes)
link.innerText = text
link.onclick = onClick
this.dom.append(link)
}
}
Loading

0 comments on commit fbc5086

Please sign in to comment.