diff --git a/components/DatetimeToTimestamp.tsx b/components/DatetimeToTimestamp.tsx index 389c45f..7789e29 100644 --- a/components/DatetimeToTimestamp.tsx +++ b/components/DatetimeToTimestamp.tsx @@ -49,31 +49,25 @@ const TIMESTAMP_UNITS = [ ]; export function DatetimeToTimestamp() { - /** @type {[string, function]} 输入的日期时间字符串 */ const [dateValue, setDateValue] = useState(() => formatWithZone(Date.now(), 'Asia/Shanghai')); - /** @type {[string, function]} 选择的时区 */ const [selectedZone, setSelectedZone] = useState('Asia/Shanghai'); - /** @type {[string, function]} 转换结果 */ const [result, setResult] = useState(''); - /** @type {[string, function]} 时间戳单位 ('milliseconds' | 'seconds') */ const [unit, setUnit] = useState('milliseconds'); - /** @type {[string, function]} 错误信息 */ const [error, setError] = useState(''); /** * 转换日期时间为时间戳 - * @type {function(): void} */ const handleConvertDatetimeToTimestamp = useCallback(() => { try { setError(''); const timestamp = formatWithDate(dateValue, selectedZone); - if (isNaN(timestamp)) { + if (typeof timestamp !== 'number' || isNaN(timestamp)) { setError('无效的日期时间格式'); setResult(''); return; @@ -90,7 +84,6 @@ export function DatetimeToTimestamp() { /** * 处理日期时间输入变化 - * @type {function(React.ChangeEvent): void} */ const handleDateChange = useCallback((e) => { setDateValue(e.target.value); @@ -99,7 +92,6 @@ export function DatetimeToTimestamp() { /** * 处理时区选择变化 - * @type {function(React.ChangeEvent): void} */ const handleZoneChange = useCallback((e) => { setSelectedZone(e.target.value); @@ -107,7 +99,6 @@ export function DatetimeToTimestamp() { /** * 处理时间戳单位变化 - * @type {function(React.ChangeEvent): void} */ const handleUnitChange = useCallback( (e) => { diff --git a/components/TimestampExecution.tsx b/components/TimestampExecution.tsx index 1937419..efb9217 100644 --- a/components/TimestampExecution.tsx +++ b/components/TimestampExecution.tsx @@ -1,16 +1,9 @@ -import { useEffect, useState, useRef, useCallback } from 'react'; +import { useEffect, useState, useCallback } from 'react'; import CopyButton from './CopyButton'; /** * 时间戳显示和执行组件 * - * 功能特性: - * 1. 实时显示当前时间戳(毫秒/秒) - * 2. 支持毫秒和秒单位切换 - * 3. 支持启动/停止时间戳自动更新 - * 4. 提供复制时间戳功能 - * 5. 响应式设计和良好的可访问性 - * * @component * @example * ```jsx @@ -29,9 +22,6 @@ export function TimestampExecution() { /** @type {[boolean, function]} 时间戳是否正在自动更新 */ const [isRunningTimestamp, setIsRunningTimestamp] = useState(true); - /** @type {React.RefObject} 定时器引用,用于清理 */ - const timerRef = useRef(null); - /** * 计算显示的时间戳值 * @type {number} @@ -40,10 +30,6 @@ export function TimestampExecution() { ? currentTimestamp : Math.floor(currentTimestamp / 1000); - /** - * 计算单位文本 - * @type {string} - */ const unitText = showMilliseconds ? '毫秒' : '秒'; /** @@ -51,32 +37,21 @@ export function TimestampExecution() { * 根据 isRunningTimestamp 和 showMilliseconds 控制定时器的启停和间隔 */ useEffect(() => { - // 清除之前的定时器 - if (timerRef.current) { - clearInterval(timerRef.current); - timerRef.current = null; - } + let timer: number; - // 如果需要运行,创建新的定时器 if (isRunningTimestamp) { const interval = showMilliseconds ? 100 : 1000; - timerRef.current = setInterval(() => { + timer = window.setInterval(() => { setCurrentTimestamp(Math.floor(Date.now())); }, interval); } // 清理函数 - return () => { - if (timerRef.current) { - clearInterval(timerRef.current); - timerRef.current = null; - } - }; + return () => clearInterval(timer); }, [isRunningTimestamp, showMilliseconds]); /** * 切换时间戳显示单位(毫秒/秒) - * @type {function(): void} */ const toggleUnit = useCallback(() => { setShowMilliseconds((prev) => !prev); @@ -84,7 +59,6 @@ export function TimestampExecution() { /** * 切换时间戳自动更新状态(启动/停止) - * @type {function(): void} */ const toggleTimestamp = useCallback(() => { setIsRunningTimestamp((prev) => !prev); diff --git a/utils/db.tsx b/utils/db.tsx deleted file mode 100644 index 32166ce..0000000 --- a/utils/db.tsx +++ /dev/null @@ -1,7 +0,0 @@ -import Dexie from "dexie"; - -export const db = new Dexie("testImagesDb"); - -db.version(1).stores({ - images: '++id, created, source' -}); \ No newline at end of file diff --git a/utils/env.tsx b/utils/env.tsx deleted file mode 100644 index 836b527..0000000 --- a/utils/env.tsx +++ /dev/null @@ -1,7 +0,0 @@ -/** - * 判断当前是否处于 Chrome 插件环境 - * @returns {false|chrome.storage.LocalStorageArea} - */ -export const isExtension = () => { - return typeof chrome !== 'undefined' && chrome.storage && chrome.storage.local; -} \ No newline at end of file diff --git a/utils/storageAdapter.tsx b/utils/storageAdapter.tsx deleted file mode 100644 index 355f684..0000000 --- a/utils/storageAdapter.tsx +++ /dev/null @@ -1,30 +0,0 @@ -// 判断当前是否处于 Chrome 插件环境 -const isExtension = typeof chrome !== 'undefined' && chrome.storage && chrome.storage.local; - -const storageAdapter = { - // 获取数据 - get: async (key) => { - if (isExtension) { - const result = await chrome.storage.local.get([key]); - return result[key]; - } else { - const item = localStorage.getItem(key); - try { - return JSON.parse(item); // 保持与插件版一致的对象处理 - } catch { - return item; - } - } - }, - - // 设置数据 - set: async (key, value) => { - if (isExtension) { - await chrome.storage.local.set({[key]: value}); - } else { - localStorage.setItem(key, JSON.stringify(value)); - } - } -}; - -export default storageAdapter; \ No newline at end of file