Skip to content

Commit

Permalink
Clean code and correct spellings
Browse files Browse the repository at this point in the history
  • Loading branch information
sheepzh committed Jan 15, 2024
1 parent 7c38c70 commit c66fd10
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 94 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
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
2 changes: 1 addition & 1 deletion src/content-script/locale.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Copyright (c) 2022 Hengyang Zhang
*
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
Expand Down
2 changes: 1 addition & 1 deletion src/guide/component/merge/target-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const SITE_EXAMPLES: _SiteExample[] = [{
original: 'es.news.google.com',
ruleIdx: [2],
}, {
original: 'a.b.c.phontos.google.com',
original: 'a.b.c.photos.google.com',
ruleIdx: [2],
}, {
original: 'pass.hust.edu.cn',
Expand Down
108 changes: 54 additions & 54 deletions src/manifest.ts
Original file line number Diff line number Diff line change
@@ -1,73 +1,73 @@
/**
* Copyright (c) 2021 Hengyang Zhang
*
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/

/**
* Build the manifest.json in chrome extension directory via this file
*
*
* @author zhy
* @since 0.0.1
*/
// Not use path alias in manifest.json
// Not use path alias in manifest.json
import packageInfo from "./package"
import { OPTION_ROUTE } from "./app/router/constants"
const { version, author: { name: author }, homepage } = packageInfo

const _default: chrome.runtime.ManifestV3 = {
name: '__MSG_meta_marketName__',
description: "__MSG_meta_description__",
version,
author,
default_locale: 'en',
homepage_url: homepage,
manifest_version: 3,
icons: {
16: "static/images/icon.png",
48: "static/images/icon.png",
128: "static/images/icon.png"
},
background: {
service_worker: 'background.js'
},
content_scripts: [
{
matches: [
"<all_urls>"
],
js: [
"content_scripts.js"
],
run_at: "document_start"
}
],
permissions: [
'storage',
'tabs',
'webNavigation',
'contextMenus',
'alarms',
'scripting',
],
host_permissions: [
"<all_urls>",
],
/**
* @since 0.3.4
*/
optional_permissions: [
'clipboardRead'
],
action: {
default_popup: "static/popup.html",
default_icon: "static/images/icon.png"
},
/**
* @since 0.4.0
*/
options_page: 'static/app.html#' + OPTION_ROUTE
name: '__MSG_meta_marketName__',
description: "__MSG_meta_description__",
version,
author,
default_locale: 'en',
homepage_url: homepage,
manifest_version: 3,
icons: {
16: "static/images/icon.png",
48: "static/images/icon.png",
128: "static/images/icon.png"
},
background: {
service_worker: 'background.js'
},
content_scripts: [
{
matches: [
"<all_urls>"
],
js: [
"content_scripts.js"
],
run_at: "document_start"
}
],
permissions: [
'storage',
'tabs',
'webNavigation',
'contextMenus',
'alarms',
'scripting',
],
host_permissions: [
"<all_urls>",
],
/**
* @since 0.3.4
*/
optional_permissions: [
'clipboardRead'
],
action: {
default_popup: "static/popup.html",
default_icon: "static/images/icon.png"
},
/**
* @since 0.4.0
*/
options_page: 'static/app.html#' + OPTION_ROUTE
}

export default _default
4 changes: 2 additions & 2 deletions src/service/limit-service/verification/common.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Copyright (c) 2023 Hengyang Zhang
*
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
Expand All @@ -26,7 +26,7 @@ export type VerificationPair = {
*/
export interface VerificationGenerator {
/**
* Whether to support
* Whether to support
*/
supports(context: VerificationContext): boolean

Expand Down
6 changes: 3 additions & 3 deletions types/timer/limit.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ declare namespace timer.limit {
type Period = [number, number]
/**
* Limit rule in runtime
*
*
* @since 0.8.4
*/
type Item = Rule & {
Expand All @@ -28,7 +28,7 @@ declare namespace timer.limit {
time: number
/**
* Time limit per visit, seconds
*
*
* @since 2.0.0
*/
visitTime?: number
Expand Down Expand Up @@ -65,7 +65,7 @@ declare namespace timer.limit {
| 'nothing'
// Password required to lock or modify restricted rule
| 'password'
// Verification code input requird to lock or modify restricted rule
// Verification code input required to lock or modify restricted rule
| 'verification'
/**
* @since 1.9.0
Expand Down

0 comments on commit c66fd10

Please sign in to comment.