7167a43763
核心功能新增 工具套件扩展 JSON 工具(差异比较、格式化、转 YAML/TOML、压缩) Base64 转换器(文本/文件/图像编解码) Markdown ↔ HTML 双向转换 JWT 解析器 文本统计工具 二维码生成/解析(替换库以减小体积) 表单工具(已移除) 表单映射、智能填充、高亮定位功能已移除 架构与工程改进 技术栈升级 引入 @webext-core/messaging 重构消息通信 添加 @dnd-kit 支持功能列表拖拽排序 引入 i18next 实现中英文国际化 使用 MUI 主题系统替代硬编码样式,支持暗色模式 代码质量 统一组件导出为默认导出 提取公共组件(TextInputArea、SwitchButtonGroup、PageHeader、DecodeResultPaper) 使用 useStorageState 钩子统一管理存储状态 添加 PageErrorBoundary 页面级错误边界 实现组件懒加载优化首屏性能 关键重构 路由系统重构 — 支持独立标签页模式,合并路由与功能配置 状态管理优化 — 存储状态增加快照机制、验证器和防抖处理 剪贴板与打印工具 — 统一为 async/await 形式,修复重复触发问题 存储清理器 — 使用 TextEncoder 准确计算 UTF-8 字节数,支持 TB 单位 测试与 CI 测试覆盖 — 为新增工具、公共组件、边界场景补充单元测试 CI 精简 — 移除 Firefox 测试,仅保留 Chrome;修正类型检查命令
156 lines
4.6 KiB
TypeScript
156 lines
4.6 KiB
TypeScript
import { useMemo, useState } from 'react';
|
|
import { Box, Container, Paper, Stack, Typography } from '@mui/material';
|
|
import { useSnackbar } from '@/components/GlobalSnackbar';
|
|
import VpnKeyIcon from '@mui/icons-material/VpnKey';
|
|
import PageHeader from '@/components/PageHeader';
|
|
import { stringifyJson, parseJwt } from '@/utils/jwt';
|
|
import CopyButton from '@/components/CopyButton';
|
|
import TextInputArea from '@/components/TextInputArea';
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
interface SectionProps {
|
|
title: string;
|
|
content: unknown;
|
|
color: string;
|
|
}
|
|
|
|
const Section = ({ title, content, color }: SectionProps) => {
|
|
const { t } = useTranslation(['jwt']);
|
|
return (
|
|
<Paper
|
|
variant="outlined"
|
|
sx={{
|
|
p: 2,
|
|
borderRadius: 3,
|
|
borderColor: `${color}40`,
|
|
bgcolor: `${color}05`,
|
|
position: 'relative',
|
|
}}
|
|
>
|
|
<Box sx={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', mb: 1 }}>
|
|
<Typography variant="subtitle2" sx={{ fontWeight: 800, color: color, letterSpacing: 0.5 }}>
|
|
{title}
|
|
</Typography>
|
|
<Box sx={{ display: 'flex', gap: 0.5 }}>
|
|
<CopyButton text={JSON.stringify(content)} size="small" />
|
|
</Box>
|
|
</Box>
|
|
<Box
|
|
component="pre"
|
|
sx={{
|
|
m: 0,
|
|
p: 1.5,
|
|
bgcolor: 'rgba(255,255,255,0.6)',
|
|
borderRadius: 2,
|
|
fontSize: '0.8rem',
|
|
fontFamily: 'monospace',
|
|
overflowX: 'auto',
|
|
whiteSpace: 'pre-wrap',
|
|
wordBreak: 'break-all',
|
|
border: '1px solid rgba(0,0,0,0.05)',
|
|
}}
|
|
>
|
|
{content ? stringifyJson(content) : t('jwt:invalidFormat')}
|
|
</Box>
|
|
</Paper>
|
|
);
|
|
};
|
|
|
|
export default function Index() {
|
|
const { showMessage } = useSnackbar();
|
|
const { t } = useTranslation(['jwt']);
|
|
const [jwtInput, setJwtInput] = useState('');
|
|
|
|
const result = useMemo(() => {
|
|
if (!jwtInput.trim()) {
|
|
return null;
|
|
}
|
|
return parseJwt(jwtInput);
|
|
}, [jwtInput]);
|
|
|
|
return (
|
|
<Box>
|
|
<Container sx={{ p: 2 }}>
|
|
<PageHeader
|
|
title={t('jwt:pageTitle')}
|
|
subtitle={t('jwt:pageSubtitle')}
|
|
icon={<VpnKeyIcon />}
|
|
/>
|
|
|
|
<Stack spacing={2.5}>
|
|
{/* Input Area */}
|
|
<TextInputArea
|
|
minRows={4}
|
|
placeholder={t('jwt:placeholder')}
|
|
value={jwtInput}
|
|
onChange={(val) => {
|
|
const cleaned = val.replace(/^Bearer\s*/i, '').trim();
|
|
setJwtInput(cleaned);
|
|
}}
|
|
allowCopy={true}
|
|
showClear={true}
|
|
showMessage={showMessage}
|
|
externalError={result?.error}
|
|
/>
|
|
|
|
{result && !result.error && (
|
|
<Stack spacing={2}>
|
|
<Section
|
|
title={t('jwt:headerTitle')}
|
|
content={result.header}
|
|
color="#fb015b" // JWT.io Header Color
|
|
/>
|
|
<Section
|
|
title={t('jwt:payloadTitle')}
|
|
content={result.payload}
|
|
color="#d63aff" // JWT.io Payload Color
|
|
/>
|
|
<Paper
|
|
variant="outlined"
|
|
sx={{
|
|
p: 2,
|
|
borderRadius: 3,
|
|
borderColor: 'primary.light',
|
|
bgcolor: 'primary.lighter',
|
|
}}
|
|
>
|
|
<Box
|
|
sx={{
|
|
display: 'flex',
|
|
justifyContent: 'space-between',
|
|
alignItems: 'center',
|
|
mb: 1,
|
|
}}
|
|
>
|
|
<Typography
|
|
variant="subtitle2"
|
|
sx={{ fontWeight: 800, color: 'info.main', letterSpacing: 0.5 }}
|
|
>
|
|
{t('jwt:signatureTitle')}
|
|
</Typography>
|
|
<CopyButton text={JSON.stringify(result.raw.signature)} size="small" />
|
|
</Box>
|
|
<Typography
|
|
variant="body2"
|
|
sx={{
|
|
fontFamily: 'monospace',
|
|
fontSize: '0.8rem',
|
|
wordBreak: 'break-all',
|
|
color: 'text.secondary',
|
|
bgcolor: 'rgba(255,255,255,0.6)',
|
|
p: 1.5,
|
|
borderRadius: 2,
|
|
border: '1px solid rgba(0,0,0,0.05)',
|
|
}}
|
|
>
|
|
{result.signature || t('jwt:noSignature')}
|
|
</Typography>
|
|
</Paper>
|
|
</Stack>
|
|
)}
|
|
</Stack>
|
|
</Container>
|
|
</Box>
|
|
);
|
|
}
|