You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

223 lines
6.0 KiB

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JSON 格式化工具</title>
<style>
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
margin: 0;
padding: 36px 24px;
background: radial-gradient(circle at top, #111827, #0b0f14);
color: #e5e7eb;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial;
min-height: 100vh;
}
.box {
max-width: 960px;
margin: auto;
}
.page-title {
font-size: 22px;
font-weight: 600;
color: #f3f4f6;
margin-bottom: 20px;
display: flex;
align-items: center;
gap: 10px;
}
.card {
background: rgba(255,255,255,0.03);
border: 1px solid rgba(255,255,255,0.08);
border-radius: 16px;
padding: 24px;
margin-bottom: 16px;
}
.section-label {
font-size: 12px;
color: #6b7280;
text-transform: uppercase;
letter-spacing: 1px;
margin-bottom: 10px;
}
textarea {
width: 100%;
background: #0d1117;
border: 1px solid rgba(255,255,255,0.1);
border-radius: 12px;
color: #e6edf3;
font-family: "SF Mono", "Fira Code", Consolas, monospace;
font-size: 13.5px;
line-height: 1.7;
padding: 16px;
outline: none;
transition: border-color 0.2s;
}
textarea:focus { border-color: rgba(59,130,246,0.5); }
textarea::placeholder { color: #484f58; }
textarea.input-area {
border-color: rgba(59,130,246,0.2);
min-height: 280px;
}
textarea.result-area {
border-color: rgba(34,197,94,0.25);
color: #7ee787;
min-height: 260px;
}
.btn-row {
display: flex;
gap: 10px;
margin-top: 14px;
}
.btn {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 10px 20px;
font-size: 13px;
border-radius: 10px;
border: none;
cursor: pointer;
font-weight: 500;
transition: all 0.2s;
}
.btn-primary { background: #2563eb; color: white; }
.btn-primary:hover { background: #1d4ed8; transform: translateY(-1px); }
.btn-secondary { background: rgba(255,255,255,0.06); color: #9ca3af; border: 1px solid rgba(255,255,255,0.1); }
.btn-secondary:hover { background: rgba(255,255,255,0.1); }
.btn-green { background: rgba(34,197,94,0.12); color: #4ade80; border: 1px solid rgba(34,197,94,0.25); }
.btn-green:hover { background: rgba(34,197,94,0.2); }
.result-bar {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 10px;
}
.result-title {
font-size: 12px;
color: #6b7280;
text-transform: uppercase;
letter-spacing: 1px;
}
.copy-btn {
display: inline-flex;
align-items: center;
gap: 5px;
padding: 5px 12px;
font-size: 12px;
border-radius: 8px;
background: rgba(34,197,94,0.12);
color: #4ade80;
border: 1px solid rgba(34,197,94,0.25);
cursor: pointer;
transition: all 0.2s;
}
.copy-btn:hover { background: rgba(34,197,94,0.22); }
.copy-btn.copied { background: rgba(34,197,94,0.35); }
.toast {
position: fixed;
right: 24px;
bottom: 24px;
background: rgba(17,24,39,0.96);
color: #e5e7eb;
padding: 10px 16px;
border-radius: 10px;
border: 1px solid rgba(34,197,94,0.3);
font-size: 13px;
opacity: 0;
transform: translateY(8px);
transition: all 0.25s ease;
z-index: 9999;
pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }
@media (max-width: 768px) {
body { padding: 24px 16px; }
.card { padding: 18px 16px; }
textarea.input-area, textarea.result-area { min-height: 200px; }
.btn-row { flex-wrap: wrap; }
.btn { flex: 1; justify-content: center; }
}
</style>
</head>
<body>
<div class="box">
<div class="page-title">📋 JSON 格式化工具</div>
<div class="card">
<div class="section-label">输入</div>
<textarea class="input-area" id="jsonInput" placeholder="粘贴 JSON 内容至此处...">{{ text or '' }}</textarea>
<div class="btn-row">
<button class="btn btn-primary" onclick="doAction('format')">✨ 格式化</button>
<button class="btn btn-secondary" onclick="doAction('minify')">⏱ 压缩</button>
<button class="btn btn-green" onclick="doAction('validate')">✅ 校验</button>
</div>
</div>
{% if result %}
<div class="card">
<div class="result-bar">
<span class="result-title">输出</span>
<button class="copy-btn" id="copyBtn" onclick="copyResult()">
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<rect x="9" y="9" width="13" height="13" rx="2"></rect>
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path>
</svg>
<span id="copyText">复制</span>
</button>
</div>
<textarea class="result-area" id="resultText" readonly>{{ result }}</textarea>
</div>
{% endif %}
</div>
<div class="toast" id="toast"></div>
<script>
function doAction(action) {
const text = document.getElementById('jsonInput').value;
if (!text.trim()) { showToast('请输入 JSON'); return; }
window.location.href = '/tool/json?action=' + action + '&text=' + encodeURIComponent(text);
}
function copyResult() {
const result = document.getElementById('resultText').value;
if (!result) return;
navigator.clipboard.writeText(result).then(() => {
const btn = document.getElementById('copyBtn');
document.getElementById('copyText').textContent = '已复制!';
btn.classList.add('copied');
showToast('已复制到剪贴板');
setTimeout(() => { btn.classList.remove('copied'); document.getElementById('copyText').textContent = '复制'; }, 2000);
}).catch(() => showToast('复制失败'));
}
function showToast(msg) {
const t = document.getElementById('toast');
t.innerText = msg;
t.classList.add('show');
setTimeout(() => t.classList.remove('show'), 2000);
}
</script>
</body>
</html>