Files
tools/index.html
T
2026-11-02 16:01:16 +08:00

1706 lines
46 KiB
HTML

<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta
name="description"
content="功能工具箱 · 电费计算、进制转换、颜色选择、JSON 格式化、URL 编解码、图片转 PDF、图片压缩,全部在浏览器本地完成。"
/>
<title>功能工具箱</title>
<link rel="icon" href="assets/favicon.svg" type="image/svg+xml" />
<link rel="stylesheet" href="assets/styles.css" />
<script src="assets/common.js"></script>
<style>
html,
body {
height: 100%;
}
body {
overflow: hidden;
}
.app {
display: flex;
height: 100vh;
height: 100dvh;
overflow: hidden;
}
/* ================= 侧边栏 ================= */
.sidebar {
position: relative;
z-index: 40;
flex: 0 0 auto;
width: 268px;
display: flex;
flex-direction: column;
gap: 12px;
padding: 14px;
border-right: 1px solid var(--border);
background: var(--surface);
transition: width 0.22s ease, padding 0.22s ease;
}
.brand {
display: flex;
align-items: center;
gap: 10px;
padding: 4px 4px 2px;
min-height: 44px;
}
.brand-mark {
width: 36px;
height: 36px;
flex: none;
display: grid;
place-items: center;
padding: 0;
border: none;
border-radius: 11px;
background: linear-gradient(135deg, #6366f1, #a855f7);
color: #fff;
cursor: pointer;
box-shadow: 0 8px 18px -8px rgba(99, 102, 241, 0.7);
}
.brand-mark svg {
width: 20px;
height: 20px;
}
/* 所有线性图标统一描边 */
.nav-icon svg,
.icon-btn svg,
.crumb svg,
.side-search svg,
.collapse-btn svg,
.mobile-close svg,
.hero-search svg,
.tile svg,
.info-icon svg,
.tool-card .go,
[data-theme-toggle] svg {
fill: none;
stroke: currentColor;
stroke-width: 1.8;
stroke-linecap: round;
stroke-linejoin: round;
}
.brand-mark svg {
fill: currentColor;
stroke: none;
}
.brand-text {
display: flex;
flex-direction: column;
line-height: 1.3;
white-space: nowrap;
overflow: hidden;
}
.brand-text strong {
font-size: 0.95rem;
letter-spacing: -0.01em;
}
.brand-text span {
font-size: 0.66rem;
letter-spacing: 0.16em;
text-transform: uppercase;
color: var(--text-muted);
}
.collapse-btn {
margin-left: auto;
width: 30px;
height: 30px;
flex: none;
display: grid;
place-items: center;
border: 1px solid transparent;
border-radius: 8px;
background: transparent;
color: var(--text-muted);
cursor: pointer;
transition: all var(--rate) ease;
}
.collapse-btn:hover {
background: var(--surface-2);
color: var(--text);
}
.collapse-btn svg {
width: 17px;
height: 17px;
transition: transform 0.22s ease;
}
.mobile-close {
display: none;
margin-left: auto;
width: 30px;
height: 30px;
place-items: center;
border: none;
border-radius: 8px;
background: transparent;
color: var(--text-muted);
cursor: pointer;
}
.mobile-close:hover {
background: var(--surface-2);
color: var(--text);
}
.mobile-close svg {
width: 17px;
height: 17px;
}
body.sidebar-collapsed .collapse-btn svg {
transform: rotate(180deg);
}
.side-search {
position: relative;
}
.side-search svg {
position: absolute;
left: 11px;
top: 50%;
width: 15px;
height: 15px;
transform: translateY(-50%);
color: var(--text-muted);
pointer-events: none;
}
.side-search input {
height: 38px;
padding-left: 33px;
padding-right: 46px;
background: var(--surface-2);
border-color: transparent;
font-size: 0.84rem;
}
.side-search input:focus {
background: var(--surface);
border-color: var(--accent);
}
.side-search .kbd {
position: absolute;
right: 9px;
top: 50%;
transform: translateY(-50%);
pointer-events: none;
}
.nav {
flex: 1;
min-height: 0;
overflow-y: auto;
display: flex;
flex-direction: column;
gap: 2px;
padding: 2px 0;
}
.nav-section {
padding: 12px 10px 5px;
font-size: 0.66rem;
font-weight: 700;
letter-spacing: 0.14em;
text-transform: uppercase;
color: var(--text-muted);
}
.nav-item {
position: relative;
display: flex;
align-items: center;
gap: 10px;
width: 100%;
padding: 8px 10px;
border: none;
border-radius: 10px;
background: transparent;
color: var(--text-secondary);
font-size: 0.855rem;
font-weight: 500;
text-align: left;
cursor: pointer;
transition:
background var(--rate) ease,
color var(--rate) ease;
}
.nav-item:hover {
background: var(--surface-2);
color: var(--text);
}
.nav-item.active {
background: var(--accent-soft);
color: var(--accent);
font-weight: 600;
}
.nav-item.active::before {
content: "";
position: absolute;
left: 0;
top: 9px;
bottom: 9px;
width: 3px;
border-radius: 3px;
background: var(--accent);
}
.nav-icon {
width: 20px;
height: 20px;
flex: none;
display: grid;
place-items: center;
}
.nav-icon svg {
width: 17px;
height: 17px;
}
.nav-label {
min-width: 0;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.nav-item .nav-dot {
margin-left: auto;
width: 5px;
height: 5px;
border-radius: 50%;
background: var(--accent);
opacity: 0;
}
.nav-item.active .nav-dot {
opacity: 1;
}
.side-foot {
flex: none;
padding-top: 10px;
border-top: 1px solid var(--border);
}
.side-foot .version {
display: flex;
align-items: center;
justify-content: space-between;
padding: 4px 10px 0;
font-size: 0.68rem;
color: var(--text-muted);
}
.side-foot .dot {
display: inline-flex;
align-items: center;
gap: 5px;
}
.side-foot .dot::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--success);
}
/* 收起状态 */
body.sidebar-collapsed .sidebar {
width: 74px;
padding: 14px 10px;
}
body.sidebar-collapsed .brand {
flex-direction: column;
justify-content: flex-start;
gap: 8px;
min-height: 0;
}
body.sidebar-collapsed .collapse-btn {
margin-left: 0;
width: 28px;
height: 28px;
background: var(--surface-2);
border-radius: 8px;
}
body.sidebar-collapsed .brand-text,
body.sidebar-collapsed .side-search,
body.sidebar-collapsed .nav-section,
body.sidebar-collapsed .nav-label,
body.sidebar-collapsed .nav-dot,
body.sidebar-collapsed .side-foot .version {
display: none;
}
body.sidebar-collapsed .nav-item {
justify-content: center;
padding: 9px;
}
body.sidebar-collapsed .nav-item.active::before {
left: 2px;
}
body.sidebar-collapsed .side-foot {
padding-top: 8px;
}
/* ================= 主区域 ================= */
.main {
flex: 1;
min-width: 0;
display: flex;
flex-direction: column;
height: 100vh;
height: 100dvh;
overflow: hidden;
background: var(--bg);
}
.topbar {
flex: none;
height: 58px;
display: flex;
align-items: center;
gap: 10px;
padding: 0 clamp(14px, 3vw, 26px);
border-bottom: 1px solid var(--border);
background: var(--surface);
}
.icon-btn.menu-btn {
display: none;
}
.icon-btn {
width: 36px;
height: 36px;
flex: none;
display: grid;
place-items: center;
border: 1px solid transparent;
border-radius: 9px;
background: transparent;
color: var(--text-secondary);
cursor: pointer;
transition: all var(--rate) ease;
}
.icon-btn:hover {
background: var(--surface-2);
color: var(--text);
}
.icon-btn svg {
width: 18px;
height: 18px;
}
.crumb {
display: flex;
align-items: center;
gap: 7px;
min-width: 0;
font-size: 0.84rem;
color: var(--text-muted);
}
.crumb svg {
width: 14px;
height: 14px;
flex: none;
}
.crumb strong {
color: var(--text);
font-weight: 600;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.top-actions {
margin-left: auto;
display: flex;
align-items: center;
gap: 4px;
}
.content {
flex: 1;
min-height: 0;
overflow: auto;
scroll-behavior: smooth;
}
.content.is-frame {
overflow: hidden;
display: flex;
}
.content iframe {
flex: 1;
width: 100%;
height: 100%;
border: none;
display: block;
background: var(--bg);
}
/* ================= 首页 ================= */
.home {
width: 100%;
max-width: 1160px;
margin: 0 auto;
padding: clamp(20px, 3.6vw, 40px);
}
.hero {
position: relative;
overflow: hidden;
padding: clamp(26px, 4.6vw, 52px);
border: 1px solid var(--border);
border-radius: 22px;
background:
radial-gradient(
720px 300px at 0% 0%,
rgba(99, 102, 241, 0.16),
transparent 62%
),
radial-gradient(
620px 300px at 100% 0%,
rgba(168, 85, 247, 0.14),
transparent 62%
),
var(--surface);
box-shadow: var(--shadow-sm);
}
.hero-badge {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 4px 10px 4px 8px;
border-radius: 999px;
background: var(--surface);
border: 1px solid var(--border);
color: var(--text-secondary);
font-size: 0.72rem;
font-weight: 600;
box-shadow: var(--shadow-sm);
}
.hero-badge .pulse {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--success);
box-shadow: 0 0 0 3px var(--success-soft);
}
.hero h1 {
margin: 16px 0 10px;
font-size: clamp(1.75rem, 4vw, 2.6rem);
line-height: 1.16;
letter-spacing: -0.035em;
font-weight: 750;
max-width: 16em;
}
.grad {
background: linear-gradient(100deg, #6366f1, #a855f7 60%, #ec4899);
-webkit-background-clip: text;
background-clip: text;
color: transparent;
}
.hero > p {
max-width: 36em;
color: var(--text-secondary);
font-size: 0.94rem;
}
.hero-search {
position: relative;
max-width: 540px;
margin-top: 22px;
}
.hero-search svg {
position: absolute;
left: 14px;
top: 50%;
width: 17px;
height: 17px;
transform: translateY(-50%);
color: var(--text-muted);
pointer-events: none;
}
.hero-search input {
height: 46px;
padding-left: 41px;
padding-right: 60px;
border-radius: 12px;
background: var(--surface);
border-color: var(--border-strong);
font-size: 0.9rem;
box-shadow: var(--shadow-sm);
}
.hero-search .kbd {
position: absolute;
right: 12px;
top: 50%;
transform: translateY(-50%);
pointer-events: none;
}
.hero-stats {
display: flex;
flex-wrap: wrap;
gap: 26px;
margin-top: 26px;
padding-top: 20px;
border-top: 1px solid var(--border);
}
.hero-stat b {
display: block;
font-size: 1.15rem;
font-weight: 700;
letter-spacing: -0.02em;
}
.hero-stat span {
font-size: 0.75rem;
color: var(--text-muted);
}
.section-head {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin: 28px 2px 12px;
}
.section-head h2 {
font-size: 1.02rem;
font-weight: 700;
}
.section-head span {
font-size: 0.78rem;
color: var(--text-muted);
}
.tools-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
gap: 12px;
}
.tool-card {
position: relative;
display: flex;
flex-direction: column;
gap: 10px;
padding: 18px;
border: 1px solid var(--border);
border-radius: 16px;
background: var(--surface);
text-align: left;
cursor: pointer;
transition:
transform 0.18s ease,
border-color 0.18s ease,
box-shadow 0.18s ease;
}
.tool-card:hover {
transform: translateY(-2px);
border-color: var(--accent);
box-shadow: var(--shadow-md);
}
.tool-card:active {
transform: translateY(0);
}
.tool-card h3 {
font-size: 0.94rem;
font-weight: 650;
margin-top: 2px;
}
.tool-card p {
font-size: 0.8rem;
line-height: 1.55;
color: var(--text-secondary);
padding-right: 12px;
}
.tool-card .go {
position: absolute;
top: 18px;
right: 16px;
width: 18px;
height: 18px;
color: var(--text-muted);
opacity: 0;
transform: translateX(-4px);
transition: all 0.18s ease;
}
.tool-card:hover .go {
opacity: 1;
transform: none;
color: var(--accent);
}
.tile {
width: 42px;
height: 42px;
flex: none;
display: grid;
place-items: center;
border-radius: 12px;
background: var(--tile-bg, var(--surface-2));
color: var(--tile-fg, var(--text-secondary));
}
.tile svg {
width: 21px;
height: 21px;
}
.tile--indigo {
--tile-bg: #eef2ff;
--tile-fg: #4f46e5;
}
.tile--amber {
--tile-bg: #fff7e6;
--tile-fg: #c2760a;
}
.tile--rose {
--tile-bg: #fff0f3;
--tile-fg: #e11d48;
}
.tile--emerald {
--tile-bg: #e9fbf3;
--tile-fg: #0f9d76;
}
.tile--sky {
--tile-bg: #eaf5ff;
--tile-fg: #0369a1;
}
.tile--violet {
--tile-bg: #f5efff;
--tile-fg: #7c3aed;
}
.tile--teal {
--tile-bg: #e8faf8;
--tile-fg: #0d9488;
}
.tile--slate {
--tile-bg: #f1f3f8;
--tile-fg: #64748b;
}
html[data-theme="dark"] .tile--indigo {
--tile-bg: rgba(99, 102, 241, 0.16);
--tile-fg: #a5b4fc;
}
html[data-theme="dark"] .tile--amber {
--tile-bg: rgba(245, 158, 11, 0.14);
--tile-fg: #fcd34d;
}
html[data-theme="dark"] .tile--rose {
--tile-bg: rgba(244, 63, 94, 0.14);
--tile-fg: #fda4af;
}
html[data-theme="dark"] .tile--emerald {
--tile-bg: rgba(16, 185, 129, 0.14);
--tile-fg: #6ee7b7;
}
html[data-theme="dark"] .tile--sky {
--tile-bg: rgba(14, 165, 233, 0.14);
--tile-fg: #7dd3fc;
}
html[data-theme="dark"] .tile--violet {
--tile-bg: rgba(139, 92, 246, 0.16);
--tile-fg: #c4b5fd;
}
html[data-theme="dark"] .tile--teal {
--tile-bg: rgba(20, 184, 166, 0.14);
--tile-fg: #5eead4;
}
html[data-theme="dark"] .tile--slate {
--tile-bg: rgba(100, 116, 139, 0.16);
--tile-fg: #cbd5e1;
}
.info-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(215px, 1fr));
gap: 12px;
margin-top: 26px;
}
.info-card {
display: flex;
gap: 12px;
align-items: flex-start;
padding: 16px;
border: 1px solid var(--border);
border-radius: 14px;
background: var(--surface);
}
.info-card .info-icon {
width: 34px;
height: 34px;
flex: none;
display: grid;
place-items: center;
border-radius: 9px;
background: var(--accent-soft);
color: var(--accent);
}
.info-card .info-icon svg {
width: 17px;
height: 17px;
}
.info-card h3 {
font-size: 0.85rem;
font-weight: 650;
margin-bottom: 2px;
}
.info-card p {
font-size: 0.76rem;
line-height: 1.55;
color: var(--text-secondary);
}
.page-foot {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
gap: 8px;
margin-top: 30px;
padding-top: 16px;
border-top: 1px solid var(--border);
font-size: 0.75rem;
color: var(--text-muted);
}
.page-foot a {
color: var(--text-secondary);
}
.page-foot a:hover {
color: var(--accent);
}
.no-results {
padding: 34px 20px;
text-align: center;
border: 1px dashed var(--border-strong);
border-radius: 14px;
color: var(--text-muted);
font-size: 0.85rem;
}
.backdrop {
display: none;
}
/* ================= 响应式 ================= */
@media (max-width: 900px) {
.sidebar {
position: fixed;
top: 0;
left: 0;
bottom: 0;
width: 280px;
max-width: 86vw;
transform: translateX(-102%);
box-shadow: var(--shadow-lg);
transition: transform 0.22s ease;
}
body.sidebar-open .sidebar {
transform: translateX(0);
}
body.sidebar-open .backdrop {
display: block;
position: fixed;
inset: 0;
z-index: 30;
background: rgba(5, 7, 15, 0.5);
backdrop-filter: blur(2px);
}
body.sidebar-collapsed .sidebar {
width: 280px;
max-width: 86vw;
padding: 14px;
}
body.sidebar-collapsed .brand {
flex-direction: row;
justify-content: flex-start;
gap: 10px;
min-height: 44px;
}
body.sidebar-collapsed .brand-text {
display: flex;
}
body.sidebar-collapsed .side-search,
body.sidebar-collapsed .nav-section {
display: revert;
}
body.sidebar-collapsed .side-foot .version {
display: flex;
}
.collapse-btn {
display: none;
}
.mobile-close {
display: grid;
}
body.sidebar-collapsed .nav-label,
body.sidebar-collapsed .nav-dot {
display: block;
}
body.sidebar-collapsed .nav-item {
justify-content: flex-start;
padding: 8px 10px;
}
body.sidebar-collapsed .nav-item.active::before {
left: 0;
}
.icon-btn.menu-btn {
display: grid;
}
.topbar {
height: 54px;
}
.home {
padding: 16px;
}
.hero {
border-radius: 18px;
}
.hero-stats {
gap: 20px;
}
}
@media (max-width: 560px) {
.tools-grid {
grid-template-columns: 1fr;
}
.hero h1 {
font-size: 1.65rem;
}
.hero-search .kbd {
display: none;
}
.crumbs-home {
display: none;
}
}
</style>
</head>
<body>
<!-- 图标库 -->
<svg width="0" height="0" style="position: absolute" aria-hidden="true">
<defs>
<symbol id="i-spark" viewBox="0 0 24 24">
<path
d="M12 2.5 14.4 9.6 21.5 12l-7.1 2.4L12 21.5l-2.4-7.1L2.5 12l7.1-2.4L12 2.5Z"
fill="currentColor"
/>
</symbol>
<symbol id="i-home" viewBox="0 0 24 24">
<path d="m3 10 9-7 9 7v10a1 1 0 0 1-1 1h-5v-7H9v7H4a1 1 0 0 1-1-1V10Z" />
</symbol>
<symbol id="i-bolt" viewBox="0 0 24 24">
<path d="M13 2 4.5 13.5H11l-1 8.5L19.5 10H13l1-8Z" />
</symbol>
<symbol id="i-hash" viewBox="0 0 24 24">
<path d="M4 9h16M4 15h16M10 3 8 21M16 3l-2 18" />
</symbol>
<symbol id="i-palette" viewBox="0 0 24 24">
<path
d="M12 3a9 9 0 1 0 0 18h1.2a2.3 2.3 0 0 0 0-4.6h-.9a1.7 1.7 0 0 1 0-3.4H16a4 4 0 0 0 4-4C20 5.6 16.4 3 12 3Z"
/>
<circle cx="7.6" cy="10.6" r="0.9" />
<circle cx="11" cy="7.1" r="0.9" />
<circle cx="15.4" cy="8" r="0.9" />
</symbol>
<symbol id="i-braces" viewBox="0 0 24 24">
<path
d="M8 3H7a2 2 0 0 0-2 2v4a2 2 0 0 1-2 2 2 2 0 0 1 2 2v4a2 2 0 0 0 2 2h1M16 3h1a2 2 0 0 1 2 2v4a2 2 0 0 0 2 2 2 2 0 0 0-2 2v4a2 2 0 0 1-2 2h-1"
/>
</symbol>
<symbol id="i-link" viewBox="0 0 24 24">
<path d="M10.5 13.5a5 5 0 0 0 7.1 0l2-2a5 5 0 0 0-7.1-7.1l-1.1 1.1" />
<path d="M13.5 10.5a5 5 0 0 0-7.1 0l-2 2a5 5 0 0 0 7.1 7.1l1.1-1.1" />
</symbol>
<symbol id="i-file-image" viewBox="0 0 24 24">
<path d="M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8l-5-5Z" />
<path d="M14 3v5h5" />
<circle cx="9.8" cy="12" r="1.1" />
<path d="m7 19 3.6-3.6 2 2L16 14l2 2.2" />
</symbol>
<symbol id="i-compress" viewBox="0 0 24 24">
<path d="M9 3v4a2 2 0 0 1-2 2H3M15 3v4a2 2 0 0 0 2 2h4" />
<path d="M9 21v-4a2 2 0 0 0-2-2H3M15 21v-4a2 2 0 0 1 2-2h4" />
</symbol>
<symbol id="i-grid" viewBox="0 0 24 24">
<rect x="3" y="3" width="7" height="7" rx="1.6" />
<rect x="14" y="3" width="7" height="7" rx="1.6" />
<rect x="3" y="14" width="7" height="7" rx="1.6" />
<rect x="14" y="14" width="7" height="7" rx="1.6" />
</symbol>
<symbol id="i-search" viewBox="0 0 24 24">
<circle cx="11" cy="11" r="7" />
<path d="m20 20-3.6-3.6" />
</symbol>
<symbol id="i-sun" viewBox="0 0 24 24">
<circle cx="12" cy="12" r="4" />
<path
d="M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4"
/>
</symbol>
<symbol id="i-moon" viewBox="0 0 24 24">
<path d="M21 12.8A8.5 8.5 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8Z" />
</symbol>
<symbol id="i-panel" viewBox="0 0 24 24">
<rect x="3" y="3" width="18" height="18" rx="2.5" />
<path d="M9 3v18" />
</symbol>
<symbol id="i-close" viewBox="0 0 24 24">
<path d="M6 6l12 12M18 6 6 18" />
</symbol>
<symbol id="i-menu" viewBox="0 0 24 24">
<path d="M4 6h16M4 12h16M4 18h16" />
</symbol>
<symbol id="i-arrow-right" viewBox="0 0 24 24">
<path d="M5 12h14M13 6l6 6-6 6" />
</symbol>
<symbol id="i-external" viewBox="0 0 24 24">
<path d="M14 4h6v6M20 4l-9 9" />
<path d="M18 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h5" />
</symbol>
<symbol id="i-shield" viewBox="0 0 24 24">
<path d="M12 3 4.5 6v5c0 4.8 3.2 8.2 7.5 10 4.3-1.8 7.5-5.2 7.5-10V6L12 3Z" />
<path d="m9 12 2 2 4-4" />
</symbol>
<symbol id="i-device" viewBox="0 0 24 24">
<rect x="6" y="2.5" width="12" height="19" rx="2.5" />
<path d="M10.5 18.5h3" />
</symbol>
<symbol id="i-share" viewBox="0 0 24 24">
<circle cx="18" cy="5" r="2.5" />
<circle cx="6" cy="12" r="2.5" />
<circle cx="18" cy="19" r="2.5" />
<path d="m8.2 10.8 7.6-4.6M8.2 13.2l7.6 4.6" />
</symbol>
</defs>
</svg>
<div class="app">
<!-- 侧边栏 -->
<aside class="sidebar" id="sidebar">
<div class="brand">
<button class="brand-mark" title="返回首页" aria-label="返回首页">
<svg><use href="#i-spark"></use></svg>
</button>
<div class="brand-text">
<strong>功能工具箱</strong>
<span>Utilities</span>
</div>
<button
class="collapse-btn"
id="collapseBtn"
title="收起侧边栏"
aria-label="收起侧边栏"
>
<svg><use href="#i-panel"></use></svg>
</button>
<button
class="mobile-close"
id="closeSidebarBtn"
title="关闭菜单"
aria-label="关闭菜单"
>
<svg><use href="#i-close"></use></svg>
</button>
</div>
<div class="side-search">
<svg><use href="#i-search"></use></svg>
<input
type="search"
id="sideSearch"
placeholder="搜索工具…"
aria-label="搜索工具"
autocomplete="off"
/>
<span class="kbd">⌘K</span>
</div>
<nav class="nav" id="nav" aria-label="工具导航"></nav>
<div class="side-foot">
<button
class="nav-item"
id="themeToggle"
data-theme-toggle
title="切换主题"
>
<span class="nav-icon">
<svg class="icon-moon"><use href="#i-moon"></use></svg>
<svg class="icon-sun"><use href="#i-sun"></use></svg>
</span>
<span class="nav-label" id="themeLabel">深色模式</span>
</button>
<div class="version">
<span class="dot">本地处理</span>
<span>v2.0</span>
</div>
</div>
</aside>
<div class="backdrop" id="backdrop"></div>
<!-- 主区域 -->
<div class="main">
<header class="topbar">
<button
class="icon-btn menu-btn"
id="menuBtn"
title="打开菜单"
aria-label="打开菜单"
>
<svg><use href="#i-menu"></use></svg>
</button>
<div class="crumb">
<svg class="crumbs-home"><use href="#i-home"></use></svg>
<span class="crumbs-home">首页</span>
<span class="crumbs-home">/</span>
<strong id="crumbTitle">全部工具</strong>
</div>
<div class="top-actions">
<button
class="icon-btn hidden"
id="openExternal"
title="在新标签页打开当前工具"
aria-label="在新标签页打开当前工具"
>
<svg><use href="#i-external"></use></svg>
</button>
<button
class="icon-btn"
id="themeToggleTop"
data-theme-toggle
title="切换主题"
aria-label="切换主题"
>
<svg class="icon-moon"><use href="#i-moon"></use></svg>
<svg class="icon-sun"><use href="#i-sun"></use></svg>
</button>
</div>
</header>
<div class="content" id="content"></div>
</div>
</div>
<script>
(function () {
"use strict";
/* ================= 工具配置 ================= */
var TOOLS = [
{
key: "welcome",
name: "首页",
nav: "首页",
desc: "浏览全部工具",
icon: "home",
tint: "slate",
hash: "",
},
{
key: "calculator",
name: "电费计算器",
desc: "估算电器每日、每月与每年的用电成本,支持峰谷电价。",
url: "electricity_calculator.html",
hash: "#calculator",
icon: "bolt",
tint: "amber",
},
{
key: "number",
name: "程序员计算器",
desc: "二进制、八进制、十进制、十六进制即时互转。",
url: "number.html",
hash: "#number",
icon: "hash",
tint: "indigo",
},
{
key: "color",
name: "颜色选择器",
desc: "可视取色、RGB 调节,HEX / RGB / HSL / HSV 一键复制。",
url: "color_pick.html",
hash: "#color",
icon: "palette",
tint: "rose",
},
{
key: "json",
name: "JSON 格式化",
desc: "美化、压缩、校验 JSON,支持键名排序与语法高亮。",
url: "json_formatter.html",
hash: "#json",
icon: "braces",
tint: "emerald",
},
{
key: "url",
name: "URL 编解码",
desc: "URIComponent、完整 URL、表单与 Base64 编解码。",
url: "url_encoder.html",
hash: "#url",
icon: "link",
tint: "sky",
},
{
key: "image2pdf",
name: "图片转 PDF",
desc: "多张图片合并为 PDF,可排序、预览并自定义页面。",
url: "image_to_pdf.html",
hash: "#image2pdf",
icon: "file-image",
tint: "violet",
},
{
key: "image-compressor",
name: "图片压缩",
desc: "调节质量与格式压缩图片,支持批量下载与效果预览。",
url: "image_compressor.html",
hash: "#image-compressor",
icon: "compress",
tint: "teal",
},
{
key: "other",
name: "其他功能",
desc: "更多实用工具正在路上,欢迎提出你的需求。",
url: "other_function.html",
hash: "#other",
icon: "grid",
tint: "slate",
},
];
var TOOL_MAP = {};
TOOLS.forEach(function (tool) {
TOOL_MAP[tool.key] = tool;
});
var SIDEBAR_KEY = "toolbox-sidebar-collapsed";
var content = document.getElementById("content");
var nav = document.getElementById("nav");
var crumbTitle = document.getElementById("crumbTitle");
var openExternal = document.getElementById("openExternal");
var sideSearch = document.getElementById("sideSearch");
var themeLabel = document.getElementById("themeLabel");
var backdrop = document.getElementById("backdrop");
var activeKey = null;
var rendered = false;
var query = "";
var homeSearch = null;
/* ================= 图标 / 导航渲染 ================= */
function icon(name) {
return (
'<svg aria-hidden="true"><use href="#i-' + name + '"></use></svg>'
);
}
function buildNav() {
var html =
'<button class="nav-item" data-tool="welcome" title="首页" aria-label="首页">';
html +=
'<span class="nav-icon">' +
icon("home") +
"</span><span class=\"nav-label\">首页</span>";
html += '<span class="nav-dot"></span></button>';
html += '<div class="nav-section">工具</div>';
TOOLS.forEach(function (tool) {
if (tool.key === "welcome") return;
html +=
'<button class="nav-item" data-tool="' +
tool.key +
'" title="' +
tool.name +
'" aria-label="' +
tool.name +
'">';
html +=
'<span class="nav-icon">' +
icon(tool.icon) +
'</span><span class="nav-label">' +
tool.name +
"</span>";
html += '<span class="nav-dot"></span></button>';
});
nav.innerHTML = html;
nav.querySelectorAll(".nav-item").forEach(function (item) {
item.addEventListener("click", function () {
navigateTo(item.dataset.tool);
closeMobileSidebar();
});
});
}
/* ================= 首页 ================= */
function toolCard(tool) {
return (
'<button class="tool-card" data-tool="' +
tool.key +
'" data-search="' +
(tool.name + " " + tool.desc).toLowerCase() +
'">' +
'<span class="tile tile--' +
tool.tint +
'">' +
icon(tool.icon) +
"</span>" +
"<h3>" +
tool.name +
"</h3>" +
"<p>" +
tool.desc +
"</p>" +
'<svg class="go" aria-hidden="true"><use href="#i-arrow-right"></use></svg>' +
"</button>"
);
}
function buildHome() {
var cards = TOOLS.filter(function (tool) {
return tool.key !== "welcome";
}).map(toolCard);
return (
'<div class="home">' +
'<section class="hero">' +
'<span class="hero-badge"><span class="pulse"></span>本地运行 · 数据不出浏览器</span>' +
"<h1>一站式实用工具<br /><span class=\"grad\">打开即用</span></h1>" +
"<p>无需安装,无需登录。电费、进制、颜色、JSON、图片处理等常用能力都集中在这里。</p>" +
'<div class="hero-search">' +
icon("search") +
'<input type="search" id="heroSearch" placeholder="搜索工具,例如 JSON、颜色、图片…" aria-label="搜索工具" autocomplete="off" />' +
'<span class="kbd">⌘K</span>' +
"</div>" +
'<div class="hero-stats">' +
'<div class="hero-stat"><b>' +
(TOOLS.length - 1) +
"</b><span>实用工具</span></div>" +
'<div class="hero-stat"><b>100%</b><span>浏览器本地处理</span></div>' +
'<div class="hero-stat"><b>0</b><span>数据上传</span></div>' +
"</div>" +
"</section>" +
'<div class="section-head"><h2>全部工具</h2><span id="toolCount">' +
(TOOLS.length - 1) +
" 个工具</span></div>" +
'<div class="tools-grid" id="toolsGrid">' +
cards.join("") +
"</div>" +
'<div class="no-results hidden" id="noResults">没有找到匹配的工具,换个关键词试试。</div>' +
'<div class="info-grid">' +
'<div class="info-card"><span class="info-icon">' +
icon("shield") +
'</span><div><h3>隐私优先</h3><p>所有计算和文件处理都在本地完成,敏感数据不会离开你的设备。</p></div></div>' +
'<div class="info-card"><span class="info-icon">' +
icon("bolt") +
'</span><div><h3>即开即用</h3><p>纯前端实现,无后端依赖,加载快、响应快。</p></div></div>' +
'<div class="info-card"><span class="info-icon">' +
icon("device") +
'</span><div><h3>多端适配</h3><p>桌面与手机均可使用,侧边栏会自动收起。</p></div></div>' +
'<div class="info-card"><span class="info-icon">' +
icon("share") +
'</span><div><h3>链接直达</h3><p>每个工具都有独立地址,可以直接分享给同事或朋友。</p></div></div>' +
"</div>" +
'<div class="page-foot"><span>© ' +
new Date().getFullYear() +
' 功能工具箱 · 纯前端工具集合</span><span>定制需求请联系 <a href="mailto:gogongxt@163.com">gogongxt@163.com</a></span></div>' +
"</div>"
);
}
function bindHome() {
homeSearch = document.getElementById("heroSearch");
if (homeSearch) {
homeSearch.value = query;
homeSearch.addEventListener("input", function () {
applyFilter(homeSearch.value);
});
homeSearch.addEventListener("keydown", function (event) {
if (event.key === "Enter") {
var first = document.querySelector(
"#toolsGrid .tool-card:not(.hidden)",
);
if (first) navigateTo(first.dataset.tool);
}
});
}
content
.querySelectorAll("#toolsGrid .tool-card")
.forEach(function (card) {
card.addEventListener("click", function () {
navigateTo(card.dataset.tool);
});
});
applyFilter(query);
}
/* ================= 路由 ================= */
function toolFromLocation() {
var hash = window.location.hash.slice(1);
if (!hash) return "welcome";
if (TOOL_MAP[hash]) return hash;
for (var i = 0; i < TOOLS.length; i += 1) {
if (TOOLS[i].hash === "#" + hash) return TOOLS[i].key;
}
return "welcome";
}
function updateActiveNav(key) {
nav.querySelectorAll(".nav-item").forEach(function (item) {
item.classList.toggle("active", item.dataset.tool === key);
});
}
function openTool(key, options) {
options = options || {};
if (!TOOL_MAP[key]) key = "welcome";
if (key === activeKey && rendered) return;
var tool = TOOL_MAP[key];
activeKey = key;
rendered = true;
updateActiveNav(key);
document.title =
key === "welcome" ? "功能工具箱" : tool.name + " · 功能工具箱";
crumbTitle.textContent =
key === "welcome" ? "全部工具" : tool.name;
openExternal.classList.toggle("hidden", !tool.url);
if (key === "welcome") {
content.classList.remove("is-frame");
content.innerHTML = buildHome();
bindHome();
} else {
content.classList.add("is-frame");
content.innerHTML =
'<iframe src="' +
tool.url +
'" title="' +
tool.name +
'"></iframe>';
content.scrollTop = 0;
}
if (options.push) {
var target =
window.location.pathname +
window.location.search +
(tool.hash || "");
history.pushState({ tool: key }, document.title, target);
}
}
function navigateTo(key) {
if (!TOOL_MAP[key]) return;
openTool(key, { push: true });
}
window.addEventListener("popstate", function () {
openTool(toolFromLocation());
});
window.addEventListener("hashchange", function () {
openTool(toolFromLocation());
});
/* ================= 搜索 ================= */
function applyFilter(value) {
query = String(value || "").trim().toLowerCase();
if (sideSearch.value !== value) sideSearch.value = value || "";
if (homeSearch && homeSearch.value !== value) {
homeSearch.value = value || "";
}
nav.querySelectorAll(".nav-item").forEach(function (item) {
if (item.id === "themeToggle") return;
var text = item.textContent.toLowerCase();
item.classList.toggle("hidden", !!query && text.indexOf(query) < 0);
});
var cards = content.querySelectorAll("#toolsGrid .tool-card");
var visible = 0;
cards.forEach(function (card) {
var match =
!query || (card.dataset.search || "").indexOf(query) >= 0;
card.classList.toggle("hidden", !match);
if (match) visible += 1;
});
var noResults = document.getElementById("noResults");
if (noResults) noResults.classList.toggle("hidden", visible > 0);
var count = document.getElementById("toolCount");
if (count) {
count.textContent = query
? "匹配 " + visible + " 个工具"
: TOOLS.length - 1 + " 个工具";
}
}
sideSearch.addEventListener("input", function () {
applyFilter(sideSearch.value);
});
sideSearch.addEventListener("keydown", function (event) {
if (event.key === "Enter") {
var first = nav.querySelector(".nav-item:not(.hidden)");
if (first) {
navigateTo(first.dataset.tool);
closeMobileSidebar();
}
}
});
function focusSearch() {
if (window.innerWidth <= 900) {
document.body.classList.add("sidebar-open");
}
setTimeout(function () {
sideSearch.focus();
sideSearch.select();
}, 40);
}
/* ================= 侧边栏 ================= */
var collapseBtn = document.getElementById("collapseBtn");
function setCollapsed(collapsed) {
document.body.classList.toggle("sidebar-collapsed", collapsed);
collapseBtn.title = collapsed ? "展开侧边栏" : "收起侧边栏";
collapseBtn.setAttribute(
"aria-label",
collapsed ? "展开侧边栏" : "收起侧边栏",
);
try {
localStorage.setItem(SIDEBAR_KEY, collapsed ? "1" : "0");
} catch (error) {
/* 忽略 */
}
}
collapseBtn.addEventListener("click", function () {
setCollapsed(
!document.body.classList.contains("sidebar-collapsed"),
);
});
try {
if (localStorage.getItem(SIDEBAR_KEY) === "1") {
document.body.classList.add("sidebar-collapsed");
collapseBtn.title = "展开侧边栏";
collapseBtn.setAttribute("aria-label", "展开侧边栏");
}
} catch (error) {
/* 忽略 */
}
var menuBtn = document.getElementById("menuBtn");
menuBtn.addEventListener("click", function () {
document.body.classList.add("sidebar-open");
});
document
.getElementById("closeSidebarBtn")
.addEventListener("click", closeMobileSidebar);
backdrop.addEventListener("click", closeMobileSidebar);
document
.querySelector(".brand-mark")
.addEventListener("click", function () {
navigateTo("welcome");
closeMobileSidebar();
});
function closeMobileSidebar() {
document.body.classList.remove("sidebar-open");
}
/* ================= 主题 ================= */
function refreshThemeUI(theme) {
themeLabel.textContent = theme === "dark" ? "浅色模式" : "深色模式";
document
.getElementById("themeToggle")
.setAttribute(
"title",
theme === "dark" ? "切换到浅色模式" : "切换到深色模式",
);
}
Toolbox.onThemeChange(refreshThemeUI);
refreshThemeUI(Toolbox.theme());
/* ================= 在新标签打开 ================= */
openExternal.addEventListener("click", function () {
var tool = TOOL_MAP[activeKey];
if (tool && tool.url) {
window.open(tool.url, "_blank", "noopener");
}
});
/* ================= 快捷键 ================= */
document.addEventListener("keydown", function (event) {
var target = event.target;
var typing =
target &&
(target.tagName === "INPUT" ||
target.tagName === "TEXTAREA" ||
target.tagName === "SELECT" ||
target.isContentEditable);
if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === "k") {
event.preventDefault();
focusSearch();
return;
}
if (!typing && event.key === "/") {
event.preventDefault();
focusSearch();
return;
}
if (event.key === "Escape") {
closeMobileSidebar();
if (typing && target === sideSearch) {
sideSearch.value = "";
applyFilter("");
sideSearch.blur();
}
return;
}
if (
(event.metaKey || event.ctrlKey) &&
!event.shiftKey &&
/^[1-8]$/.test(event.key)
) {
var shortcuts = TOOLS.filter(function (tool) {
return tool.key !== "welcome";
});
var tool = shortcuts[Number(event.key) - 1];
if (tool) {
event.preventDefault();
navigateTo(tool.key);
closeMobileSidebar();
}
}
});
/* ================= 初始化 ================= */
buildNav();
openTool(toolFromLocation());
})();
</script>
</body>
</html>