初始化仓库,创建项目
This commit is contained in:
commit
90bd40ffde
33 files changed
+5356
No files matched your search
@@ -0,0 +1,501 @@
|
||||
/* common.css —— 全站统一样式与组件(含昼/夜主题、响应式) */
|
||||
/* ============ 主题变量 ============ */
|
||||
:root, [data-theme="light"] {
|
||||
--bg: #f2f5fa;
|
||||
--bg-2: #e8edf5;
|
||||
--card: #ffffff;
|
||||
--line: #dde3ec;
|
||||
--line-2: #c9d2e0;
|
||||
--text: #1f2d3d;
|
||||
--text-2: #3c4b61;
|
||||
--text-3: #71809a;
|
||||
--brand: #2563eb;
|
||||
--brand-2: #1f3a5f;
|
||||
--brand-ink: #ffffff;
|
||||
--accent-soft: rgba(37, 99, 235, 0.10);
|
||||
--hover-bg: rgba(37, 99, 235, 0.08);
|
||||
--danger: #dc2626;
|
||||
--ok: #16a34a;
|
||||
--warn: #d97706;
|
||||
--shadow: 0 4px 16px rgba(15, 30, 55, 0.08);
|
||||
--shadow-sm: 0 1px 4px rgba(15, 30, 55, 0.06);
|
||||
--code-bg: #f4f6fa;
|
||||
--code-text: #1f2d3d;
|
||||
--tooltip-bg: #1f2d3d;
|
||||
--tooltip-text: #f2f5fa;
|
||||
--input-bg: #ffffff;
|
||||
--brand-grad: linear-gradient(135deg, #1f3a5f 0%, #2563eb 100%);
|
||||
--board-tint: linear-gradient(160deg, rgba(37, 99, 235, 0.10), rgba(31, 58, 95, 0.04));
|
||||
color-scheme: light;
|
||||
}
|
||||
[data-theme="dark"] {
|
||||
--bg: #0f1520;
|
||||
--bg-2: #161e2c;
|
||||
--card: #1a2332;
|
||||
--line: #2a3648;
|
||||
--line-2: #3a4a60;
|
||||
--text: #e7edf5;
|
||||
--text-2: #c2ccda;
|
||||
--text-3: #8fa0b6;
|
||||
--brand: #60a5fa;
|
||||
--brand-2: #93c5fd;
|
||||
--brand-ink: #0b1220;
|
||||
--accent-soft: rgba(96, 165, 250, 0.14);
|
||||
--hover-bg: rgba(96, 165, 250, 0.12);
|
||||
--danger: #f87171;
|
||||
--ok: #4ade80;
|
||||
--warn: #fbbf24;
|
||||
--shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
|
||||
--shadow-sm: 0 1px 4px rgba(0, 0, 0, 0.3);
|
||||
--code-bg: #111927;
|
||||
--code-text: #dbe4f0;
|
||||
--tooltip-bg: #e7edf5;
|
||||
--tooltip-text: #1a2332;
|
||||
--input-bg: #131c2a;
|
||||
--brand-grad: linear-gradient(135deg, #12233d 0%, #1d4ed8 100%);
|
||||
--board-tint: linear-gradient(160deg, rgba(96, 165, 250, 0.13), rgba(18, 35, 61, 0.10));
|
||||
color-scheme: dark;
|
||||
}
|
||||
|
||||
/* ============ 基础 ============ */
|
||||
* { box-sizing: border-box; }
|
||||
html, body { margin: 0; padding: 0; }
|
||||
body {
|
||||
font-family: -apple-system, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
font-size: 15px;
|
||||
line-height: 1.6;
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
transition: background .25s ease, color .25s ease;
|
||||
}
|
||||
a { color: var(--brand); text-decoration: none; }
|
||||
a:hover { text-decoration: none; }
|
||||
img { max-width: 100%; }
|
||||
.wrap { width: 100%; max-width: 1200px; margin: 0 auto; padding: 0 20px; }
|
||||
main.page-main { flex: 1 0 auto; padding-bottom: 24px; }
|
||||
|
||||
h1, h2, h3, h4 { line-height: 1.3; margin: 0 0 .5em; }
|
||||
button { font-family: inherit; }
|
||||
|
||||
/* 提示小字 */
|
||||
.tip { font-size: 13px; color: var(--text-3); }
|
||||
.tip code { background: var(--code-bg); color: var(--code-text); border-radius: 4px; padding: 1px 6px; }
|
||||
.err-msg, .ok-msg { border-radius: 8px; padding: 10px 14px; font-size: 14px; margin: 12px 0; }
|
||||
.err-msg { background: rgba(220, 38, 38, .10); color: var(--danger); }
|
||||
.ok-msg { background: rgba(22, 163, 74, .12); color: var(--ok); }
|
||||
.seg-check { display: inline-flex; align-items: center; gap: 5px; font-size: 14px; color: var(--text-2); padding: 6px 10px; border: 1px solid var(--line-2); border-radius: 8px; background: var(--card); cursor: pointer; user-select: none; }
|
||||
.seg-check:hover { border-color: var(--brand); }
|
||||
.seg-check input { margin: 0; }
|
||||
|
||||
/* ============ 按钮 ============ */
|
||||
.btn {
|
||||
display: inline-flex; align-items: center; justify-content: center; gap: 6px;
|
||||
border: 1px solid var(--line-2); background: var(--card); color: var(--text);
|
||||
padding: 8px 16px; border-radius: 8px; font-size: 14px; cursor: pointer;
|
||||
transition: all .15s ease; line-height: 1.4; vertical-align: middle;
|
||||
}
|
||||
.btn:hover { border-color: var(--brand); color: var(--brand); }
|
||||
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
|
||||
.btn-primary:hover { filter: brightness(1.08); color: var(--brand-ink); }
|
||||
.btn-ghost { background: transparent; }
|
||||
.btn-danger { color: var(--danger); border-color: rgba(220, 38, 38, .4); }
|
||||
.btn-danger:hover { background: rgba(220, 38, 38, .1); border-color: var(--danger); color: var(--danger); }
|
||||
.btn-sm { padding: 4px 10px; font-size: 13px; border-radius: 6px; }
|
||||
.btn[disabled] { opacity: .5; cursor: not-allowed; }
|
||||
|
||||
/* ============ 表单 ============ */
|
||||
label.fl { display: block; font-size: 13px; color: var(--text-3); margin: 10px 0 4px; }
|
||||
input[type=text], input[type=password], input[type=number], input[type=url], input[type=file],
|
||||
select, textarea {
|
||||
width: 100%; padding: 8px 12px; border: 1px solid var(--line-2); border-radius: 8px;
|
||||
background: var(--input-bg); color: var(--text); font-size: 14px; font-family: inherit;
|
||||
transition: border .15s ease, box-shadow .15s ease;
|
||||
}
|
||||
input:focus, select:focus, textarea:focus {
|
||||
outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--accent-soft);
|
||||
}
|
||||
textarea { resize: vertical; min-height: 90px; line-height: 1.6; }
|
||||
input[type=checkbox] { accent-color: var(--brand); }
|
||||
select { width: auto; min-width: 150px; }
|
||||
.field-row { display: flex; gap: 10px; align-items: flex-start; flex-wrap: wrap; }
|
||||
|
||||
/* ============ 主题浮动按钮 ============ */
|
||||
.theme-fab {
|
||||
position: fixed; right: 18px; bottom: 22px; width: 46px; height: 46px; z-index: 1000;
|
||||
border-radius: 50%; border: 1px solid var(--line-2); background: var(--card);
|
||||
color: var(--text); font-size: 20px; cursor: pointer;
|
||||
box-shadow: var(--shadow); display: flex; align-items: center; justify-content: center;
|
||||
transition: transform .2s ease, background .2s ease;
|
||||
}
|
||||
.theme-fab:hover { transform: scale(1.08); }
|
||||
|
||||
/* ============ 通用头部(品牌条 / 顶部条) ============ */
|
||||
.brand { display: inline-flex; align-items: center; gap: 12px; }
|
||||
.brand .logo {
|
||||
width: 52px; height: 52px; border-radius: 12px; object-fit: contain;
|
||||
background: var(--card); padding: 4px; box-shadow: var(--shadow-sm);
|
||||
}
|
||||
.brand .site-name { font-size: 21px; font-weight: 700; }
|
||||
.brand .site-slogan { font-size: 13px; color: var(--text-3); }
|
||||
.brand-sm .logo { width: 38px; height: 38px; border-radius: 9px; }
|
||||
.brand-sm .site-name { font-size: 17px; }
|
||||
|
||||
/* ---------- 首页 Hero 展示栏 ---------- */
|
||||
.hero {
|
||||
background: var(--brand-grad); color: #fff;
|
||||
padding: 26px 0 18px; min-height: 20vh; box-shadow: var(--shadow);
|
||||
}
|
||||
.hero .brand .site-name, .hero .brand .site-slogan { color: #fff; }
|
||||
.hero .brand .logo { background: rgba(255, 255, 255, .95); }
|
||||
.hero-inner { display: flex; flex-direction: column; gap: 14px; }
|
||||
.hero-top { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
|
||||
.hero-meta { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: rgba(255, 255, 255, .9); text-align: right; }
|
||||
.hero-meta .val { font-variant-numeric: tabular-nums; font-weight: 600; color: #fff; }
|
||||
.weather-box { display: flex; justify-content: center; }
|
||||
.weather-box iframe { display: block; border-radius: 8px; background: transparent; max-width: 100%; }
|
||||
/* 第三方天气 iframe 内容为白底,无法跨域改色:深色主题下用反色滤镜融入当前背景 */
|
||||
[data-theme="dark"] .weather-box iframe { filter: invert(0.9) hue-rotate(180deg) contrast(0.92) saturate(0.9); }
|
||||
|
||||
/* ---------- 名言条 ---------- */
|
||||
.quote-bar { background: var(--card); border-bottom: 1px solid var(--line); }
|
||||
.quote-inner { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 12px 16px; text-align: center; }
|
||||
.quote-mark { font-size: 22px; color: var(--brand); }
|
||||
.quote-text {
|
||||
font-size: 17px; color: var(--text-2); cursor: pointer; user-select: none;
|
||||
padding: 2px 8px; border-radius: 8px;
|
||||
transition: color .15s ease, background .15s ease;
|
||||
}
|
||||
.quote-text:hover { color: var(--brand); background: var(--hover-bg); }
|
||||
|
||||
/* ============ 首页四大板块 ============ */
|
||||
/* 首页板块区:内容放得下时填满视口剩余高度(不出现竖向滚动条),内容超高时自然滚动 */
|
||||
.board-section { flex: 1 0 auto; display: flex; flex-direction: column; padding: 26px 0 24px; }
|
||||
.board-section > .wrap { flex: 1; display: flex; flex-direction: column; justify-content: center; }
|
||||
/* 首页快捷站点条(后台“内容与顺序”配置,点击新标签页打开) */
|
||||
.quick-strip { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-bottom: 24px; }
|
||||
.quick-chip {
|
||||
position: relative; display: inline-flex; align-items: center; gap: 6px; padding: 8px 18px; border-radius: 999px;
|
||||
background: var(--card); border: 1px solid var(--line-2); color: var(--text-2); font-size: 14px;
|
||||
box-shadow: var(--shadow-sm); text-decoration: none;
|
||||
transition: border-color .15s ease, color .15s ease, transform .12s ease, box-shadow .15s ease;
|
||||
}
|
||||
.quick-chip:hover { border-color: var(--brand); color: var(--brand); transform: translateY(-1px); box-shadow: var(--shadow); }
|
||||
.quick-chip .q-icon { font-size: 15px; line-height: 1; display: inline-flex; align-items: center; }
|
||||
.quick-chip .icon-img { width: 16px; height: 16px; object-fit: contain; }
|
||||
/* 快捷站点按钮 hover 备注(data-note) */
|
||||
a.quick-chip[data-note]::after {
|
||||
content: attr(data-note); position: absolute; z-index: 60; bottom: calc(100% + 8px); left: 50%;
|
||||
transform: translateX(-50%) translateY(4px); width: max-content; max-width: 320px;
|
||||
background: var(--tooltip-bg); color: var(--tooltip-text); font-size: 12px; line-height: 1.5;
|
||||
padding: 6px 10px; border-radius: 7px; white-space: normal; word-break: break-word;
|
||||
text-align: center; opacity: 0; pointer-events: none; box-shadow: var(--shadow);
|
||||
transition: opacity .14s ease, transform .14s ease;
|
||||
}
|
||||
a.quick-chip[data-note]:hover::after { opacity: 1; transform: translateX(-50%) translateY(0); }
|
||||
/* 通用图标 <img>(site_icon 输出)在各容器中的尺寸 */
|
||||
.icon-img { object-fit: contain; vertical-align: middle; }
|
||||
.board-icon img.icon-img { width: 30px; height: 30px; }
|
||||
.board-section .section-title { text-align: center; font-size: 22px; margin-bottom: 6px; }
|
||||
.board-section .section-sub { text-align: center; color: var(--text-3); font-size: 14px; margin-bottom: 18px; }
|
||||
.boards { position: relative; display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; }
|
||||
.board-card {
|
||||
position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
|
||||
gap: 12px; background-color: var(--card); background-image: var(--board-tint);
|
||||
border: 1px solid var(--line); border-radius: 16px; padding: 26px 14px; text-align: center;
|
||||
box-shadow: var(--shadow-sm); color: var(--text);
|
||||
transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
|
||||
min-height: 230px;
|
||||
}
|
||||
.board-card:hover { transform: translateY(-4px); box-shadow: var(--shadow); border-color: var(--brand); }
|
||||
.board-icon {
|
||||
width: 64px; height: 64px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
|
||||
font-size: 30px; color: #fff; background: var(--brand-grad); box-shadow: var(--shadow);
|
||||
}
|
||||
.board-name { font-size: 19px; font-weight: 700; }
|
||||
.board-hint { font-size: 13px; color: var(--text-3); }
|
||||
.func-card .fc-icon img.icon-img { width: 24px; height: 24px; }
|
||||
|
||||
/* 板块展开说明浮层 */
|
||||
.board-panel {
|
||||
position: absolute; top: 6px; bottom: 6px; width: 52%; z-index: 5;
|
||||
background: var(--card); border: 1px solid var(--brand); border-radius: 16px;
|
||||
padding: 24px 26px; box-shadow: var(--shadow); pointer-events: none;
|
||||
opacity: 0; transform: translateY(8px) scale(.98); transition: opacity .18s ease, transform .18s ease;
|
||||
display: flex; flex-direction: column; justify-content: center;
|
||||
}
|
||||
.board-panel.visible { opacity: 1; transform: none; }
|
||||
.board-panel.panel-left { left: 0; }
|
||||
.board-panel.panel-right { right: 0; }
|
||||
.board-panel-title { font-size: 20px; font-weight: 700; color: var(--brand); margin-bottom: 10px; }
|
||||
.board-panel-desc { font-size: 15px; color: var(--text-2); }
|
||||
|
||||
/* 名言隐藏池 */
|
||||
.quote-pool { display: none; }
|
||||
|
||||
/* ============ 页脚 ============ */
|
||||
.footer { background: var(--bg-2); border-top: 1px solid var(--line); color: var(--text-3); font-size: 13px; }
|
||||
.footer-inner { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 22px 16px; text-align: center; }
|
||||
.footer .admin-link { opacity: .65; }
|
||||
.footer .admin-link:hover { opacity: 1; }
|
||||
|
||||
/* ============ 顶部条(导航区/其他内页) ============ */
|
||||
.top-strip { background: var(--card); border-bottom: 1px solid var(--line); }
|
||||
.strip-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 20px; }
|
||||
.nav-top { padding-top: 14px; }
|
||||
|
||||
/* ============ 搜索栏 ============ */
|
||||
.search-zone { padding: 10vh 0 0; }
|
||||
.search-zone .search-title { text-align: center; color: var(--text-3); font-size: 14px; margin: 8px 0 6px; }
|
||||
.search-box {
|
||||
max-width: 760px; margin: 0 auto; display: flex; align-items: center;
|
||||
border: 1px solid var(--line-2); border-radius: 26px; background: var(--card);
|
||||
box-shadow: var(--shadow-sm); overflow: visible; padding: 4px;
|
||||
transition: border-color .15s ease, box-shadow .15s ease;
|
||||
}
|
||||
.search-box:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px var(--accent-soft); }
|
||||
.engine-btn {
|
||||
position: relative; display: inline-flex; align-items: center; gap: 5px;
|
||||
border: none; background: transparent; color: var(--text-2); padding: 8px 14px 8px 16px;
|
||||
border-radius: 22px 0 0 22px; cursor: pointer; font-size: 14px; white-space: nowrap;
|
||||
}
|
||||
.engine-btn:hover { background: var(--hover-bg); }
|
||||
.engine-btn .arrow { font-size: 10px; opacity: .7; }
|
||||
.engine-menu {
|
||||
position: absolute; top: calc(100% + 6px); left: 0; margin: 0; padding: 6px; list-style: none;
|
||||
background: var(--card); border: 1px solid var(--line-2); border-radius: 10px; box-shadow: var(--shadow);
|
||||
min-width: 150px; display: none; z-index: 20;
|
||||
}
|
||||
.engine-menu.open { display: block; }
|
||||
.engine-menu li { padding: 7px 10px; border-radius: 6px; cursor: pointer; font-size: 14px; }
|
||||
.engine-menu li:hover { background: var(--hover-bg); }
|
||||
.engine-menu li.active { color: var(--brand); font-weight: 600; }
|
||||
.search-field { flex: 1; position: relative; display: flex; align-items: center; }
|
||||
.search-field input { border: none; box-shadow: none !important; background: transparent; width: 100%; padding: 9px 34px 9px 6px; font-size: 15px; }
|
||||
.search-field input:focus { border: none; }
|
||||
.search-clear {
|
||||
position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
|
||||
width: 20px; height: 20px; border-radius: 50%; border: none; background: var(--bg-2);
|
||||
color: var(--text-3); font-size: 12px; line-height: 1; cursor: pointer;
|
||||
display: flex; align-items: center; justify-content: center; visibility: hidden;
|
||||
}
|
||||
.search-clear:hover { background: var(--line-2); color: var(--text); }
|
||||
.search-go {
|
||||
border: none; background: var(--brand); color: var(--brand-ink); border-radius: 20px;
|
||||
padding: 9px 22px; font-size: 15px; cursor: pointer; font-weight: 600;
|
||||
}
|
||||
.search-go:hover { filter: brightness(1.08); }
|
||||
|
||||
/* ============ 导航区 ============ */
|
||||
.nav-area { margin: 26px 15% 40px; }
|
||||
.nav-area-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 16px; gap: 10px; flex-wrap: wrap; }
|
||||
.nav-area-title { font-size: 20px; font-weight: 700; }
|
||||
.nav-area-count { color: var(--text-3); font-size: 13px; }
|
||||
.nav-cols { display: grid; grid-template-columns: repeat(3, 1fr); gap: 22px; align-items: start; }
|
||||
.nav-col { display: flex; flex-direction: column; gap: 18px; }
|
||||
.nav-block {
|
||||
background: var(--card); border: 1px solid var(--line); border-radius: 14px;
|
||||
padding: 14px 14px 12px; box-shadow: var(--shadow-sm); break-inside: avoid;
|
||||
}
|
||||
.nav-block-title { font-weight: 700; font-size: 15px; margin: 0 0 10px; color: var(--brand-2); padding-left: 2px; }
|
||||
.nav-block-grid { display: grid; grid-template-columns: repeat(3, 1fr); grid-auto-rows: 36px; gap: 8px; }
|
||||
.nav-btn {
|
||||
position: relative; display: flex; align-items: center; justify-content: center; padding: 0 6px;
|
||||
border: 1px solid var(--line); border-radius: 8px; background: var(--bg);
|
||||
color: var(--text-2); font-size: 13px; text-align: center; overflow: visible;
|
||||
transition: background .15s ease, color .15s ease, border-color .15s ease, transform .12s ease;
|
||||
min-width: 0; white-space: nowrap;
|
||||
}
|
||||
a.nav-btn:hover { background: var(--brand); border-color: var(--brand); color: #fff; transform: translateY(-1px); }
|
||||
span.nav-btn.is-empty { visibility: hidden; }
|
||||
span.nav-btn.is-off { opacity: .45; cursor: not-allowed; }
|
||||
/* tooltip:有备注按钮 hover 浮出气泡 */
|
||||
a.nav-btn[data-note]::after {
|
||||
content: attr(data-note); position: absolute; z-index: 60; bottom: calc(100% + 7px); left: 50%;
|
||||
transform: translateX(-50%) translateY(4px); background: var(--tooltip-bg); color: var(--tooltip-text);
|
||||
font-size: 12px; line-height: 1.5; padding: 5px 10px; border-radius: 7px; white-space: nowrap;
|
||||
max-width: 280px; overflow: hidden; text-overflow: ellipsis;
|
||||
opacity: 0; pointer-events: none; transition: opacity .14s ease, transform .14s ease;
|
||||
box-shadow: var(--shadow);
|
||||
}
|
||||
a.nav-btn[data-note]:hover::after { opacity: 1; transform: translateX(-50%) translateY(0); }
|
||||
|
||||
/* ============ 功能区 ============ */
|
||||
.func-bar { background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 50; }
|
||||
.func-bar-inner { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; }
|
||||
.func-bar-title { font-size: 16px; font-weight: 700; text-align: center; flex: 0 1 auto; }
|
||||
.func-bar .spacer { width: 120px; }
|
||||
.sub-hero { position: relative; background: var(--brand-grad); color: #fff; text-align: center; padding: 46px 20px 40px; }
|
||||
.sub-hero h1 { font-size: 26px; margin: 0 0 8px; }
|
||||
.sub-hero p { color: rgba(255, 255, 255, .88); margin: 0; font-size: 14px; }
|
||||
.sub-hero .back-home { position: absolute; top: 14px; left: 18px; color: rgba(255, 255, 255, .92); font-size: 14px; }
|
||||
.sub-hero .back-home:hover { color: #fff; text-decoration: underline; }
|
||||
.page-body { padding: 26px 0 10px; }
|
||||
|
||||
/* 工具入口卡片 */
|
||||
.func-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 18px; margin: 6px 0 20px; }
|
||||
.func-card {
|
||||
display: flex; align-items: center; gap: 14px; background: var(--card); border: 1px solid var(--line);
|
||||
border-radius: 14px; padding: 18px; box-shadow: var(--shadow-sm); color: var(--text);
|
||||
transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease;
|
||||
}
|
||||
.func-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: var(--brand); }
|
||||
.func-card .fc-icon {
|
||||
width: 50px; height: 50px; flex: 0 0 50px; border-radius: 12px; display: flex; align-items: center; justify-content: center;
|
||||
font-size: 24px; color: var(--brand); background: var(--accent-soft);
|
||||
}
|
||||
.func-card .fc-name { font-weight: 700; font-size: 15px; }
|
||||
.func-card .fc-desc { font-size: 13px; color: var(--text-3); margin-top: 2px; }
|
||||
|
||||
/* 工具卡片容器 */
|
||||
.panel-card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 20px; margin-bottom: 20px; box-shadow: var(--shadow-sm); }
|
||||
.panel-card > h2 { font-size: 17px; margin-top: 0; }
|
||||
|
||||
/* IO 双文本区布局 */
|
||||
.io-area { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 14px; }
|
||||
.io-box { display: flex; flex-direction: column; }
|
||||
.io-box .io-label { font-size: 13px; color: var(--text-3); margin-bottom: 6px; display: flex; justify-content: space-between; align-items: center; }
|
||||
.io-box textarea { min-height: 230px; font-family: Consolas, Menlo, monospace; font-size: 13px; }
|
||||
.copy-btn .btn { display: inline-flex; }
|
||||
|
||||
/* 工具操作行 */
|
||||
.tool-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 10px 0; }
|
||||
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 8px; overflow: hidden; }
|
||||
.seg button { border: none; background: var(--card); color: var(--text-2); padding: 7px 16px; cursor: pointer; font-size: 14px; }
|
||||
.seg button.active { background: var(--brand); color: #fff; }
|
||||
|
||||
/* 密码结果 */
|
||||
.pwd-results { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
|
||||
.pwd-line { display: flex; align-items: center; gap: 10px; }
|
||||
.pwd-line code { flex: 1; background: var(--code-bg); color: var(--code-text); padding: 8px 12px; border-radius: 8px; font-size: 14px; overflow-x: auto; white-space: pre; word-break: break-all; }
|
||||
|
||||
/* 二维码 */
|
||||
.qr-stage { display: flex; flex-direction: column; align-items: center; gap: 14px; margin-top: 10px; }
|
||||
.qr-stage canvas, .qr-stage img { border-radius: 10px; background: #fff; padding: 8px; box-shadow: var(--shadow-sm); }
|
||||
|
||||
/* 数据表格 */
|
||||
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; margin: 10px 0; }
|
||||
.tbl th, .tbl td { border: 1px solid var(--line); padding: 8px 12px; text-align: left; }
|
||||
.tbl th { background: var(--bg-2); font-weight: 600; }
|
||||
.tbl tr:hover td { background: var(--hover-bg); }
|
||||
.badge { display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: 12px; }
|
||||
.badge-ok { background: rgba(22, 163, 74, .14); color: var(--ok); }
|
||||
.badge-no { background: rgba(148, 163, 184, .16); color: var(--text-3); }
|
||||
/* IP 地址处理:来源分类徽章 */
|
||||
.badge-cdn { background: rgba(37, 99, 235, .14); color: var(--brand); }
|
||||
.badge-priv { background: rgba(217, 119, 6, .15); color: var(--warn); }
|
||||
.badge-pub { background: rgba(148, 163, 184, .16); color: var(--text-3); }
|
||||
/* IP 处理结果预览(红色标记重点 IP) */
|
||||
.ip-pre {
|
||||
font-family: Consolas, Menlo, monospace; font-size: 13px; line-height: 1.8;
|
||||
background: var(--code-bg); color: var(--code-text);
|
||||
border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px;
|
||||
white-space: pre-wrap; word-break: break-all; overflow: auto; max-height: 440px;
|
||||
}
|
||||
.ip-pre .ip-hit, .ip-pre .ip-seg-hit { color: var(--danger); font-weight: 700; }
|
||||
.ip-pre .ip-seg-hit { background: rgba(220, 38, 38, .10); border-radius: 4px; }
|
||||
|
||||
/* ============ 后台管理 ============ */
|
||||
.admin-nav { background: var(--brand-2); color: #fff; }
|
||||
.admin-nav a { color: rgba(255, 255, 255, .9); }
|
||||
.admin-nav-inner { display: flex; align-items: center; gap: 18px; padding: 10px 20px; flex-wrap: wrap; }
|
||||
.admin-nav-inner .sp { margin-left: auto; display: flex; gap: 14px; align-items: center; }
|
||||
.admin-nav-inner .logo { height: 30px; width: 30px; border-radius: 7px; object-fit: contain; background: #fff; padding: 2px; }
|
||||
.admin-nav .brand .site-name { color: #fff; }
|
||||
.admin-nav a.active { text-decoration: underline; text-underline-offset: 4px; font-weight: 600; }
|
||||
|
||||
.fieldset-card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 18px; margin-bottom: 20px; box-shadow: var(--shadow-sm); }
|
||||
.fieldset-card > .fs-title { font-weight: 700; font-size: 16px; margin: 0 0 12px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
|
||||
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 18px; }
|
||||
|
||||
/* 后台导航内容管理 */
|
||||
.m-block { border: 1px solid var(--line); border-radius: 12px; margin-bottom: 16px; overflow: hidden; }
|
||||
.m-block-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--bg-2); flex-wrap: wrap; }
|
||||
.m-block-head input[type=text] { max-width: 320px; }
|
||||
.m-block-head input.b-title { flex: 1 1 240px; width: auto; max-width: 520px; }
|
||||
.m-block-head .ops { margin-left: auto; display: flex; gap: 6px; align-items: center; }
|
||||
.m-items { padding: 4px 12px 12px; }
|
||||
.m-item { display: grid; grid-template-columns: 1fr 1.4fr 1.2fr 36px; gap: 8px; align-items: center; margin-top: 8px; }
|
||||
.m-item .m-del { text-align: center; }
|
||||
/* 后台搜索引擎管理行 */
|
||||
.e-row { display: grid; grid-template-columns: 70px 1.1fr 1.8fr 40px; gap: 8px; align-items: center; margin-top: 8px; }
|
||||
/* 后台图标控件:预览框 + 文本输入 + 上传按钮 + 隐藏文件选择 */
|
||||
.icon-ctl { display: flex; align-items: center; gap: 6px; flex: 0 1 250px; min-width: 170px; }
|
||||
.icon-ctl .icon-preview {
|
||||
width: 30px; height: 30px; flex: 0 0 30px; border: 1px solid var(--line-2); border-radius: 8px;
|
||||
background: var(--bg); color: var(--text-2); overflow: hidden;
|
||||
display: flex; align-items: center; justify-content: center;
|
||||
font-size: 13px; line-height: 1; white-space: nowrap; text-overflow: ellipsis;
|
||||
}
|
||||
.icon-ctl .icon-preview img { width: 100%; height: 100%; object-fit: contain; }
|
||||
.icon-ctl .icon-input { flex: 1 1 90px; min-width: 70px; padding: 7px 9px; font-size: 13px; }
|
||||
.icon-ctl .icon-upload { flex: 0 0 auto; padding: 7px 12px; font-size: 13px; }
|
||||
/* 后台功能区工具管理行 / 首页快捷站点管理行:flex 自适应,窄屏自动换行,避免重叠 */
|
||||
.t-row, .l-row {
|
||||
display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
|
||||
padding: 12px 0; margin-top: 12px; border-top: 1px dashed var(--line);
|
||||
}
|
||||
.t-row:first-child, .l-row:first-child { margin-top: 0; padding-top: 0; border-top: none; }
|
||||
.t-row .icon-ctl, .l-row .icon-ctl { flex: 0 1 240px; }
|
||||
.t-row .t-name, .l-row .l-name { flex: 1 1 120px; min-width: 90px; }
|
||||
.t-row .t-desc { flex: 1 1 170px; min-width: 110px; }
|
||||
.t-row .t-url, .l-row .l-url { flex: 2 1 230px; min-width: 150px; }
|
||||
.t-row .t-ext { flex: 0 1 132px; min-width: 0; width: 100%; }
|
||||
.l-row .l-note { flex: 1 1 170px; min-width: 120px; }
|
||||
.t-row .ops, .l-row .ops { display: flex; gap: 6px; flex: 0 0 auto; margin-left: auto; }
|
||||
.t-on { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--text-2); white-space: nowrap; flex: 0 0 auto; }
|
||||
.add-btn { margin: 6px 0 18px; }
|
||||
|
||||
/* 登录页 */
|
||||
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg-2); padding: 20px; }
|
||||
.login-card { width: 100%; max-width: 380px; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 30px; box-shadow: var(--shadow); }
|
||||
.login-card h1 { text-align: center; font-size: 20px; margin-bottom: 4px; }
|
||||
.login-card .lc-sub { text-align: center; color: var(--text-3); font-size: 13px; margin-bottom: 16px; }
|
||||
.login-logo { text-align: center; margin-bottom: 10px; }
|
||||
.login-logo img { width: 64px; height: 64px; border-radius: 14px; }
|
||||
|
||||
/* 顶部 logo 占位展示 */
|
||||
.logo-preview { display: flex; align-items: center; gap: 14px; margin: 8px 0; }
|
||||
.logo-preview img { width: 64px; height: 64px; border-radius: 12px; border: 1px solid var(--line); object-fit: contain; background: #fff; }
|
||||
|
||||
/* ============ 响应式 ============ */
|
||||
@media (max-width: 1199px) {
|
||||
.nav-area { margin: 24px 5% 36px; }
|
||||
}
|
||||
@media (max-width: 991px) {
|
||||
.form-grid { grid-template-columns: 1fr; }
|
||||
}
|
||||
@media (max-width: 767px) {
|
||||
.hero { min-height: 0; }
|
||||
.hero-top { flex-direction: column; text-align: center; }
|
||||
.hero-meta { text-align: center; }
|
||||
.weather-box iframe { width: 100%; }
|
||||
.quote-inner { flex-wrap: wrap; }
|
||||
.boards { grid-template-columns: repeat(2, 1fr); gap: 12px; min-height: 0; }
|
||||
.board-panel { width: 100%; }
|
||||
.nav-cols { grid-template-columns: 1fr; gap: 14px; }
|
||||
.nav-area { margin: 18px 12px 30px; }
|
||||
.search-zone { padding-top: 6vh; }
|
||||
.search-box { flex-wrap: wrap; border-radius: 16px; padding: 6px; }
|
||||
.engine-btn { border-radius: 12px; }
|
||||
.search-go { border-radius: 12px; }
|
||||
.search-field { order: 3; flex-basis: 100%; }
|
||||
.io-area { grid-template-columns: 1fr; }
|
||||
.io-box textarea { min-height: 160px; }
|
||||
.m-item { grid-template-columns: 1fr; gap: 4px; }
|
||||
.e-row { grid-template-columns: 1fr; gap: 4px; }
|
||||
.t-row, .l-row { gap: 6px; padding: 10px 0; }
|
||||
.t-row > *, .l-row > * { flex: 1 1 100%; min-width: 0; }
|
||||
.icon-ctl { min-width: 0; }
|
||||
.t-row .t-on, .l-row .t-on { flex: 0 0 auto; }
|
||||
.t-row .ops, .l-row .ops { flex: 0 0 auto; margin-left: auto; justify-content: flex-end; }
|
||||
.m-block-head input[type=text] { max-width: 100%; }
|
||||
.func-bar-title { font-size: 14px; }
|
||||
.func-bar .spacer { width: 60px; }
|
||||
}
|
||||
@media (max-width: 600px) {
|
||||
.nav-block-grid { grid-template-columns: 1fr; grid-auto-rows: auto; }
|
||||
.nav-btn { justify-content: flex-start; padding: 8px 12px; }
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" width="64" height="64">
|
||||
<defs>
|
||||
<linearGradient id="g" x1="0" y1="0" x2="1" y2="1">
|
||||
<stop offset="0" stop-color="#2563eb"/>
|
||||
<stop offset="1" stop-color="#1f3a5f"/>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<rect x="2" y="2" width="60" height="60" rx="15" fill="url(#g)"/>
|
||||
<text x="32" y="42" font-family="Arial, 'Microsoft YaHei', sans-serif" font-size="30" font-weight="bold" text-anchor="middle" fill="#ffffff">知</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 502 B |
@@ -0,0 +1,240 @@
|
||||
/* codec.js —— 编码/加解密纯前端算法库
|
||||
* 提供:UTF-8、Base64、Base32、URL、Unicode、SHA 系列(Web Crypto 原生)
|
||||
* MD5 / SHA-224 依赖 CryptoJS(由页面懒加载,双 CDN fallback)
|
||||
*/
|
||||
(function (global) {
|
||||
'use strict';
|
||||
|
||||
/* ---------- UTF-8 工具 ---------- */
|
||||
function utf8Encode(str) {
|
||||
if (typeof TextEncoder !== 'undefined') return new TextEncoder().encode(str);
|
||||
// 降级实现
|
||||
var out = [], ch, i, code;
|
||||
for (i = 0; i < str.length; i++) {
|
||||
code = str.charCodeAt(i);
|
||||
if (code < 0x80) out.push(code);
|
||||
else if (code < 0x800) {
|
||||
out.push(0xc0 | (code >> 6), 0x80 | (code & 0x3f));
|
||||
} else if (code < 0xd800 || code >= 0xe000) {
|
||||
out.push(0xe0 | (code >> 12), 0x80 | ((code >> 6) & 0x3f), 0x80 | (code & 0x3f));
|
||||
} else {
|
||||
// surrogate pair
|
||||
ch = (code - 0xd800) * 0x400 + (str.charCodeAt(++i) - 0xdc00) + 0x10000;
|
||||
out.push(0xf0 | (ch >> 18), 0x80 | ((ch >> 12) & 0x3f), 0x80 | ((ch >> 6) & 0x3f), 0x80 | (ch & 0x3f));
|
||||
}
|
||||
}
|
||||
return new Uint8Array(out);
|
||||
}
|
||||
|
||||
function utf8Decode(bytes) {
|
||||
if (typeof TextDecoder !== 'undefined') return new TextDecoder('utf-8').decode(bytes);
|
||||
var out = '', i = 0, b1, b2, b3, b4, code;
|
||||
while (i < bytes.length) {
|
||||
b1 = bytes[i++];
|
||||
if (b1 < 0x80) { out += String.fromCharCode(b1); }
|
||||
else if (b1 < 0xe0) { b2 = bytes[i++]; out += String.fromCharCode(((b1 & 0x1f) << 6) | (b2 & 0x3f)); }
|
||||
else if (b1 < 0xf0) {
|
||||
b2 = bytes[i++]; b3 = bytes[i++];
|
||||
out += String.fromCharCode(((b1 & 0x0f) << 12) | ((b2 & 0x3f) << 6) | (b3 & 0x3f));
|
||||
} else {
|
||||
b2 = bytes[i++]; b3 = bytes[i++]; b4 = bytes[i++];
|
||||
code = ((b1 & 0x07) << 18) | ((b2 & 0x3f) << 12) | ((b3 & 0x3f) << 6) | (b4 & 0x3f);
|
||||
code -= 0x10000;
|
||||
out += String.fromCharCode(0xd800 + (code >> 10), 0xdc00 + (code & 0x3ff));
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
function bytesToBin(bytes) {
|
||||
var bin = '', i;
|
||||
for (i = 0; i < bytes.length; i++) {
|
||||
bin += String.fromCharCode(bytes[i]);
|
||||
}
|
||||
return bin;
|
||||
}
|
||||
|
||||
function binToBytes(bin) {
|
||||
var out = new Uint8Array(bin.length), i;
|
||||
for (i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);
|
||||
return out;
|
||||
}
|
||||
|
||||
/* ---------- Base64(UTF-8 安全) ---------- */
|
||||
function b64Encode(str) {
|
||||
var bytes = utf8Encode(str);
|
||||
// 浏览器环境用 btoa
|
||||
if (typeof btoa !== 'undefined') {
|
||||
var bin = '';
|
||||
for (var i = 0; i < bytes.length; i++) bin += String.fromCharCode(bytes[i]);
|
||||
return btoa(bin);
|
||||
}
|
||||
return global.Base64 && global.Base64.encode(bytesToBin(bytes)) ? global.Base64.encode(bytesToBin(bytes)) : '';
|
||||
}
|
||||
|
||||
function b64Decode(b64) {
|
||||
b64 = String(b64 || '').replace(/\s+/g, '');
|
||||
var bin;
|
||||
if (typeof atob !== 'undefined') {
|
||||
bin = atob(b64);
|
||||
} else if (global.Base64) {
|
||||
bin = global.Base64.decode(b64);
|
||||
} else {
|
||||
throw new Error('当前环境不支持 Base64 解码');
|
||||
}
|
||||
return utf8Decode(binToBytes(bin));
|
||||
}
|
||||
|
||||
/* ---------- Base32(RFC 4648,UTF-8 安全) ---------- */
|
||||
var B32_ALPHA = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
|
||||
|
||||
function base32Encode(str) {
|
||||
var bytes = utf8Encode(str), out = '', bits = 0, value = 0, i;
|
||||
for (i = 0; i < bytes.length; i++) {
|
||||
value = (value << 8) | bytes[i];
|
||||
bits += 8;
|
||||
while (bits >= 5) {
|
||||
out += B32_ALPHA[(value >>> (bits - 5)) & 31];
|
||||
bits -= 5;
|
||||
}
|
||||
}
|
||||
if (bits > 0) out += B32_ALPHA[(value << (5 - bits)) & 31];
|
||||
while (out.length % 8 !== 0) out += '=';
|
||||
return out;
|
||||
}
|
||||
|
||||
function base32Decode(b32) {
|
||||
b32 = String(b32 || '').toUpperCase().replace(/[=\s]/g, '');
|
||||
if (!b32) return '';
|
||||
var bits = 0, value = 0, out = [], i, idx, b;
|
||||
for (i = 0; i < b32.length; i++) {
|
||||
idx = B32_ALPHA.indexOf(b32[i]);
|
||||
if (idx === -1) throw new Error('Base32 字符串包含非法字符: ' + b32[i]);
|
||||
value = (value << 5) | idx;
|
||||
bits += 5;
|
||||
if (bits >= 8) {
|
||||
b = (value >>> (bits - 8)) & 0xff;
|
||||
out.push(b);
|
||||
bits -= 8;
|
||||
}
|
||||
}
|
||||
return utf8Decode(new Uint8Array(out));
|
||||
}
|
||||
|
||||
/* ---------- URL 编解码 ---------- */
|
||||
function urlEncode(str) { return encodeURIComponent(String(str)); }
|
||||
function urlDecode(str) { return decodeURIComponent(String(str).replace(/\+/g, ' ')); }
|
||||
|
||||
/* ---------- Unicode 编解码(支持中文、emoji) ---------- */
|
||||
function unicodeEncode(str) {
|
||||
str = String(str);
|
||||
var out = [], i, code;
|
||||
for (i = 0; i < str.length; i++) {
|
||||
code = str.charCodeAt(i);
|
||||
if (code >= 0xd800 && code <= 0xdbff && i + 1 < str.length) {
|
||||
// 代理对:按两个 \uXXXX 输出,JS 自动组合
|
||||
out.push('\\u' + code.toString(16).toUpperCase().padStart(4, '0'));
|
||||
out.push('\\u' + str.charCodeAt(++i).toString(16).toUpperCase().padStart(4, '0'));
|
||||
} else {
|
||||
out.push('\\u' + code.toString(16).toUpperCase().padStart(4, '0'));
|
||||
}
|
||||
}
|
||||
return out.join('');
|
||||
}
|
||||
|
||||
function unicodeDecode(str) {
|
||||
str = String(str);
|
||||
// 兼容 \u{1F600} 与 \uXXXX 两种写法
|
||||
str = str.replace(/\\u\{([0-9a-fA-F]{1,6})\}/g, function (m, h) {
|
||||
var cp = parseInt(h, 16);
|
||||
if (cp > 0xffff) {
|
||||
cp -= 0x10000;
|
||||
return String.fromCharCode(0xd800 + (cp >> 10), 0xdc00 + (cp & 0x3ff));
|
||||
}
|
||||
return String.fromCharCode(cp);
|
||||
});
|
||||
str = str.replace(/\\u([0-9a-fA-F]{4})/g, function (m, h) {
|
||||
return String.fromCharCode(parseInt(h, 16));
|
||||
});
|
||||
return str;
|
||||
}
|
||||
|
||||
/* ---------- SHA 系列(Web Crypto 原生) ---------- */
|
||||
var HASHES = { 'SHA-1': 'SHA-1', 'SHA-256': 'SHA-256', 'SHA-384': 'SHA-384', 'SHA-512': 'SHA-512' };
|
||||
|
||||
function hexFromBuffer(buf) {
|
||||
var bytes = new Uint8Array(buf), out = '', i;
|
||||
for (i = 0; i < bytes.length; i++) out += bytes[i].toString(16).padStart(2, '0');
|
||||
return out;
|
||||
}
|
||||
|
||||
function shaDigest(algorithm, text) {
|
||||
var bytes = utf8Encode(text);
|
||||
if (typeof crypto !== 'undefined' && crypto.subtle) {
|
||||
return crypto.subtle.digest(algorithm, bytes).then(hexFromBuffer);
|
||||
}
|
||||
// 非安全上下文(如普通 http)无 Web Crypto:回退 crypto-js
|
||||
return cryptoJsDigest(algorithm, text);
|
||||
}
|
||||
|
||||
/* ---------- CryptoJS 懒加载(MD5 / SHA-224 等需要) ---------- */
|
||||
var CDN_CRYPTO_JS = [
|
||||
'https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.2.0/crypto-js.min.js',
|
||||
'https://cdn.jsdelivr.net/npm/crypto-js@4.2.0/crypto-js.min.js'
|
||||
];
|
||||
|
||||
var cryptoJSPromise = null;
|
||||
function loadCryptoJS() {
|
||||
if (global.CryptoJS) return Promise.resolve(global.CryptoJS);
|
||||
if (cryptoJSPromise) return cryptoJSPromise;
|
||||
cryptoJSPromise = new Promise(function (resolve) {
|
||||
var load = function (idx) {
|
||||
if (global.CryptoJS) { resolve(global.CryptoJS); return; }
|
||||
if (idx >= CDN_CRYPTO_JS.length) { resolve(null); return; }
|
||||
var s = document.createElement('script');
|
||||
s.src = CDN_CRYPTO_JS[idx];
|
||||
s.onload = function () { resolve(global.CryptoJS || null); };
|
||||
s.onerror = function () { load(idx + 1); };
|
||||
document.head.appendChild(s);
|
||||
};
|
||||
load(0);
|
||||
});
|
||||
return cryptoJSPromise;
|
||||
}
|
||||
|
||||
var CRYPTO_JS_METHODS = {
|
||||
'MD5': 'MD5', 'SHA-1': 'SHA1', 'SHA-224': 'SHA224',
|
||||
'SHA-256': 'SHA256', 'SHA-384': 'SHA384', 'SHA-512': 'SHA512'
|
||||
};
|
||||
|
||||
function cryptoJsDigest(algo, text) {
|
||||
return loadCryptoJS().then(function (C) {
|
||||
if (!C) throw new Error('计算 ' + algo + ' 需要联网加载加密组件(crypto-js)失败,请检查网络');
|
||||
var method = CRYPTO_JS_METHODS[algo];
|
||||
if (!method || typeof C[method] !== 'function') throw new Error('不支持的算法: ' + algo);
|
||||
return C[method](text).toString(C.enc.Hex);
|
||||
});
|
||||
}
|
||||
|
||||
function hashText(algo, text) {
|
||||
if (HASHES[algo]) return shaDigest(HASHES[algo], text);
|
||||
if (algo === 'MD5' || algo === 'SHA-224') return cryptoJsDigest(algo, text);
|
||||
return Promise.reject(new Error('未知算法: ' + algo));
|
||||
}
|
||||
|
||||
/* ---------- 导出 ---------- */
|
||||
global.CodecLib = {
|
||||
utf8Encode: utf8Encode,
|
||||
utf8Decode: utf8Decode,
|
||||
b64Encode: b64Encode,
|
||||
b64Decode: b64Decode,
|
||||
base32Encode: base32Encode,
|
||||
base32Decode: base32Decode,
|
||||
urlEncode: urlEncode,
|
||||
urlDecode: urlDecode,
|
||||
unicodeEncode: unicodeEncode,
|
||||
unicodeDecode: unicodeDecode,
|
||||
hashText: hashText,
|
||||
hashes: ['MD5', 'SHA-1', 'SHA-224', 'SHA-256', 'SHA-384', 'SHA-512']
|
||||
};
|
||||
})(window);
|
||||
@@ -0,0 +1,308 @@
|
||||
/* common.js —— 全站通用交互
|
||||
* 功能:昼/夜主题切换、实时时钟、随机名言刷新、四大板块 hover 浮层、
|
||||
* 搜索栏(引擎下拉/清除/回车搜索)、复制到剪贴板、DOM 工具函数
|
||||
*/
|
||||
(function (global) {
|
||||
'use strict';
|
||||
|
||||
/* ---------- 工具 ---------- */
|
||||
function $(sel, root) { return (root || document).querySelector(sel); }
|
||||
function $$(sel, root) { return Array.prototype.slice.call((root || document).querySelectorAll(sel)); }
|
||||
|
||||
/* ---------- 主题(昼/夜) ---------- */
|
||||
var THEME_KEY = 'hp-theme';
|
||||
|
||||
function currentTheme() {
|
||||
var saved = null;
|
||||
try { saved = localStorage.getItem(THEME_KEY); } catch (e) { /* ignore */ }
|
||||
if (saved === 'light' || saved === 'dark') return saved;
|
||||
// 未设置:跟随系统
|
||||
return (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) ? 'dark' : 'light';
|
||||
}
|
||||
|
||||
function applyTheme(t, persist) {
|
||||
document.documentElement.setAttribute('data-theme', t);
|
||||
if (persist) {
|
||||
try { localStorage.setItem(THEME_KEY, t); } catch (e) { /* ignore */ }
|
||||
}
|
||||
var icons = $$('.js-theme-icon');
|
||||
icons.forEach(function (el) { el.textContent = (t === 'dark') ? '☀' : '☾'; });
|
||||
var btn = $('.js-theme-btn');
|
||||
if (btn) btn.title = (t === 'dark') ? '切换到白天模式' : '切换到黑夜模式';
|
||||
}
|
||||
|
||||
function initTheme() {
|
||||
applyTheme(currentTheme(), false);
|
||||
$$('.js-theme-btn').forEach(function (btn) {
|
||||
btn.addEventListener('click', function () {
|
||||
var next = (document.documentElement.getAttribute('data-theme') === 'dark') ? 'light' : 'dark';
|
||||
applyTheme(next, true);
|
||||
});
|
||||
});
|
||||
if (window.matchMedia) {
|
||||
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', function () {
|
||||
// 用户手动选过则不跟随系统变化
|
||||
try {
|
||||
if (!localStorage.getItem(THEME_KEY)) applyTheme(currentTheme(), false);
|
||||
} catch (e) { applyTheme(currentTheme(), false); }
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------- 实时时钟 ---------- */
|
||||
function pad(n) { return (n < 10 ? '0' : '') + n; }
|
||||
function formatTime(d) {
|
||||
return d.getFullYear() + '-' + pad(d.getMonth() + 1) + '-' + pad(d.getDate()) + ' ' +
|
||||
pad(d.getHours()) + ':' + pad(d.getMinutes()) + ':' + pad(d.getSeconds());
|
||||
}
|
||||
function initClocks() {
|
||||
function tick() { $$('.js-clock').forEach(function (el) { el.textContent = formatTime(new Date()); }); }
|
||||
tick();
|
||||
setInterval(tick, 1000);
|
||||
}
|
||||
|
||||
/* ---------- 名言条:点击格言本身切换 ---------- */
|
||||
function initQuoteRefresh() {
|
||||
$$('.js-quote').forEach(function (quote) {
|
||||
quote.addEventListener('click', function () {
|
||||
var list = $$('.js-quote-pool span', document); // 服务端把所有名言放入隐藏池
|
||||
if (!list.length) return;
|
||||
// 定位当前展示文本在池中的位置,避免换到下一条仍是同一条
|
||||
var currentText = quote.textContent;
|
||||
var cur = -1;
|
||||
for (var i = 0; i < list.length; i++) {
|
||||
if (list[i].textContent === currentText) { cur = i; break; }
|
||||
}
|
||||
var n = list.length;
|
||||
var idx = Math.floor(Math.random() * n);
|
||||
if (n > 1 && cur !== -1) {
|
||||
while (idx === cur) idx = (idx + 1) % n;
|
||||
}
|
||||
quote.textContent = list[idx].textContent;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/* ---------- 首页四大板块 hover 展开说明 ---------- */
|
||||
function initBoardHover() {
|
||||
var section = $('.js-boards');
|
||||
if (!section) return;
|
||||
var cards = $$('.js-board-card', section);
|
||||
var overlay = $('.js-board-panel', section);
|
||||
if (!cards.length || !overlay) return;
|
||||
var titleEl = $('.js-board-panel-title', overlay);
|
||||
var descEl = $('.js-board-panel-desc', overlay);
|
||||
var bodyEl = section;
|
||||
|
||||
function showPanel(card) {
|
||||
var name = card.getAttribute('data-name') || '';
|
||||
var desc = card.getAttribute('data-desc') || '';
|
||||
var idx = cards.indexOf(card);
|
||||
if (titleEl) titleEl.textContent = name;
|
||||
if (descEl) descEl.textContent = desc;
|
||||
overlay.classList.remove('panel-left', 'panel-right');
|
||||
// 第 0 / 1 块吸附左侧边缘,第 2 / 3 块吸附右侧边缘(实际板块位置不变)
|
||||
if (idx === 0 || idx === 1) overlay.classList.add('panel-left');
|
||||
else overlay.classList.add('panel-right');
|
||||
overlay.classList.add('visible');
|
||||
}
|
||||
|
||||
cards.forEach(function (card) {
|
||||
card.addEventListener('mouseenter', function () { showPanel(card); });
|
||||
card.addEventListener('click', function () { /* 点击由 <a> 包裹,这里无额外处理 */ });
|
||||
});
|
||||
section.addEventListener('mouseleave', function () { overlay.classList.remove('visible'); });
|
||||
}
|
||||
|
||||
/* ---------- 搜索栏 ---------- */
|
||||
var DEFAULT_ENGINES = [
|
||||
{ key: 'bing', name: 'Bing', icon: 'B', url: 'https://www.bing.com/search?q={kw}' },
|
||||
{ key: 'baidu', name: '百度', icon: '度', url: 'https://www.baidu.com/s?wd={kw}' },
|
||||
{ key: 'github', name: 'GitHub', icon: 'G', url: 'https://github.com/search?q={kw}' },
|
||||
{ key: 'google', name: 'Google', icon: 'G', url: 'https://www.google.com/search?q={kw}' }
|
||||
];
|
||||
|
||||
function initSearch() {
|
||||
var box = $('.js-search');
|
||||
if (!box) return;
|
||||
var cfg = null;
|
||||
try { cfg = JSON.parse(box.getAttribute('data-engines') || 'null'); } catch (e) { cfg = null; }
|
||||
var engines = (cfg && cfg.length) ? cfg : DEFAULT_ENGINES;
|
||||
var curKey = box.getAttribute('data-engine') || engines[0].key;
|
||||
var cur = engines.filter(function (e) { return e.key === curKey; })[0] || engines[0];
|
||||
|
||||
var input = $('.js-search-input', box);
|
||||
var clearBtn = $('.js-search-clear', box);
|
||||
var engineBtn = $('.js-engine-btn', box);
|
||||
var engineName = $('.js-engine-name', box);
|
||||
var menu = $('.js-engine-menu', box);
|
||||
|
||||
function setEngine(e) {
|
||||
cur = e;
|
||||
// 按钮区域只显示图标(全称在展开下拉列表时展示)
|
||||
if (engineName) engineName.textContent = e.icon || '';
|
||||
if (engineBtn) engineBtn.title = '搜索引擎:' + e.name;
|
||||
box.setAttribute('data-engine', e.key);
|
||||
hideMenu();
|
||||
}
|
||||
function showMenu() {
|
||||
if (!menu) return;
|
||||
if (!menu.children.length) {
|
||||
engines.forEach(function (e) {
|
||||
var li = document.createElement('li');
|
||||
li.textContent = e.icon + ' ' + e.name;
|
||||
li.className = (e.key === cur.key) ? 'active' : '';
|
||||
li.addEventListener('click', function () { setEngine(e); });
|
||||
menu.appendChild(li);
|
||||
});
|
||||
}
|
||||
menu.classList.add('open');
|
||||
}
|
||||
function hideMenu() { if (menu) menu.classList.remove('open'); }
|
||||
|
||||
function updateClear() {
|
||||
if (clearBtn) clearBtn.style.visibility = (input && input.value) ? 'visible' : 'hidden';
|
||||
}
|
||||
function doSearch() {
|
||||
var kw = (input ? input.value : '').trim();
|
||||
if (!kw) { if (input) input.focus(); return; }
|
||||
window.open(cur.url.replace('{kw}', encodeURIComponent(kw)), '_blank', 'noopener');
|
||||
}
|
||||
|
||||
if (engineBtn) engineBtn.addEventListener('click', function (ev) {
|
||||
ev.stopPropagation();
|
||||
if (menu && menu.classList.contains('open')) hideMenu(); else showMenu();
|
||||
});
|
||||
if (clearBtn) clearBtn.addEventListener('click', function () {
|
||||
if (input) { input.value = ''; input.focus(); }
|
||||
updateClear();
|
||||
});
|
||||
if (input) {
|
||||
input.addEventListener('input', updateClear);
|
||||
input.addEventListener('keydown', function (ev) { if (ev.key === 'Enter') doSearch(); });
|
||||
}
|
||||
document.addEventListener('click', function () { hideMenu(); });
|
||||
var goBtn = $('.js-search-go', box);
|
||||
if (goBtn) goBtn.addEventListener('click', doSearch);
|
||||
setEngine(cur);
|
||||
updateClear();
|
||||
}
|
||||
|
||||
/* ---------- 后台图标控件:文本 / 图片上传(≤200KB → dataURL) ---------- */
|
||||
function isIconImage(v) {
|
||||
v = String(v || '').trim();
|
||||
if (!v) return false;
|
||||
if (/^data:image\//i.test(v) || /^https?:\/\//i.test(v)) return true;
|
||||
if (/\.(png|jpe?g|gif|svg|webp)(\?|#|$)/i.test(v)) return true;
|
||||
return v.charAt(0) === '/' || v.indexOf('./') === 0 || v.indexOf('../') === 0;
|
||||
}
|
||||
function updateIconPreview(ctl) {
|
||||
var input = ctl.querySelector('.icon-input');
|
||||
var box = ctl.querySelector('.icon-preview');
|
||||
if (!input || !box) return;
|
||||
var v = input.value.trim();
|
||||
box.innerHTML = '';
|
||||
if (!v) return; // 空:显示空心占位框
|
||||
if (isIconImage(v)) {
|
||||
var img = document.createElement('img');
|
||||
img.src = v;
|
||||
img.alt = '';
|
||||
img.loading = 'lazy';
|
||||
box.appendChild(img);
|
||||
} else {
|
||||
box.textContent = v;
|
||||
}
|
||||
}
|
||||
function initIconControls() {
|
||||
// 点击“上传”→ 触发隐藏 file
|
||||
document.addEventListener('click', function (ev) {
|
||||
var btn = ev.target && ev.target.closest ? ev.target.closest('.icon-upload') : null;
|
||||
if (!btn) return;
|
||||
var ctl = btn.closest('.icon-ctl');
|
||||
var file = ctl ? ctl.querySelector('.icon-file') : null;
|
||||
if (file) file.click();
|
||||
});
|
||||
// 选择图片 → 校验并转 dataURL 写入同控件文本框
|
||||
document.addEventListener('change', function (ev) {
|
||||
var file = ev.target;
|
||||
if (!file || !file.classList || !file.classList.contains('icon-file')) return;
|
||||
var ctl = file.closest('.icon-ctl');
|
||||
var input = ctl ? ctl.querySelector('.icon-input') : null;
|
||||
var f = file.files && file.files[0];
|
||||
function reset() { file.value = ''; }
|
||||
if (!f) return;
|
||||
if (f.type.indexOf('image/') !== 0) { alert('请选择图片文件。'); reset(); return; }
|
||||
if (f.size > 200 * 1024) { alert('图片不能超过 200KB。'); reset(); return; }
|
||||
var rd = new FileReader();
|
||||
rd.onload = function () {
|
||||
if (input) {
|
||||
input.value = rd.result;
|
||||
updateIconPreview(ctl);
|
||||
}
|
||||
reset();
|
||||
};
|
||||
rd.onerror = function () { alert('图片读取失败,请重试。'); reset(); };
|
||||
rd.readAsDataURL(f);
|
||||
});
|
||||
// 手动输入文本 → 实时预览
|
||||
document.addEventListener('input', function (ev) {
|
||||
var t = ev.target;
|
||||
if (t && t.classList && t.classList.contains('icon-input')) {
|
||||
updateIconPreview(t.closest('.icon-ctl'));
|
||||
}
|
||||
});
|
||||
// 初始化页面既有控件预览
|
||||
$$('.icon-ctl').forEach(updateIconPreview);
|
||||
}
|
||||
|
||||
/* ---------- 复制 ---------- */
|
||||
function copyText(text, btnEl) {
|
||||
function done(ok) {
|
||||
if (!btnEl) return;
|
||||
var old = btnEl.textContent;
|
||||
btnEl.textContent = ok ? '✓ 已复制' : '复制失败';
|
||||
setTimeout(function () { btnEl.textContent = old; }, 1500);
|
||||
}
|
||||
if (navigator.clipboard && navigator.clipboard.writeText) {
|
||||
navigator.clipboard.writeText(text).then(function () { done(true); }, function () { fallbackCopy(text, done); });
|
||||
} else {
|
||||
fallbackCopy(text, done);
|
||||
}
|
||||
}
|
||||
function fallbackCopy(text, done) {
|
||||
var ta = document.createElement('textarea');
|
||||
ta.value = text;
|
||||
ta.style.cssText = 'position:fixed;opacity:0;';
|
||||
document.body.appendChild(ta);
|
||||
ta.select();
|
||||
try { done(document.execCommand('copy')); } catch (e) { done(false); }
|
||||
document.body.removeChild(ta);
|
||||
}
|
||||
function initCopyButtons() {
|
||||
document.addEventListener('click', function (ev) {
|
||||
var btn = ev.target.closest ? ev.target.closest('.js-copy') : null;
|
||||
if (!btn) return;
|
||||
var text = btn.getAttribute('data-copy');
|
||||
if (text === null || text === undefined) {
|
||||
var target = $(btn.getAttribute('data-target') || '');
|
||||
text = target ? target.value : '';
|
||||
}
|
||||
copyText(text, btn);
|
||||
});
|
||||
}
|
||||
|
||||
/* ---------- 自动初始化 ---------- */
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
initTheme();
|
||||
initClocks();
|
||||
initQuoteRefresh();
|
||||
initBoardHover();
|
||||
initSearch();
|
||||
initIconControls();
|
||||
initCopyButtons();
|
||||
});
|
||||
|
||||
global.HomePage = {
|
||||
$: $, $$: $$, copyText: copyText, applyTheme: applyTheme, currentTheme: currentTheme
|
||||
};
|
||||
})(window);
|
||||
@@ -0,0 +1,206 @@
|
||||
/* gmcrypto.js —— 国密 SM2 / SM3 / SM4 前端封装
|
||||
* SM1 为国密硬件算法(不公开、依赖专用加密芯片),无法在浏览器纯软件实现,
|
||||
* 故本页提供可在网页中直接使用的 SM2(非对称)/ SM3(摘要)/ SM4(对称分组)。
|
||||
* 底层使用 sm-crypto@0.3.13,运行时按需双 CDN 懒加载(jsdelivr → unpkg)。
|
||||
*/
|
||||
(function (global) {
|
||||
'use strict';
|
||||
|
||||
var VERSION = '0.3.13';
|
||||
var LIBS = {
|
||||
sm2: {
|
||||
file: 'sm2.js', key: 'sm2',
|
||||
urls: [
|
||||
'https://cdn.jsdelivr.net/npm/sm-crypto@' + VERSION + '/dist/sm2.js',
|
||||
'https://unpkg.com/sm-crypto@' + VERSION + '/dist/sm2.js'
|
||||
]
|
||||
},
|
||||
sm3: {
|
||||
file: 'sm3.js', key: 'sm3',
|
||||
urls: [
|
||||
'https://cdn.jsdelivr.net/npm/sm-crypto@' + VERSION + '/dist/sm3.js',
|
||||
'https://unpkg.com/sm-crypto@' + VERSION + '/dist/sm3.js'
|
||||
]
|
||||
},
|
||||
sm4: {
|
||||
file: 'sm4.js', key: 'sm4',
|
||||
urls: [
|
||||
'https://cdn.jsdelivr.net/npm/sm-crypto@' + VERSION + '/dist/sm4.js',
|
||||
'https://unpkg.com/sm-crypto@' + VERSION + '/dist/sm4.js'
|
||||
]
|
||||
}
|
||||
};
|
||||
var loadCache = {};
|
||||
|
||||
/** 加载指定算法库(返回 Promise<库对象|null>) */
|
||||
function loadLib(name) {
|
||||
var lib = LIBS[name];
|
||||
if (!lib) return Promise.resolve(null);
|
||||
if (global[lib.key]) return Promise.resolve(global[lib.key]);
|
||||
if (loadCache[name]) return loadCache[name];
|
||||
loadCache[name] = new Promise(function (resolve) {
|
||||
var load = function (idx) {
|
||||
if (global[lib.key]) { resolve(global[lib.key]); return; }
|
||||
if (idx >= lib.urls.length) { resolve(null); return; }
|
||||
var s = document.createElement('script');
|
||||
s.src = lib.urls[idx];
|
||||
s.onload = function () { resolve(global[lib.key] || null); };
|
||||
s.onerror = function () { load(idx + 1); };
|
||||
document.head.appendChild(s);
|
||||
};
|
||||
load(0);
|
||||
});
|
||||
return loadCache[name];
|
||||
}
|
||||
|
||||
/* ---------- 基础编码工具 ---------- */
|
||||
function utf8Bytes(str) {
|
||||
if (typeof TextEncoder !== 'undefined') return new TextEncoder().encode(String(str));
|
||||
var out = [], code, i;
|
||||
for (i = 0; i < str.length; i++) {
|
||||
code = str.charCodeAt(i);
|
||||
if (code < 0x80) out.push(code);
|
||||
else if (code < 0x800) out.push(0xc0 | (code >> 6), 0x80 | (code & 0x3f));
|
||||
else if (code < 0xd800 || code >= 0xe000) {
|
||||
out.push(0xe0 | (code >> 12), 0x80 | ((code >> 6) & 0x3f), 0x80 | (code & 0x3f));
|
||||
} else {
|
||||
var ch = (code - 0xd800) * 0x400 + (str.charCodeAt(++i) - 0xdc00) + 0x10000;
|
||||
out.push(0xf0 | (ch >> 18), 0x80 | ((ch >> 12) & 0x3f), 0x80 | ((ch >> 6) & 0x3f), 0x80 | (ch & 0x3f));
|
||||
}
|
||||
}
|
||||
return new Uint8Array(out);
|
||||
}
|
||||
|
||||
function hexToBytes(hexStr) {
|
||||
var h = String(hexStr).replace(/[^0-9a-fA-F]/g, '');
|
||||
if (h === '' || h.length % 2 !== 0) throw new Error('十六进制串长度需为偶数');
|
||||
var out = new Uint8Array(h.length / 2), i;
|
||||
for (i = 0; i < out.length; i++) {
|
||||
out[i] = parseInt(h.substr(i * 2, 2), 16);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
function bytesToHex(bytes) {
|
||||
var s = '', i, t;
|
||||
for (i = 0; i < bytes.length; i++) {
|
||||
t = bytes[i].toString(16);
|
||||
s += t.length < 2 ? '0' + t : t;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
function bytesToB64(bytes) {
|
||||
var s = '', i;
|
||||
for (i = 0; i < bytes.length; i++) s += String.fromCharCode(bytes[i]);
|
||||
return global.btoa(s);
|
||||
}
|
||||
|
||||
function b64ToBytes(b64) {
|
||||
var s = global.atob(String(b64).trim());
|
||||
var out = new Uint8Array(s.length), i;
|
||||
for (i = 0; i < s.length; i++) out[i] = s.charCodeAt(i);
|
||||
return out;
|
||||
}
|
||||
|
||||
function randomHex(bytesLen) {
|
||||
var c = global.crypto || global.msCrypto;
|
||||
var out = new Uint8Array(bytesLen), i;
|
||||
if (c && c.getRandomValues) {
|
||||
c.getRandomValues(out);
|
||||
} else {
|
||||
for (i = 0; i < bytesLen; i++) out[i] = Math.floor(Math.random() * 256);
|
||||
}
|
||||
return bytesToHex(out);
|
||||
}
|
||||
|
||||
/* ---------- SM4 密钥 / IV 规范化 ---------- */
|
||||
function sm4KeyBytes(keyStr) {
|
||||
var s = String(keyStr || '').trim();
|
||||
if (!s) throw new Error('请输入 SM4 密钥');
|
||||
if (/^[0-9a-fA-F]{32}$/.test(s)) return hexToBytes(s);
|
||||
var b = utf8Bytes(s);
|
||||
if (b.length === 16) return b;
|
||||
throw new Error('SM4 密钥需为 128 位(16 字节):可输入 32 位十六进制串,或恰好 16 个 ASCII 字符');
|
||||
}
|
||||
|
||||
function sm4IvHex(ivStr) {
|
||||
var s = String(ivStr || '').trim();
|
||||
if (/^[0-9a-fA-F]{32}$/.test(s)) return s;
|
||||
var b = utf8Bytes(s);
|
||||
if (b.length === 16) return bytesToHex(b);
|
||||
throw new Error('SM4 CBC 模式需要 16 字节 IV(32 位十六进制或恰好 16 个字符)');
|
||||
}
|
||||
|
||||
/* ---------- 业务 Promise ---------- */
|
||||
function asArray(bytes) { return Array.prototype.slice.call(bytes); }
|
||||
|
||||
function need(name) {
|
||||
return loadLib(name).then(function (lib) {
|
||||
if (!lib) throw new Error('国密 ' + name.toUpperCase() + ' 组件加载失败,请检查网络后重试');
|
||||
return lib;
|
||||
});
|
||||
}
|
||||
|
||||
function sm3Digest(text, hmacKeyHex) {
|
||||
return need('sm3').then(function (sm3) {
|
||||
if (hmacKeyHex) return sm3(String(text), { key: hmacKeyHex });
|
||||
return sm3(String(text));
|
||||
});
|
||||
}
|
||||
|
||||
function sm4Run(text, keyStr, mode, ivStr, isEncrypt) {
|
||||
return need('sm4').then(function (sm4) {
|
||||
var kb = asArray(sm4KeyBytes(keyStr));
|
||||
var opt = {};
|
||||
if (mode === 'cbc') opt = { mode: 'cbc', iv: sm4IvHex(ivStr) };
|
||||
if (isEncrypt) {
|
||||
var hex = sm4.encrypt(String(text), kb, opt);
|
||||
return { ok: true, hex: hex };
|
||||
}
|
||||
var raw = String(text).trim().replace(/\s+/g, '');
|
||||
var inArr;
|
||||
if (/^[0-9a-fA-F]+$/.test(raw) && raw.length % 2 === 0) inArr = asArray(hexToBytes(raw));
|
||||
else inArr = asArray(b64ToBytes(raw));
|
||||
var out = sm4.decrypt(inArr, kb, opt);
|
||||
return { ok: true, hex: '', text: out };
|
||||
});
|
||||
}
|
||||
|
||||
function sm2GenKey() {
|
||||
return need('sm2').then(function (sm2) {
|
||||
var kp = sm2.generateKeyPairHex();
|
||||
return { publicKey: kp.publicKey, privateKey: kp.privateKey };
|
||||
});
|
||||
}
|
||||
|
||||
function sm2Encrypt(text, publicKey) {
|
||||
return need('sm2').then(function (sm2) {
|
||||
if (!String(publicKey || '').trim()) throw new Error('SM2 加密请填写对方公钥');
|
||||
return sm2.doEncrypt(String(text), String(publicKey).trim(), 1);
|
||||
});
|
||||
}
|
||||
|
||||
function sm2Decrypt(cipherHex, privateKey) {
|
||||
return need('sm2').then(function (sm2) {
|
||||
if (!String(privateKey || '').trim()) throw new Error('SM2 解密请填写自己的私钥');
|
||||
return sm2.doDecrypt(String(cipherHex).trim().replace(/\s+/g, ''), String(privateKey).trim(), 1);
|
||||
});
|
||||
}
|
||||
|
||||
/* ---------- 导出 ---------- */
|
||||
global.GmCrypto = {
|
||||
load: loadLib,
|
||||
utf8Bytes: utf8Bytes,
|
||||
hexToBytes: hexToBytes,
|
||||
bytesToHex: bytesToHex,
|
||||
bytesToB64: bytesToB64,
|
||||
b64ToBytes: b64ToBytes,
|
||||
randomHex: randomHex,
|
||||
sm3: sm3Digest,
|
||||
sm4: sm4Run,
|
||||
sm2Key: sm2GenKey,
|
||||
sm2Encrypt: sm2Encrypt,
|
||||
sm2Decrypt: sm2Decrypt
|
||||
};
|
||||
})(window);
|
||||
+289
@@ -0,0 +1,289 @@
|
||||
/* ip.js —— IP 地址处理
|
||||
* 提取输入文本中全部 IPv4 → 按 /24 段聚合输出(文本 / 高亮预览):
|
||||
* IP段 发现数量(段内去重IP数) IP段性质
|
||||
* 1.2.3.0/24 8 公网
|
||||
* 1.2.3.4
|
||||
*
|
||||
* 「重点匹配 IP」:填写的 IP 命中后,其所在 /24 段优先置顶、对应 IP 红色标出。
|
||||
* CDN 段库由服务端通过 #ipCdnRaw 隐藏文本框注入,可在后台维护。
|
||||
*/
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
function $(id) { return document.getElementById(id); }
|
||||
|
||||
// 内网 / 保留地址段(IPv4)
|
||||
var PRIV_RANGES = [
|
||||
['0.0.0.0', 8], ['10.0.0.0', 8], ['100.64.0.0', 10], ['127.0.0.0', 8],
|
||||
['169.254.0.0', 16], ['172.16.0.0', 12], ['192.168.0.0', 16],
|
||||
['192.0.2.0', 24], ['198.51.100.0', 24], ['203.0.113.0', 24],
|
||||
['224.0.0.0', 4], ['240.0.0.0', 4]
|
||||
].map(function (r) {
|
||||
return { net: ipToInt(r[0]), prefix: r[1] };
|
||||
});
|
||||
|
||||
function ipToInt(ip) {
|
||||
var p = String(ip).split('.');
|
||||
return (((+p[0]) << 24) + ((+p[1]) << 16) + ((+p[2]) << 8) + (+p[3])) >>> 0;
|
||||
}
|
||||
function inRange(ipInt, net, prefix) {
|
||||
var mask = (prefix === 0) ? 0 : ((0xFFFFFFFF << (32 - prefix)) >>> 0);
|
||||
return ((ipInt & mask) >>> 0) === ((net & mask) >>> 0);
|
||||
}
|
||||
function isPrivate(ipInt) {
|
||||
for (var i = 0; i < PRIV_RANGES.length; i++) {
|
||||
if (inRange(ipInt, PRIV_RANGES[i].net, PRIV_RANGES[i].prefix)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* ---------- CDN 段库解析 ---------- */
|
||||
function parseCdnText(text) {
|
||||
var out = [], lines = String(text || '').split(/\r?\n/), i, m, p;
|
||||
for (i = 0; i < lines.length; i++) {
|
||||
var line = lines[i].trim();
|
||||
if (!line || line.charAt(0) === '#') continue;
|
||||
p = line.split(/\s+/);
|
||||
m = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\/(\d{1,2})$/.exec(p[0]);
|
||||
if (!m) continue;
|
||||
var a = +m[1], b = +m[2], c = +m[3], d = +m[4], pre = +m[5];
|
||||
if (a > 255 || b > 255 || c > 255 || d > 255 || pre > 32) continue;
|
||||
out.push({
|
||||
net: (((a << 24) + (b << 16) + (c << 8) + d) >>> 0),
|
||||
prefix: pre,
|
||||
label: p.slice(1).join(' ') || 'CDN'
|
||||
});
|
||||
}
|
||||
return out;
|
||||
}
|
||||
function cdnOf(ipInt, ranges) {
|
||||
for (var i = 0; i < ranges.length; i++) {
|
||||
if (inRange(ipInt, ranges[i].net, ranges[i].prefix)) return ranges[i].label;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/* ---------- IPv4 提取 ---------- */
|
||||
function extractIps(text) {
|
||||
var re = /(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/g, m, found = [];
|
||||
while ((m = re.exec(text)) !== null) {
|
||||
var a = +m[1], b = +m[2], c = +m[3], d = +m[4];
|
||||
if (a > 255 || b > 255 || c > 255 || d > 255) continue;
|
||||
found.push(a + '.' + b + '.' + c + '.' + d);
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
/* ---------- 重点 IP 解析 ---------- */
|
||||
function parseFocus(text) {
|
||||
var set = {};
|
||||
var parts = String(text || '').split(/[\s,,;;]+/);
|
||||
for (var i = 0; i < parts.length; i++) {
|
||||
var p = parts[i].trim();
|
||||
if (!p) continue;
|
||||
var m = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(p);
|
||||
if (!m) continue;
|
||||
if (+m[1] > 255 || +m[2] > 255 || +m[3] > 255 || +m[4] > 255) continue;
|
||||
set[m[1] + '.' + m[2] + '.' + m[3] + '.' + m[4]] = true;
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
function ipLess(a, b) {
|
||||
var aa = a.split('.').map(Number), bb = b.split('.').map(Number), k;
|
||||
for (k = 0; k < 4; k++) {
|
||||
if (aa[k] !== bb[k]) return aa[k] - bb[k];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
function keyLess(a, b) {
|
||||
var aa = a.split('.').map(Number), bb = b.split('.').map(Number), k;
|
||||
for (k = 0; k < 3; k++) {
|
||||
if (aa[k] !== bb[k]) return aa[k] - bb[k];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
var TYPE_ZH = { priv: '内网', cdn: 'CDN', pub: '公网' };
|
||||
|
||||
/* 返回 { segs:[{line, hit, ips:[{ip,hit}]}], segTotals, totalIps, totalSeg, hitSeg, hitIps, rangeCount } */
|
||||
function analyze(text, cdnRaw, focusSet) {
|
||||
var all = extractIps(text);
|
||||
if (!all.length) return null;
|
||||
var ranges = parseCdnText(cdnRaw);
|
||||
|
||||
var segMap = {}, segOrder = [];
|
||||
for (var i = 0; i < all.length; i++) {
|
||||
var ip = all[i];
|
||||
var key = ip.substring(0, ip.lastIndexOf('.'));
|
||||
if (!segMap[key]) {
|
||||
segMap[key] = { key: key, ips: [], classes: {} };
|
||||
segOrder.push(key);
|
||||
}
|
||||
var seg = segMap[key];
|
||||
if (seg.ips.indexOf(ip) === -1) {
|
||||
seg.ips.push(ip);
|
||||
var int = ipToInt(ip);
|
||||
var vendor = cdnOf(int, ranges);
|
||||
var cls = vendor ? 'cdn' : (isPrivate(int) ? 'priv' : 'pub');
|
||||
seg.classes[cls] = (seg.classes[cls] || 0) + 1;
|
||||
}
|
||||
}
|
||||
segOrder.sort(keyLess);
|
||||
|
||||
function segLabel(s) {
|
||||
var keys = Object.keys(s.classes);
|
||||
if (keys.length === 1) return TYPE_ZH[keys[0]];
|
||||
var best = keys.slice().sort(function (x, y) {
|
||||
return (s.classes[y] - s.classes[x]) || (TYPE_ZH[x] < TYPE_ZH[y] ? -1 : 1);
|
||||
})[0];
|
||||
return TYPE_ZH[best] + '为主(混合)';
|
||||
}
|
||||
|
||||
var segs = segOrder.map(function (k) { return segMap[k]; });
|
||||
segs.forEach(function (s) { s.label = segLabel(s); });
|
||||
// 命中重点 IP 的段排前,组内段号升序
|
||||
var focusSegs = [], otherSegs = [];
|
||||
segs.forEach(function (s) {
|
||||
s.hit = s.ips.some(function (ip) { return focusSet[ip]; });
|
||||
(s.hit ? focusSegs : otherSegs).push(s);
|
||||
});
|
||||
segs = focusSegs.concat(otherSegs);
|
||||
|
||||
var totalIps = 0, hitIps = 0, hitSeg = 0;
|
||||
segs.forEach(function (s) {
|
||||
totalIps += s.ips.length;
|
||||
if (s.hit) hitSeg++;
|
||||
s.ips.sort(ipLess);
|
||||
var h = [], o = [];
|
||||
s.ips.forEach(function (ip) {
|
||||
if (focusSet[ip]) { h.push(ip); hitIps++; }
|
||||
else o.push(ip);
|
||||
});
|
||||
s.details = h.concat(o);
|
||||
s.line = s.key + '.0/24\t' + s.ips.length + '\t' + s.label;
|
||||
});
|
||||
|
||||
var cntSeg = { priv: 0, cdn: 0, pub: 0 };
|
||||
segs.forEach(function (s) {
|
||||
var lab = s.label;
|
||||
if (lab.indexOf('内网') === 0) cntSeg.priv++;
|
||||
else if (lab.indexOf('CDN') === 0) cntSeg.cdn++;
|
||||
else cntSeg.pub++;
|
||||
});
|
||||
|
||||
return {
|
||||
segs: segs,
|
||||
totalIps: totalIps,
|
||||
totalSeg: segs.length,
|
||||
hitSeg: hitSeg,
|
||||
hitIps: hitIps,
|
||||
cntSeg: cntSeg,
|
||||
rangeCount: ranges.length
|
||||
};
|
||||
}
|
||||
|
||||
/* ---------- 文本 / 高亮输出 ---------- */
|
||||
function esc(s) {
|
||||
return String(s).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
||||
}
|
||||
function plainText(data) {
|
||||
var lines = ['IP段\t发现数量\tIP段性质'];
|
||||
data.segs.forEach(function (s) {
|
||||
lines.push(s.line);
|
||||
s.details.forEach(function (ip) { lines.push('\t' + ip); });
|
||||
lines.push('');
|
||||
});
|
||||
return lines.join('\n');
|
||||
}
|
||||
function previewHtml(data) {
|
||||
var parts = [];
|
||||
parts.push(esc('IP段\t发现数量\tIP段性质').replace(/\t/g, ' '));
|
||||
data.segs.forEach(function (s) {
|
||||
var lineTxt = s.line.replace(/\t/g, ' ');
|
||||
parts.push(s.hit ? '<span class="ip-seg-hit">★ ' + esc(lineTxt) + '</span>' : esc(lineTxt));
|
||||
s.details.forEach(function (ip) {
|
||||
parts.push(focusCur[ip] ? '<span class="ip-hit">' + esc(ip) + '</span>' : esc(ip));
|
||||
});
|
||||
parts.push('');
|
||||
});
|
||||
return parts.join('\n');
|
||||
}
|
||||
var focusCur = {};
|
||||
|
||||
/* ---------- 事件 ---------- */
|
||||
var lastData = null;
|
||||
function run() {
|
||||
var input = $('ipInput');
|
||||
var msg = $('ipMsg');
|
||||
msg.innerHTML = '';
|
||||
var text = input.value;
|
||||
if (!text.trim()) {
|
||||
msg.innerHTML = '<div class="err-msg">请先粘贴要分析的日志 / 文本内容。</div>';
|
||||
return;
|
||||
}
|
||||
var cdnRaw = ($('ipCdnRaw') && $('ipCdnRaw').value) || '';
|
||||
var fs = parseFocus($('ipFocus').value);
|
||||
focusCur = fs;
|
||||
lastData = analyze(text, cdnRaw, fs);
|
||||
if (!lastData) {
|
||||
$('ipResult').hidden = true;
|
||||
msg.innerHTML = '<div class="err-msg">未在输入内容中解析到有效的 IPv4 地址。</div>';
|
||||
return;
|
||||
}
|
||||
var d = lastData;
|
||||
$('ipPreview').innerHTML = previewHtml(d);
|
||||
var st = d.cntSeg;
|
||||
var note = '共提取去重 IP ' + d.totalIps + ' 个,涉及 ' + d.totalSeg + ' 个 /24 段(内网 ' +
|
||||
st.priv + ' 段 / CDN ' + st.cdn + ' 段 / 公网 ' + st.pub + ' 段)。';
|
||||
if (Object.keys(parseFocus($('ipFocus').value)).length === 0) {
|
||||
note += ' 未填写重点 IP,按原顺序输出。';
|
||||
} else if (d.hitIps === 0) {
|
||||
note += ' 填写的重点 IP 均未在输入内容中命中。';
|
||||
} else {
|
||||
note += ' 命中重点 IP ' + d.hitIps + ' 个,' + d.hitSeg + ' 个 /24 段已优先置顶。';
|
||||
}
|
||||
if (d.rangeCount === 0) note += ' CDN 段库为空,可在后台补充。';
|
||||
$('ipStat').textContent = note;
|
||||
$('ipResult').hidden = false;
|
||||
msg.innerHTML = '';
|
||||
}
|
||||
function copyText(text) {
|
||||
function done(ok) {
|
||||
var btn = $('ipCopy');
|
||||
var old = btn.textContent;
|
||||
btn.textContent = ok ? '✓ 已复制' : '复制失败';
|
||||
setTimeout(function () { btn.textContent = old; }, 1200);
|
||||
}
|
||||
if (navigator.clipboard && navigator.clipboard.writeText) {
|
||||
navigator.clipboard.writeText(text).then(function () { done(true); }, function () { fallback(text, done); });
|
||||
} else {
|
||||
fallback(text, done);
|
||||
}
|
||||
}
|
||||
function fallback(text, done) {
|
||||
var ta = document.createElement('textarea');
|
||||
ta.value = text;
|
||||
ta.style.cssText = 'position:fixed;opacity:0;';
|
||||
document.body.appendChild(ta);
|
||||
ta.select();
|
||||
try { done(document.execCommand('copy')); } catch (e) { done(false); }
|
||||
document.body.removeChild(ta);
|
||||
}
|
||||
function clearAll() {
|
||||
$('ipInput').value = '';
|
||||
$('ipFocus').value = '';
|
||||
$('ipMsg').innerHTML = '';
|
||||
$('ipResult').hidden = true;
|
||||
$('ipInput').focus();
|
||||
}
|
||||
|
||||
$('ipBtn').addEventListener('click', run);
|
||||
$('ipCopy').addEventListener('click', function () {
|
||||
if (lastData) copyText(plainText(lastData));
|
||||
});
|
||||
$('ipClear').addEventListener('click', clearAll);
|
||||
$('ipInput').addEventListener('keydown', function (ev) {
|
||||
if (ev.key === 'Enter' && (ev.ctrlKey || ev.metaKey)) run();
|
||||
});
|
||||
})();
|
||||
Reference in new issue
Block a user