This commit is contained in:
gogongxt committed 2026-11-02 16:01:16 +08:00
1 parent 2ce1c9056a
commit 9a726dbd9f
13 files changed
+8337 -5625

No files matched your search

+74 -66
View File
@@ -4,93 +4,101 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
## Project Overview
This is a Chinese-language web-based utility toolbox (功能工具箱) that provides multiple practical tools through a single interface. It's a pure frontend application built with vanilla HTML, CSS, and JavaScript that requires no backend server or external dependencies.
Chinese-language browser toolbox (功能工具箱) offering multiple practical utilities through one interface. Pure frontend: vanilla HTML, CSS, and JavaScript with no build step and no backend. All processing happens in the browser.
## Architecture
### Core Structure
- **Single-page application (SPA)** with modular tool architecture
- **Main entry point**: `index.html` - Central hub with collapsible sidebar navigation
- **Individual tools**: Separate HTML files loaded via iframe when selected
- **Pure client-side**: All processing happens in the browser, ensuring data privacy
- **Single-page shell** (`index.html`): collapsible sidebar, top bar, searchable tool cards, hash-based routing.
- **Tool pages**: standalone HTML files loaded in an iframe when selected, so each tool also works when opened directly.
- **Shared design system**: `assets/styles.css` (tokens + components) and `assets/common.js` (theme, toast, clipboard, helpers) are used by every page.
- **No dependencies** except jsPDF, loaded from CDN by `image_to_pdf.html`.
### Tool Modules
### Tools
- **Electricity Calculator** (`electricity_calculator.html`): Calculate appliance electricity costs
- **Programmer Calculator** (`number.html`): Base conversion utility (binary, octal, decimal, hex)
- **Color Picker** (`color_pick.html`): Professional color selection and format conversion
- **Other Functions** (`other_function.html`): Placeholder for future tools (under construction)
| File | Tool |
| --- | --- |
| `electricity_calculator.html` | 电费计算器 (single + peak/valley pricing) |
| `number.html` | 程序员计算器 (binary/octal/decimal/hex, arbitrary precision) |
| `color_pick.html` | 颜色选择器 (SV/H hue picker, HSV/RGB/HEX/HSL) |
| `json_formatter.html` | JSON 格式化 (pretty, minify, sort keys, highlight) |
| `url_encoder.html` | URL 编解码 (URI component/full/form/Base64) |
| `image_to_pdf.html` | 图片转 PDF (ordering, preview, page settings) |
| `image_compressor.html` | 图片压缩 (quality, format, resize, batch download) |
| `other_function.html` | 其他功能 (roadmap) |
### Shared assets
- `assets/styles.css`: design tokens for light/dark themes, resets, and reusable components (`.card`, `.btn`, `.field`, `.segmented`, `.editor-app`, `.image-grid`, `.dropzone`, `.toast`, etc.). Tool pages should reuse these instead of adding ad-hoc styles.
- `assets/common.js`: exposes `window.Toolbox` with `theme()`, `setTheme()`, `toggleTheme()`, `onThemeChange()`, `toast()`, `copy()`, `copyWithToast()`, `formatBytes()`, `escapeHtml()`, `debounce()`. It also wires `[data-theme-toggle]` buttons and declarative copy buttons (`data-copy-text` / `data-copy-target`).
### Theme
- Theme is stored in `localStorage` under `toolbox-theme`; without a stored value the system preference is used.
- `common.js` applies the theme before paint and listens to `storage` events, which keeps the parent page and iframe in sync live.
- Theme toggles use `<svg class="icon-moon">` + `<svg class="icon-sun">` inside a `[data-theme-toggle]` element.
### Routing
- Hashes map to tools: `#calculator`, `#number`, `#color`, `#json`, `#url`, `#image2pdf`, `#image-compressor`, `#other`.
- `index.html` uses `history.pushState` plus `popstate` / `hashchange` listeners.
- Keyboard shortcuts: `Ctrl/Cmd + K` focuses search, `Ctrl/Cmd + 1…8` opens tools, `Esc` closes mobile sidebar.
## Development
### No Build Process
### No build process
- **Static files**: Direct HTML/CSS/JS - no compilation needed
- **No dependencies**: Pure frontend with no npm packages or build tools
- **Simple deployment**: Can be served by any web server or opened directly in browser
Open `index.html` directly or serve the folder:
### Testing
```bash
python3 -m http.server 8000
```
- Open `index.html` directly in browser to test
- Test individual tools by opening their respective HTML files
- Check responsive design at different viewport sizes
- Verify keyboard shortcuts (Ctrl/Cmd + 1-5 for tool navigation)
### Testing checklist
### Adding New Tools
- Open `index.html`; verify sidebar collapse, mobile drawer, search, theme toggle, hash links.
- Open each tool directly; verify it works standalone and inside the iframe.
- Test light and dark themes; check contrast and iframe theme sync.
- Test mobile widths (≈375px) and desktop (≈1440px).
- Verify localStorage persists theme, sidebar state, and color history.
- Image tools: add multiple files, reorder/delete, change options, generate/compress, download.
1. Create new HTML file in root directory (following naming convention: `tool_name.html`)
2. Update `index.html` sidebar navigation to include new tool
3. Ensure new tool follows existing design patterns and styling
4. Test iframe loading and responsive behavior
### Adding a tool
### Code Style
1. Create `tool_name.html` using the shared assets:
```html
<link rel="stylesheet" href="assets/styles.css" />
<script src="assets/common.js"></script>
```
2. Use the `.tool-page` / `.tool-header` / `.card` layout and existing components; add a theme toggle in `.header-actions`.
3. Add the tool to the `TOOLS` array in `index.html` (name, description, URL, hash, icon, tint). The sidebar and home cards are generated from that array.
4. Add an icon `<symbol>` to the sprite at the top of `index.html` if needed; use `viewBox="0 0 24 24"` and stroke-style paths.
5. Test inside the iframe and standalone, in both themes and on mobile.
- **HTML5**: Semantic markup with Chinese UI text
- **CSS3**: Modern features (Flexbox, Grid, animations, gradients)
- **Vanilla JavaScript**: No external libraries, cross-browser compatible
- **Responsive design**: Mobile-first approach with media queries
- **Consistent styling**: Shared CSS patterns across all tools
### Code style
### Key Features to Maintain
- **Privacy-focused**: All processing happens locally, no external data transmission
- **User experience**: Smooth animations, collapsible sidebar, tooltips
- **Accessibility**: Semantic HTML and keyboard navigation support
- **Professional UI**: Gradient backgrounds, modern styling, clean layouts
- Semantic HTML5, Chinese UI text, accessible labels (`aria-label`, `role`, visible focus).
- Vanilla ES5+/ES2020 browser JavaScript; no frameworks.
- Prefer shared CSS variables and components over inline styling.
- Keep all processing local; do not add backend calls or telemetry.
## File Structure
```
/
├── index.html # Main application hub with navigation
├── electricity_calculator.html # Electricity cost calculator
├── number.html # Programmer calculator (base conversion)
├── color_pick.html # Color picker and format converter
├── other_function.html # Future tools placeholder
└── CLAUDE.md # This file
├── index.html # App shell, sidebar, routing, tool registry
├── electricity_calculator.html
├── number.html
├── color_pick.html
├── json_formatter.html
├── url_encoder.html
├── image_to_pdf.html
├── image_compressor.html
├── other_function.html
├── assets/
│ ├── styles.css # Shared design tokens and components
│ ├── common.js # Theme, toast, clipboard, helpers
│ └── favicon.svg # App icon
└── CLAUDE.md
```
## Common Tasks
### Running the Application
```bash
# Serve with any web server (optional)
python3 -m http.server 8000
# or open directly in browser
open index.html
```
### Adding New Tools
- Follow existing HTML structure and CSS patterns
- Include Chinese interface text consistent with current tools
- Ensure responsive design for mobile devices
- Test iframe integration with main navigation
### Modifying Styles
- Main styles are embedded in individual HTML files
- Consistent color scheme and design patterns across tools
- Use CSS variables for easy theme maintenance if needed
+265
View File
@@ -0,0 +1,265 @@
/* ============================================================
功能工具箱 · 共享脚本
主题同步 / Toast / 剪贴板 / 格式化工具
============================================================ */
(function () {
"use strict";
var THEME_KEY = "toolbox-theme";
var root = document.documentElement;
function readStoredTheme() {
try {
var value = localStorage.getItem(THEME_KEY);
return value === "light" || value === "dark" ? value : null;
} catch (error) {
return null;
}
}
function systemTheme() {
return window.matchMedia &&
window.matchMedia("(prefers-color-scheme: dark)").matches
? "dark"
: "light";
}
function applyTheme(theme, persist) {
if (theme !== "light" && theme !== "dark") return;
root.dataset.theme = theme;
root.style.colorScheme = theme;
if (persist) {
try {
localStorage.setItem(THEME_KEY, theme);
} catch (error) {
/* 忽略隐私模式下的写入失败 */
}
}
window.dispatchEvent(
new CustomEvent("toolbox:themechange", { detail: { theme: theme } }),
);
}
function currentTheme() {
return root.dataset.theme === "dark" ? "dark" : "light";
}
function toggleTheme() {
var next = currentTheme() === "dark" ? "light" : "dark";
applyTheme(next, true);
return next;
}
// 首次渲染前应用主题,避免闪烁
applyTheme(readStoredTheme() || systemTheme(), false);
// 跟随系统主题(用户未手动选择时)
if (window.matchMedia) {
var media = window.matchMedia("(prefers-color-scheme: dark)");
var onSystemChange = function (event) {
if (!readStoredTheme()) {
applyTheme(event.matches ? "dark" : "light", false);
}
};
if (media.addEventListener) {
media.addEventListener("change", onSystemChange);
} else if (media.addListener) {
media.addListener(onSystemChange);
}
}
// 同一个页面内(父页面 / iframe)的主题同步
window.addEventListener("storage", function (event) {
if (event.key === THEME_KEY && event.newValue) {
applyTheme(event.newValue, false);
}
});
/* ---------- Toast ---------- */
function toastContainer() {
var el = document.querySelector(".toast-wrap");
if (!el) {
el = document.createElement("div");
el.className = "toast-wrap";
document.body.appendChild(el);
}
return el;
}
function toast(message, type) {
if (!document.body) return;
type = type || "info";
var el = document.createElement("div");
el.className = "toast toast--" + type;
el.setAttribute("role", "status");
el.setAttribute("aria-live", "polite");
var icon = document.createElement("span");
icon.className = "toast-icon";
icon.textContent = type === "success" ? "✓" : type === "error" ? "!" : "i";
var text = document.createElement("span");
text.textContent = message;
el.appendChild(icon);
el.appendChild(text);
toastContainer().appendChild(el);
requestAnimationFrame(function () {
el.classList.add("show");
});
setTimeout(function () {
el.classList.remove("show");
setTimeout(function () {
el.remove();
}, 220);
}, 2400);
}
/* ---------- 剪贴板 ---------- */
function legacyCopy(text) {
return new Promise(function (resolve, reject) {
try {
var area = document.createElement("textarea");
area.value = text;
area.style.position = "fixed";
area.style.top = "-9999px";
area.style.opacity = "0";
document.body.appendChild(area);
area.focus();
area.select();
var ok = document.execCommand("copy");
document.body.removeChild(area);
ok ? resolve() : reject(new Error("copy failed"));
} catch (error) {
reject(error);
}
});
}
function copyText(text) {
text = String(text == null ? "" : text);
if (navigator.clipboard && window.isSecureContext) {
return navigator.clipboard.writeText(text).catch(function () {
// iframe 或权限受限时回退到 execCommand
return legacyCopy(text);
});
}
return legacyCopy(text);
}
function copyWithToast(text, message) {
return copyText(text)
.then(function () {
toast(message || "已复制到剪贴板", "success");
return true;
})
.catch(function () {
toast("复制失败,请手动选择复制", "error");
return false;
});
}
/* ---------- 格式化工具 ---------- */
function formatBytes(bytes, decimals) {
bytes = Number(bytes) || 0;
if (bytes <= 0) return "0 B";
var k = 1024;
var sizes = ["B", "KB", "MB", "GB", "TB"];
var i = Math.min(
Math.floor(Math.log(bytes) / Math.log(k)),
sizes.length - 1,
);
var value = bytes / Math.pow(k, i);
return (
parseFloat(value.toFixed(decimals == null ? 1 : decimals)) +
" " +
sizes[i]
);
}
function escapeHtml(value) {
return String(value).replace(/[&<>"']/g, function (char) {
return {
"&": "&amp;",
"<": "&lt;",
">": "&gt;",
'"': "&quot;",
"'": "&#39;",
}[char];
});
}
function debounce(fn, wait) {
var timer = null;
return function () {
var args = arguments;
var context = this;
clearTimeout(timer);
timer = setTimeout(function () {
fn.apply(context, args);
}, wait);
};
}
/* ---------- 初始化 ---------- */
function initThemeButtons() {
var buttons = document.querySelectorAll("[data-theme-toggle]");
Array.prototype.forEach.call(buttons, function (button) {
if (button.dataset.themeBound === "1") return;
button.dataset.themeBound = "1";
button.addEventListener("click", function () {
toggleTheme();
});
});
}
// 声明式复制按钮:
// data-copy-text="要复制的文本"
// data-copy-target="#elementId" (复制该元素 textContent)
function initCopyButtons() {
if (document.body.dataset.copyBound === "1") return;
document.body.dataset.copyBound = "1";
document.addEventListener("click", function (event) {
var button = event.target.closest("[data-copy-text],[data-copy-target]");
if (!button) return;
var text = button.dataset.copyText;
if (text == null && button.dataset.copyTarget) {
var target = document.querySelector(button.dataset.copyTarget);
text = target ? target.textContent : "";
}
if (!text) return;
event.preventDefault();
copyWithToast(text, button.dataset.copyMessage);
});
}
document.addEventListener("DOMContentLoaded", function () {
initThemeButtons();
initCopyButtons();
});
window.Toolbox = {
theme: currentTheme,
setTheme: function (theme) {
applyTheme(theme, true);
},
toggleTheme: toggleTheme,
onThemeChange: function (callback) {
window.addEventListener("toolbox:themechange", function (event) {
callback(event.detail.theme);
});
},
toast: toast,
copy: copyText,
copyWithToast: copyWithToast,
formatBytes: formatBytes,
escapeHtml: escapeHtml,
debounce: debounce,
};
})();
+13
View File
@@ -0,0 +1,13 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<defs>
<linearGradient id="g" x1="0" y1="0" x2="1" y2="1">
<stop offset="0" stop-color="#6366f1" />
<stop offset="1" stop-color="#a855f7" />
</linearGradient>
</defs>
<rect width="24" height="24" rx="6" fill="url(#g)" />
<path
d="M12 4.5 14 10l5.5 2L14 14l-2 5.5L10 14l-5.5-2L10 10Z"
fill="#ffffff"
/>
</svg>

After

Width:  |  Height:  |  Size: 408 B

+1945
View File
File diff suppressed because it is too large. Load diff
+706 -742
View File
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+1107 -1035
View File
File diff suppressed because it is too large. Load diff
+676 -1131
View File
File diff suppressed because it is too large. Load diff
+1548 -638
View File
File diff suppressed because it is too large. Load diff
+393 -550
View File
File diff suppressed because it is too large. Load diff
+403 -172
View File
@@ -3,231 +3,462 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>程序员进制计算器</title>
<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>
body {
font-family: sans-serif;
margin: 20px;
}
.container {
max-width: 600px;
margin: 0 auto;
padding: 20px;
}
.input-section {
margin-bottom: 20px;
.input-toolbar {
display: flex;
align-items: flex-end;
gap: 10px;
}
.input-toolbar .field {
flex: 1;
}
.input-toolbar input {
height: 44px;
font-family: var(--font-mono);
font-size: 1rem;
letter-spacing: 0.02em;
}
.input-toolbar .btn {
height: 44px;
padding-inline: 20px;
}
.base-row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 10px;
margin-bottom: 16px;
}
input[type="text"] {
width: 100%;
padding: 8px;
margin-bottom: 10px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box; /* 确保 padding 不会增加元素宽度 */
}
.radio-group {
display: flex;
gap: 10px;
margin-top: 10px;
margin-bottom: 20px;
}
.radio-group label {
display: block;
margin-bottom: 5px;
}
button {
background-color: #4caf50;
color: white;
padding: 10px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background-color: #3e8e41;
}
#results {
margin-top: 20px;
border-top: 1px solid #ccc;
padding-top: 10px;
.base-row .field-label {
font-size: 0.8rem;
font-weight: 600;
color: var(--text-secondary);
}
.history-list {
list-style-type: none;
padding: 0;
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.history-list li {
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
margin-bottom: 5px;
.history-chip {
display: inline-flex;
align-items: center;
gap: 8px;
max-width: 100%;
padding: 6px 11px;
border: 1px solid var(--border);
border-radius: 999px;
background: var(--surface-2);
color: var(--text-secondary);
font-size: 0.76rem;
cursor: pointer;
font-size: 14px;
transition: all var(--rate) ease;
}
.history-section h2 {
font-size: 18px;
color: #333;
margin-bottom: 15px;
.history-chip:hover {
border-color: var(--accent);
color: var(--accent);
background: var(--accent-soft);
}
.history-list li:hover {
background-color: #f0f0f0;
.history-chip .chip-base {
font-size: 0.62rem;
font-weight: 700;
letter-spacing: 0.06em;
color: var(--text-muted);
}
.history-chip code {
font-family: var(--font-mono);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.result-row code {
font-size: 0.92rem;
letter-spacing: 0.02em;
}
.result-row .row-label {
width: 42px;
}
@media (max-width: 560px) {
.input-toolbar {
flex-direction: column;
align-items: stretch;
}
.input-toolbar .btn {
width: 100%;
}
}
</style>
</head>
<body>
<div class="container">
<h1>程序员进制计算器</h1>
<label for="number-input">请输入数字:</label>
<input type="text" id="number-input" placeholder="例如: 100" required />
<button onclick="convertNumber()">转换</button>
<div class="radio-group">
<label
><input type="radio" name="base" value="10" checked /> 十进制</label
<div class="tool-page tool-page--narrow">
<header class="tool-header">
<div class="tool-icon">
<svg viewBox="0 0 24 24" aria-hidden="true">
<path d="M4 9h16M4 15h16M10 3 8 21M16 3l-2 18" />
</svg>
</div>
<div>
<h1>程序员计算器</h1>
<p>二进制、八进制、十进制、十六进制即时互转,支持任意精度整数。</p>
</div>
<div class="header-actions">
<button
class="btn btn--icon btn--ghost"
data-theme-toggle
title="切换主题"
aria-label="切换主题"
>
<label><input type="radio" name="base" value="2" /> 二进制</label>
<label><input type="radio" name="base" value="8" /> 八进制</label>
<label><input type="radio" name="base" value="16" /> 十六进制</label>
<svg class="icon-moon" viewBox="0 0 24 24" aria-hidden="true">
<path d="M21 12.8A8.5 8.5 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8Z" />
</svg>
<svg class="icon-sun" viewBox="0 0 24 24" aria-hidden="true">
<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"
/>
</svg>
</button>
</div>
<div id="results">
</header>
<section class="card">
<div class="base-row">
<span class="field-label">输入进制</span>
<div class="segmented" role="radiogroup" aria-label="输入进制">
<label class="seg">
<input type="radio" name="base" value="10" checked />
<span>十进制</span>
</label>
<label class="seg">
<input type="radio" name="base" value="2" />
<span>二进制</span>
</label>
<label class="seg">
<input type="radio" name="base" value="8" />
<span>八进制</span>
</label>
<label class="seg">
<input type="radio" name="base" value="16" />
<span>十六进制</span>
</label>
</div>
</div>
<div class="input-toolbar">
<div class="field">
<label for="numberInput">输入数字</label>
<input
type="text"
id="numberInput"
value="100"
placeholder="例如:100,或 0x1f"
autocomplete="off"
spellcheck="false"
/>
</div>
<button class="btn btn--primary" id="convertBtn">转换</button>
</div>
<div class="alert alert--error hidden" id="errorBox" style="margin-top: 12px">
<svg viewBox="0 0 24 24" aria-hidden="true">
<circle cx="12" cy="12" r="9" />
<path d="M12 8v5M12 16.5v.01" />
</svg>
<span id="errorText"></span>
</div>
</section>
<section class="card" aria-live="polite">
<div class="card-head">
<h2>转换结果</h2>
<div id="result-section">
<!-- 计算结果将显示在这里 -->
<span class="spacer"></span>
<span class="badge badge--accent">任意精度</span>
</div>
<div class="result-list">
<div class="result-row">
<span class="row-label">DEC</span>
<code id="resultDecimal">100</code>
<button
class="copy-btn"
data-copy-target="#resultDecimal"
data-copy-message="十进制已复制"
aria-label="复制十进制"
>
复制
</button>
</div>
<div class="result-row">
<span class="row-label">BIN</span>
<code id="resultBinary">0110 0100</code>
<button
class="copy-btn"
data-copy-target="#resultBinary"
data-copy-message="二进制已复制"
aria-label="复制二进制"
>
复制
</button>
</div>
<div class="result-row">
<span class="row-label">OCT</span>
<code id="resultOctal">144</code>
<button
class="copy-btn"
data-copy-target="#resultOctal"
data-copy-message="八进制已复制"
aria-label="复制八进制"
>
复制
</button>
</div>
<div class="result-row">
<span class="row-label">HEX</span>
<code id="resultHex">64</code>
<button
class="copy-btn"
data-copy-target="#resultHex"
data-copy-message="十六进制已复制"
aria-label="复制十六进制"
>
复制
</button>
</div>
</div>
<div class="history-section">
<p class="hint" style="margin-top: 12px">
二进制结果每 4 位以空格分组,方便阅读;点击“复制”即可粘贴到代码中。
</p>
</section>
<section class="card">
<div class="card-head">
<h2>历史记录</h2>
<ul class="history-list" id="history-list">
<!-- 历史记录将显示在这里 -->
</ul>
<span class="spacer"></span>
<button class="btn btn--ghost btn--sm" id="clearHistoryBtn">清空</button>
</div>
<div class="history-list" id="historyList"></div>
<div class="empty-state" id="historyEmpty" style="padding: 18px 10px">
<span>按 Enter 或点击“转换”后会记录到这里</span>
</div>
</section>
</div>
<script>
const historyList = [];
(function () {
"use strict";
function convertNumber() {
const numberInput = document.getElementById("number-input").value;
const base = document.querySelector(
'input[name="base"]:checked',
).value;
var BASE_NAMES = { 2: "BIN", 8: "OCT", 10: "DEC", 16: "HEX" };
var history = [];
var MAX_HISTORY = 20;
let decimal;
if (base === "10") {
decimal = parseInt(numberInput, 10);
} else if (base === "2") {
decimal = parseInt(numberInput, 2);
} else if (base === "8") {
decimal = parseInt(numberInput, 8);
} else if (base === "16") {
decimal = parseInt(numberInput, 16);
var input = document.getElementById("numberInput");
var errorBox = document.getElementById("errorBox");
var errorText = document.getElementById("errorText");
var historyList = document.getElementById("historyList");
var historyEmpty = document.getElementById("historyEmpty");
function currentBase() {
return parseInt(
document.querySelector('input[name="base"]:checked').value,
10,
);
}
if (isNaN(decimal)) {
alert("请输入有效的数字!");
return;
function cleanInput(raw, base) {
var value = String(raw).trim().replace(/[\s_]/g, "");
if (base === 16) value = value.replace(/^0x/i, "");
if (base === 2) value = value.replace(/^0b/i, "");
if (base === 8) value = value.replace(/^0o/i, "");
return value;
}
const binary = formatBinary(decimal.toString(2)); // 格式化二进制
const hexadecimal = decimal.toString(16).toUpperCase();
const octal = decimal.toString(8);
function validPattern(base) {
return {
2: /^-?[01]+$/,
8: /^-?[0-7]+$/,
10: /^-?[0-9]+$/,
16: /^-?[0-9a-f]+$/i,
}[base];
}
const resultSection = document.getElementById("result-section");
function parseValue(raw, base) {
var text = cleanInput(raw, base);
if (!text || !validPattern(base).test(text)) {
return null;
}
resultSection.innerHTML = `
<p>十进制: <span id="decimal"></span></p>
<p>二进制: <span id="binary"></span></p>
<p>十六进制: <span id="hexadecimal"></span></p>
<p>八进制: <span id="octal"></span></p>
`;
var negative = text.charAt(0) === "-";
var digits = negative ? text.slice(1) : text;
var bigBase = BigInt(base);
var value = 0n;
document.getElementById("decimal").textContent = decimal;
document.getElementById("binary").textContent = binary;
document.getElementById("hexadecimal").textContent = hexadecimal;
document.getElementById("octal").textContent = octal;
for (var i = 0; i < digits.length; i += 1) {
var digit = parseInt(digits.charAt(i), base);
if (isNaN(digit)) return null;
value = value * bigBase + BigInt(digit);
}
const historyItem = {
input: numberInput,
return negative ? -value : value;
}
function groupBinary(binary) {
var negative = binary.charAt(0) === "-";
var digits = negative ? binary.slice(1) : binary;
var grouped = digits.replace(/\B(?=(.{4})+$)/g, " ");
return (negative ? "-" : "") + grouped;
}
function setError(message) {
errorText.textContent = message;
errorBox.classList.remove("hidden");
}
function clearError() {
errorBox.classList.add("hidden");
}
function setResults(values) {
document.getElementById("resultDecimal").textContent =
values ? values.decimal : "—";
document.getElementById("resultBinary").textContent =
values ? values.binary : "—";
document.getElementById("resultOctal").textContent =
values ? values.octal : "—";
document.getElementById("resultHex").textContent =
values ? values.hex : "—";
}
// 返回解析结果,失败时返回 null
function convert() {
var base = currentBase();
var raw = input.value;
var value = parseValue(raw, base);
if (value === null) {
setError(
"请输入有效的" +
({ 2: "二进制", 8: "八进制", 10: "十进制", 16: "十六进制" }[
base
] || "") +
"数字。",
);
setResults(null);
return null;
}
clearError();
var result = {
input: cleanInput(raw, base),
base: base,
decimal: decimal,
binary: binary,
hexadecimal: hexadecimal,
octal: octal,
decimal: value.toString(10),
binary: groupBinary(value.toString(2)),
octal: value.toString(8),
hex: value.toString(16).toUpperCase(),
};
historyList.unshift(historyItem); // 将最新记录添加到最前面
updateHistoryList();
setResults(result);
return result;
}
function formatBinary(binary) {
// 从右往左每隔4位加一个空格
return binary
.split("") // 将字符串转为数组
.reverse() // 反转数组,从右往左处理
function renderHistory() {
historyList.innerHTML = "";
historyEmpty.style.display = history.length ? "none" : "block";
.join("") // 重新拼接为字符串
.replace(/(\d{4})/g, "\$1 ") // 每隔4位加一个空格
.split("") // 再次转为数组
.reverse() // 反转回原始顺序
history.forEach(function (item) {
var chip = document.createElement("button");
chip.className = "history-chip";
chip.type = "button";
chip.title = "点击重新转换";
chip.innerHTML =
'<span class="chip-base">' +
BASE_NAMES[item.base] +
"</span><code></code>";
.join("") // 重新拼接为字符串
.trim(); // 去除首尾多余的空格
}
chip.querySelector("code").textContent = item.input;
function updateHistoryList() {
const historyListElement = document.getElementById("history-list");
historyListElement.innerHTML = "";
chip.addEventListener("click", function () {
input.value = item.input;
document.querySelector(
'input[name="base"][value="' + item.base + '"]',
).checked = true;
convert();
input.focus();
});
historyList.forEach((item, index) => {
const listItem = document.createElement("li");
let displayText = "";
if (item.base === "10") {
displayText = `十进制: ${item.input}`;
} else if (item.base === "2") {
displayText = `二进制: ${item.input}`;
} else if (item.base === "8") {
displayText = `八进制: ${item.input}`;
} else if (item.base === "16") {
displayText = `十六进制: ${item.input}`;
}
listItem.textContent = displayText;
listItem.addEventListener("click", () => showHistoryResult(index));
historyListElement.appendChild(listItem);
historyList.appendChild(chip);
});
}
function showHistoryResult(index) {
const item = historyList[index];
const resultSection = document.getElementById("result-section");
resultSection.innerHTML = `
<p>十进制: <span id="decimal"></span></p>
<p>二进制: <span id="binary"></span></p>
<p>十六进制: <span id="hexadecimal"></span></p>
<p>八进制: <span id="octal"></span></p>
`;
function commit() {
var result = convert();
if (!result) return;
document.getElementById("decimal").textContent = item.decimal;
document.getElementById("binary").textContent = item.binary;
document.getElementById("hexadecimal").textContent = item.hexadecimal;
document.getElementById("octal").textContent = item.octal;
// 相同记录不重复
var duplicate = history.some(function (item) {
return (
item.input === result.input && item.base === result.base
);
});
if (!duplicate) {
history.unshift(result);
history = history.slice(0, MAX_HISTORY);
renderHistory();
}
}
var liveConvert = Toolbox.debounce(convert, 160);
input.addEventListener("input", function () {
liveConvert();
});
input.addEventListener("keydown", function (event) {
if (event.key === "Enter") {
event.preventDefault();
commit();
}
});
document
.querySelectorAll('input[name="base"]')
.forEach(function (radio) {
radio.addEventListener("change", convert);
});
document.getElementById("convertBtn").addEventListener("click", commit);
document
.getElementById("clearHistoryBtn")
.addEventListener("click", function () {
if (!history.length) return;
history = [];
renderHistory();
Toolbox.toast("历史记录已清空", "success");
});
// 初始化
convert();
renderHistory();
})();
</script>
</div>
</body>
</html>
+312 -302
View File
@@ -3,356 +3,366 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>其他功能 - 功能工具箱</title>
<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>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family:
-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
"Helvetica Neue", Arial, sans-serif;
background: radial-gradient(
circle at center,
#ff9a9e 0%,
#fad0c4 25%,
#fad0c4 50%,
#ff9a9e 75%,
#fad0c4 100%
);
background-size: 400% 400%;
animation: pinkGlow 10s ease-in-out infinite;
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
padding: 20px;
}
@keyframes pinkGlow {
0%,
100% {
background-position: 0% 50%;
}
50% {
background-position: 100% 50%;
}
}
.container {
background: white;
border-radius: 20px;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
padding: 60px 40px;
text-align: center;
max-width: 600px;
width: 100%;
.hero-card {
position: relative;
overflow: hidden;
padding: clamp(26px, 4vw, 44px);
border: 1px solid var(--border);
border-radius: var(--radius-lg);
background:
radial-gradient(
560px 260px at 0% 0%,
rgba(99, 102, 241, 0.15),
transparent 65%
),
radial-gradient(
480px 240px at 100% 100%,
rgba(168, 85, 247, 0.12),
transparent 65%
),
var(--surface);
box-shadow: var(--shadow-sm);
}
.container::before {
content: "";
position: absolute;
top: -50%;
left: -50%;
width: 200%;
height: 200%;
background: linear-gradient(45deg, #ff9a9e, #fad0c4, #fecfef, #fecfef);
opacity: 0.15;
animation: rotate 10s linear infinite;
border-radius: 50%;
}
@keyframes rotate {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
.construction-icon {
font-size: 80px;
margin-bottom: 30px;
animation: bounce 2s infinite;
}
@keyframes bounce {
0%,
20%,
50%,
80%,
100% {
transform: translateY(0);
}
40% {
transform: translateY(-30px);
}
60% {
transform: translateY(-15px);
}
}
h1 {
color: #2c3e50;
font-size: 32px;
margin-bottom: 20px;
.hero-card .hero-badge {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 4px 10px;
border-radius: 999px;
background: var(--warning-soft);
color: var(--warning);
font-size: 0.72rem;
font-weight: 700;
position: relative;
z-index: 1;
}
.status-badge {
display: inline-block;
background: linear-gradient(135deg, #ff6b6b 0%, #ee5a24 100%);
color: white;
padding: 8px 20px;
border-radius: 25px;
font-size: 14px;
font-weight: 600;
margin-bottom: 25px;
animation: pulse 2s infinite;
.hero-card h2 {
margin: 14px 0 8px;
font-size: clamp(1.4rem, 3vw, 1.9rem);
letter-spacing: -0.03em;
}
@keyframes pulse {
0% {
box-shadow: 0 0 0 0 rgba(238, 90, 36, 0.7);
}
70% {
box-shadow: 0 0 0 15px rgba(238, 90, 36, 0);
}
100% {
box-shadow: 0 0 0 0 rgba(238, 90, 36, 0);
}
.hero-card p {
max-width: 40em;
color: var(--text-secondary);
font-size: 0.92rem;
}
.description {
color: #5a6c7d;
font-size: 18px;
line-height: 1.6;
margin-bottom: 30px;
position: relative;
z-index: 1;
.progress-inline {
max-width: 420px;
margin-top: 22px;
}
.features-coming {
background: #f8f9fa;
border-radius: 15px;
padding: 30px;
margin: 30px 0;
border-left: 5px solid #3498db;
position: relative;
z-index: 1;
}
.features-coming h3 {
color: #2c3e50;
font-size: 20px;
margin-bottom: 20px;
text-align: left;
}
.feature-list {
list-style: none;
text-align: left;
}
.feature-list li {
padding: 10px 0;
color: #5a6c7d;
font-size: 16px;
.progress-inline .progress-head {
display: flex;
align-items: center;
justify-content: space-between;
font-size: 0.76rem;
color: var(--text-muted);
margin-bottom: 6px;
}
.feature-list li::before {
content: "🚧";
margin-right: 10px;
font-size: 18px;
.roadmap-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
gap: 12px;
}
.progress-bar {
width: 100%;
height: 8px;
background: #ecf0f1;
border-radius: 4px;
overflow: hidden;
margin: 20px 0;
position: relative;
z-index: 1;
.roadmap-card {
display: flex;
gap: 12px;
align-items: flex-start;
padding: 16px;
border: 1px solid var(--border);
border-radius: 14px;
background: var(--surface);
transition:
border-color var(--rate) ease,
transform var(--rate) ease;
}
.progress-fill {
height: 100%;
background: linear-gradient(90deg, #3498db, #2ecc71);
border-radius: 4px;
width: 30%;
animation: progressAnimation 3s ease-in-out infinite alternate;
.roadmap-card:hover {
border-color: var(--border-strong);
transform: translateY(-1px);
}
@keyframes progressAnimation {
from {
width: 30%;
}
to {
width: 65%;
}
.roadmap-card .rm-icon {
width: 36px;
height: 36px;
flex: none;
display: grid;
place-items: center;
border-radius: 10px;
background: var(--accent-soft);
color: var(--accent);
}
.progress-text {
color: #7f8c8d;
font-size: 14px;
margin-top: 10px;
position: relative;
z-index: 1;
}
.particles {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none;
z-index: 0;
}
.particle {
position: absolute;
background: #ff9a9e;
border-radius: 50%;
opacity: 0.15;
animation: float 6s infinite ease-in-out;
}
.particle:nth-child(1) {
width: 20px;
height: 20px;
left: 10%;
animation-delay: 0s;
}
.particle:nth-child(2) {
width: 15px;
height: 15px;
left: 30%;
animation-delay: 1s;
}
.particle:nth-child(3) {
width: 25px;
height: 25px;
left: 60%;
animation-delay: 2s;
}
.particle:nth-child(4) {
.roadmap-card .rm-icon svg {
width: 18px;
height: 18px;
left: 80%;
animation-delay: 3s;
}
@keyframes float {
0%,
100% {
transform: translateY(0) rotate(0deg);
.roadmap-card h3 {
font-size: 0.86rem;
font-weight: 650;
margin-bottom: 2px;
}
50% {
transform: translateY(-20px) rotate(180deg);
.roadmap-card p {
font-size: 0.75rem;
line-height: 1.5;
color: var(--text-secondary);
margin-bottom: 6px;
}
.roadmap-card .badge {
font-size: 0.64rem;
padding: 1px 7px;
}
.contact-card {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 14px;
margin-top: 16px;
padding: 18px 20px;
border: 1px solid var(--border);
border-radius: 14px;
background: var(--surface);
}
.contact-card .contact-body {
flex: 1;
min-width: 200px;
}
.contact-card h3 {
font-size: 0.88rem;
margin-bottom: 2px;
}
.contact-card p {
font-size: 0.78rem;
color: var(--text-secondary);
}
.section-head {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 10px;
margin: 26px 2px 12px;
}
.section-head h2 {
font-size: 1.02rem;
}
.section-head span {
font-size: 0.76rem;
color: var(--text-muted);
}
</style>
</head>
<body>
<div class="container">
<div class="particles">
<div class="particle"></div>
<div class="particle"></div>
<div class="particle"></div>
<div class="particle"></div>
<div class="tool-page">
<header class="tool-header">
<div class="tool-icon">
<svg viewBox="0 0 24 24" aria-hidden="true">
<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" />
</svg>
</div>
<div class="construction-icon">🚧</div>
<div>
<h1>其他功能</h1>
<div class="status-badge">正在开发中</div>
<p>更多实用工具正在规划与开发中,欢迎告诉我们你最想要什么。</p>
</div>
<div class="header-actions">
<button
class="btn btn--icon btn--ghost"
data-theme-toggle
title="切换主题"
aria-label="切换主题"
>
<svg class="icon-moon" viewBox="0 0 24 24" aria-hidden="true">
<path d="M21 12.8A8.5 8.5 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8Z" />
</svg>
<svg class="icon-sun" viewBox="0 0 24 24" aria-hidden="true">
<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"
/>
</svg>
</button>
</div>
</header>
<p class="description">
更多实用功能正在紧张开发中,敬请期待!我们正在为您打造更加完善的工具集合。
<section class="hero-card">
<span class="hero-badge">● 持续更新中</span>
<h2>工具箱还在长大</h2>
<p>
现有工具已经覆盖日常计算、编码、图片处理等场景。接下来会继续补充轻量、实用、完全本地运行的
小工具,让这个页面成为你收藏夹里真正用得上的那一页。
</p>
<div class="progress-inline">
<div class="progress-head">
<span>本期规划进度</span>
<span>55%</span>
</div>
<div class="progress-track">
<div class="progress-bar" style="width: 55%"></div>
</div>
</div>
</section>
<div class="features-coming">
<h3>🔮 即将推出的功能</h3>
<ul class="feature-list">
<li>文本处理工具</li>
<li>图片压缩工具</li>
<li>二维码生成器</li>
<li>密码生成器</li>
<li>单位转换工具</li>
<li>时间戳转换器</li>
<li>JSON格式化工具</li>
<li>Base64编码工具</li>
</ul>
<div class="section-head">
<h2>候选功能</h2>
<span>按优先级陆续上线</span>
</div>
<div class="progress-bar">
<div class="progress-fill"></div>
<div class="roadmap-grid">
<div class="roadmap-card">
<span class="rm-icon">
<svg viewBox="0 0 24 24" aria-hidden="true">
<rect x="3" y="3" width="7" height="7" rx="1" />
<rect x="14" y="3" width="7" height="7" rx="1" />
<rect x="3" y="14" width="7" height="7" rx="1" />
<path d="M14 14h3v3h-3zM20 14h1M14 20h1M17 20h4v1" />
</svg>
</span>
<div>
<h3>二维码生成器</h3>
<p>把文本、链接或 Wi-Fi 信息生成可下载的二维码。</p>
<span class="badge">计划中</span>
</div>
<div class="progress-text">开发进度:约 40% 完成</div>
</div>
<script>
// 添加一些动态交互效果
document.addEventListener("DOMContentLoaded", function () {
// 随机改变粒子的动画时间
const particles = document.querySelectorAll(".particle");
particles.forEach((particle, index) => {
const randomDelay = Math.random() * 3;
const randomDuration = 4 + Math.random() * 4;
particle.style.animationDelay = `${randomDelay}s`;
particle.style.animationDuration = `${randomDuration}s`;
});
<div class="roadmap-card">
<span class="rm-icon">
<svg viewBox="0 0 24 24" aria-hidden="true">
<rect x="5" y="10" width="14" height="10" rx="2" />
<path d="M8 10V7a4 4 0 0 1 8 0v3M12 14v2" />
</svg>
</span>
<div>
<h3>密码生成器</h3>
<p>按长度与字符规则生成高强度随机密码。</p>
<span class="badge">计划中</span>
</div>
</div>
// 添加点击效果
const container = document.querySelector(".container");
container.addEventListener("click", function (e) {
const ripple = document.createElement("div");
ripple.style.position = "absolute";
ripple.style.width = "20px";
ripple.style.height = "20px";
ripple.style.background = "rgba(255, 154, 158, 0.5)";
ripple.style.borderRadius = "50%";
ripple.style.transform = "translate(-50%, -50%)";
ripple.style.pointerEvents = "none";
ripple.style.left = e.clientX - container.offsetLeft + "px";
ripple.style.top = e.clientY - container.offsetTop + "px";
ripple.style.animation = "rippleEffect 0.6s ease-out";
<div class="roadmap-card">
<span class="rm-icon">
<svg viewBox="0 0 24 24" aria-hidden="true">
<path d="M4 7h6M7 4v6M14 17h6M17 14v6" />
<path d="m13 5 6 6M5 13l6 6" />
</svg>
</span>
<div>
<h3>单位换算</h3>
<p>长度、重量、温度、面积等常用单位快速换算。</p>
<span class="badge">计划中</span>
</div>
</div>
container.appendChild(ripple);
<div class="roadmap-card">
<span class="rm-icon">
<svg viewBox="0 0 24 24" aria-hidden="true">
<circle cx="12" cy="12" r="9" />
<path d="M12 7v5l3 2" />
</svg>
</span>
<div>
<h3>时间戳转换</h3>
<p>Unix 时间戳与本地日期时间双向转换。</p>
<span class="badge">计划中</span>
</div>
</div>
setTimeout(() => {
ripple.remove();
}, 600);
});
});
<div class="roadmap-card">
<span class="rm-icon">
<svg viewBox="0 0 24 24" aria-hidden="true">
<path d="M8 3H5a2 2 0 0 0-2 2v4a2 2 0 0 0 2 2h3a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2Z" />
<path d="M19 13h-3a2 2 0 0 0-2 2v4a2 2 0 0 0 2 2h3a2 2 0 0 0 2-2v-4a2 2 0 0 0-2-2Z" />
<path d="M8 13H5a2 2 0 0 0-2 2v4a2 2 0 0 0 2 2h3a2 2 0 0 0 2-2v-4a2 2 0 0 0-2-2Z" />
</svg>
</span>
<div>
<h3>文本对比</h3>
<p>逐行比较两段文本,高亮新增与删除内容。</p>
<span class="badge">计划中</span>
</div>
</div>
// 添加涟漪动画
const style = document.createElement("style");
style.textContent = `
@keyframes rippleEffect {
to {
width: 200px;
height: 200px;
opacity: 0;
}
}
`;
document.head.appendChild(style);
</script>
<div class="roadmap-card">
<span class="rm-icon">
<svg viewBox="0 0 24 24" aria-hidden="true">
<path d="M4 5a2 2 0 0 1 2-2h8l6 6v10a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V5Z" />
<path d="M14 3v6h6M8 14h8M8 17h5" />
</svg>
</span>
<div>
<h3>Markdown 预览</h3>
<p>边写边渲染 Markdown,适合整理笔记与文档。</p>
<span class="badge">计划中</span>
</div>
</div>
<div class="roadmap-card">
<span class="rm-icon">
<svg viewBox="0 0 24 24" aria-hidden="true">
<rect x="3" y="5" width="18" height="14" rx="2" />
<circle cx="9" cy="11" r="2" />
<path d="m5 17 4-4 3 3 2-2 5 5" />
</svg>
</span>
<div>
<h3>图片加水印</h3>
<p>为图片批量添加文字或图片水印,本地完成。</p>
<span class="badge">计划中</span>
</div>
</div>
<div class="roadmap-card">
<span class="rm-icon">
<svg viewBox="0 0 24 24" aria-hidden="true">
<circle cx="12" cy="12" r="9" />
<path d="M12 3a9 9 0 0 1 0 18 9 9 0 0 1 0-18ZM3 12h18" />
</svg>
</span>
<div>
<h3>颜色渐变生成</h3>
<p>生成和谐的 CSS 渐变并复制代码。</p>
<span class="badge">计划中</span>
</div>
</div>
</div>
<div class="contact-card">
<span class="rm-icon" style="
width: 42px; height: 42px; display: grid; place-items: center;
border-radius: 12px; background: var(--accent-soft); color: var(--accent);
">
<svg viewBox="0 0 24 24" aria-hidden="true" style="width: 20px; height: 20px">
<rect x="3" y="5" width="18" height="14" rx="2" />
<path d="m3 7 9 6 9-6" />
</svg>
</span>
<div class="contact-body">
<h3>想要某个工具?</h3>
<p>告诉我们你的使用场景,我们会优先安排实现。</p>
</div>
<a class="btn btn--soft" href="mailto:gogongxt@163.com">
联系 gogongxt@163.com
</a>
</div>
</div>
</body>
</html>
+333 -611
View File
File diff suppressed because it is too large. Load diff