From b4bda2d8e1b5bd625230db5824e961137e11e456 Mon Sep 17 00:00:00 2001 From: kang Date: Fri, 25 Oct 2024 22:05:52 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=ED=83=80=EC=9E=85=20=EC=97=90=EB=9F=AC?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/background/index.ts | 10 +++++----- src/content/components/Trigger.tsx | 13 +++++++++++-- src/content/components/setting/Shortcut.tsx | 4 ++-- src/content/components/task/TaskCard.tsx | 2 +- src/context/themeContext.ts | 2 +- src/utils/cheerioUtils.ts | 2 +- src/utils/getLinkId.ts | 13 ++++++++++--- 7 files changed, 31 insertions(+), 15 deletions(-) diff --git a/src/background/index.ts b/src/background/index.ts index 25b1908..8570400 100644 --- a/src/background/index.ts +++ b/src/background/index.ts @@ -1,13 +1,13 @@ chrome.runtime.onInstalled.addListener(async () => { - for (const cs of chrome.runtime.getManifest().content_scripts) { - for (const tab of await chrome.tabs.query({ url: cs.matches })) { + for (const cs of chrome.runtime.getManifest().content_scripts ?? []) { + for (const tab of await chrome.tabs.query({ url: cs.matches ?? [] })) { chrome.scripting.executeScript({ - target: { tabId: tab.id }, - files: cs.js, + target: { tabId: tab.id ?? 0 }, + files: cs.js ?? [], }) cs.css?.forEach(css => { chrome.scripting.insertCSS({ - target: { tabId: tab.id }, + target: { tabId: tab.id ?? 0 }, files: [css], }) }) diff --git a/src/content/components/Trigger.tsx b/src/content/components/Trigger.tsx index 6df51ae..f4f9e13 100644 --- a/src/content/components/Trigger.tsx +++ b/src/content/components/Trigger.tsx @@ -7,12 +7,21 @@ import { MainModal } from './MainModal' import { useShadowRoot } from '@/hooks/useShadowRoot' import { useShortcutStore } from '@/storage/useShortcutStore' import { useStorageStore } from '@/storage/useStorageStore' +import type { StorageData } from '@/types' const isActiveElementEditable = (element: Element | null): boolean => { return element instanceof HTMLInputElement || element instanceof HTMLTextAreaElement } -const TriggerButton = ({ isOpen, onClick, settings }) => ( +const TriggerButton = ({ + isOpen, + onClick, + settings, +}: { + isOpen: boolean + onClick: () => void + settings: StorageData['settings'] +}) => (
{ const activeElement = shadowRoot?.activeElement - if (isEditing || isActiveElementEditable(activeElement)) { + if (isEditing || isActiveElementEditable(activeElement ?? null)) { return } diff --git a/src/content/components/setting/Shortcut.tsx b/src/content/components/setting/Shortcut.tsx index 4f3d01b..667e34d 100644 --- a/src/content/components/setting/Shortcut.tsx +++ b/src/content/components/setting/Shortcut.tsx @@ -42,8 +42,8 @@ export function Shortcut() { if (key.length === 1 || ['F1', 'F2', 'F3', 'F4', 'F5', 'F6', 'F7', 'F8', 'F9', 'F10', 'F11', 'F12'].includes(key)) { let processedKey = key.toLowerCase() - if (KOREAN_TO_ENGLISH[processedKey]) { - processedKey = KOREAN_TO_ENGLISH[processedKey] + if (KOREAN_TO_ENGLISH[processedKey as keyof typeof KOREAN_TO_ENGLISH]) { + processedKey = KOREAN_TO_ENGLISH[processedKey as keyof typeof KOREAN_TO_ENGLISH] } const newShortcut = [ diff --git a/src/content/components/task/TaskCard.tsx b/src/content/components/task/TaskCard.tsx index 4b7ee11..baf548c 100644 --- a/src/content/components/task/TaskCard.tsx +++ b/src/content/components/task/TaskCard.tsx @@ -5,7 +5,7 @@ import { Video, FileText, CheckCircle, AlertTriangle, Clock, XCircle } from 'luc import type { Activity } from '@/types' import { cn } from '@/utils/cn' -const StatusBadge = ({ isExpired, hasSubmitted }) => { +const StatusBadge = ({ isExpired, hasSubmitted }: { isExpired: boolean; hasSubmitted: boolean }) => { if (isExpired && !hasSubmitted) { return ( diff --git a/src/context/themeContext.ts b/src/context/themeContext.ts index 696c278..da5c865 100644 --- a/src/context/themeContext.ts +++ b/src/context/themeContext.ts @@ -7,7 +7,7 @@ type ThemeContextValue = { setTheme: (theme: T) => void } -export const ThemeContext = createContext(null) +export const ThemeContext = createContext(null) export const useThemeContext = () => { const context = useContext(ThemeContext) diff --git a/src/utils/cheerioUtils.ts b/src/utils/cheerioUtils.ts index d4e23b4..79f7ffa 100644 --- a/src/utils/cheerioUtils.ts +++ b/src/utils/cheerioUtils.ts @@ -9,4 +9,4 @@ export const mapElement = (elements: Cheerio, callback: (i: number, } export const getText = ($el: Cheerio): string => $el.text().trim() -export const getAttr = ($el: Cheerio, attr: string): string => $el.attr(attr) || '' +export const getAttr = ($el: Cheerio, attr: string): string | undefined => $el.attr(attr) diff --git a/src/utils/getLinkId.ts b/src/utils/getLinkId.ts index f34986c..79dedf5 100644 --- a/src/utils/getLinkId.ts +++ b/src/utils/getLinkId.ts @@ -1,4 +1,11 @@ -export function getLinkId(link: string) { - if (!link) return '' - return new URL(link).searchParams.get('id') +export function getLinkId(link?: string) { + if (link == null) { + return '' + } + + try { + return new URL(link).searchParams.get('id') ?? '' + } catch { + return '' + } }