From 7694ffc55c68b1bac1f1e968a631078acba7c2f6 Mon Sep 17 00:00:00 2001 From: L&H Date: Wed, 29 Nov 2023 10:56:46 +0800 Subject: [PATCH] chore: unify jsdocs and ts types --- global.d.ts | 2 +- src/manifest.json | 2 +- src/scripts/background.ts | 2 +- src/scripts/background/hanzi-to-pinyin.ts | 8 ++++---- src/scripts/popup.ts | 4 ---- 5 files changed, 7 insertions(+), 11 deletions(-) diff --git a/global.d.ts b/global.d.ts index 2e65e6f..1bfbd4b 100644 --- a/global.d.ts +++ b/global.d.ts @@ -6,4 +6,4 @@ interface KeywordSearchSchema { /** * Union type of schema */ -declare type RuntimeMessageSchema = KeywordSearchSchema; +declare type ServiceWorkerMessage = KeywordSearchSchema; diff --git a/src/manifest.json b/src/manifest.json index c849691..34954ba 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -19,7 +19,7 @@ "commands": { "_execute_action": { "suggested_key": { - "default": "Shift+Alt+Z" + "default": "Alt+Shift+Z" } } }, diff --git a/src/scripts/background.ts b/src/scripts/background.ts index 202368e..6e7a185 100644 --- a/src/scripts/background.ts +++ b/src/scripts/background.ts @@ -9,7 +9,7 @@ import { KeywordSearch } from "./background/keyword-search.js"; const keywordSearch = new KeywordSearch(); -chrome.runtime.onMessage.addListener((message: RuntimeMessageSchema, sender, sendResponse) => { +chrome.runtime.onMessage.addListener((message: ServiceWorkerMessage, sender, sendResponse) => { if (!message) return; switch (message.type) { diff --git a/src/scripts/background/hanzi-to-pinyin.ts b/src/scripts/background/hanzi-to-pinyin.ts index 575a36d..77fe9c6 100644 --- a/src/scripts/background/hanzi-to-pinyin.ts +++ b/src/scripts/background/hanzi-to-pinyin.ts @@ -388,7 +388,7 @@ class Token implements IToken { /** * @return {boolean} */ -function hasChinaCollator() { +function hasChinaCollator(): boolean { // Check if zh_CN collation data is available const locale = Intl.Collator.supportedLocalesOf([LOCALE_CHINA]); const hasChinaCollator = locale.some((lang) => lang === LOCALE_CHINA); @@ -408,7 +408,7 @@ function hasChinaCollator() { * * @return {boolean} - true when the table looks correct. */ -function doSelfValidation() { +function doSelfValidation(): boolean { let lastChar = UNIHANS[0]; let lastString = lastChar.toString(); for (const c of UNIHANS) { @@ -439,7 +439,7 @@ function doSelfValidation() { * @param {string} character - The character to generate the token from. * @returns {Token} The generated token. */ -function getToken(character: string) { +function getToken(character: string): Token { const token = new Token(); const letter = character.toString(); @@ -527,7 +527,7 @@ function addToken(sb: StringBuilder, tokens: Token[], tokenType: number) { * @param {string} input * @return {Token[]} */ -export function getPinyinFromHanzi(input: string) { +export function getPinyinFromHanzi(input: string): Token[] { if (typeof input !== "string") { throw new Error("`input` must be string."); } diff --git a/src/scripts/popup.ts b/src/scripts/popup.ts index 2256ba8..0e457a1 100644 --- a/src/scripts/popup.ts +++ b/src/scripts/popup.ts @@ -72,10 +72,6 @@ class ExtensionManager { this.container.textContent = ""; } - /** - * @param {string} [input] - * @return {chrome.management.ExtensionInfo[]} - */ async getTargetExtensionInfos(input = ""): Promise { return Array.from(await this.fetchKeywordSearch(input)).filter( (item) => !(item.id === chrome.runtime.id || this.excludeTypeSet.has(item.type)),