更新完善网页逻辑,工具迁移至html逻辑
This commit is contained in:
1 parent
c3bfce7afb
commit
646754c04d
26 files changed
+1606
-167
No files matched your search
+6
-5
@@ -1,6 +1,6 @@
|
||||
/* codec.js —— 编码/加解密纯前端算法库
|
||||
* 提供:UTF-8、Base64、Base32、URL、Unicode、SHA 系列(Web Crypto 原生)
|
||||
* MD5 / SHA-224 依赖 CryptoJS(由页面懒加载,双 CDN fallback)
|
||||
* MD5 / SHA-224 依赖 CryptoJS(优先本地 assets/js/crypto-js.min.js,缺失则回退 CDN)
|
||||
*/
|
||||
(function (global) {
|
||||
'use strict';
|
||||
@@ -177,10 +177,11 @@
|
||||
return cryptoJsDigest(algorithm, text);
|
||||
}
|
||||
|
||||
/* ---------- CryptoJS 懒加载(MD5 / SHA-224 等需要) ---------- */
|
||||
/* ---------- CryptoJS 懒加载(MD5 / SHA-224 等需要;优先本地,其次 CDN) ---------- */
|
||||
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'
|
||||
'../assets/js/crypto-js.min.js', // 本地内置(离线可用)
|
||||
'https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.2.0/crypto-js.min.js', // 回退 1
|
||||
'https://cdn.jsdelivr.net/npm/crypto-js@4.2.0/crypto-js.min.js' // 回退 2
|
||||
];
|
||||
|
||||
var cryptoJSPromise = null;
|
||||
@@ -209,7 +210,7 @@
|
||||
|
||||
function cryptoJsDigest(algo, text) {
|
||||
return loadCryptoJS().then(function (C) {
|
||||
if (!C) throw new Error('计算 ' + algo + ' 需要联网加载加密组件(crypto-js)失败,请检查网络');
|
||||
if (!C) throw new Error('计算 ' + algo + ' 的加密组件加载失败:请将 crypto-js.min.js 放入 assets/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);
|
||||
|
||||
+180
-2
@@ -342,10 +342,90 @@
|
||||
var f = ev.target;
|
||||
if (!f || !f.getAttribute || !f.hasAttribute('data-confirm')) return;
|
||||
ev.preventDefault();
|
||||
siteConfirm(f.getAttribute('data-confirm')).then(function (ok) { if (ok) f.submit(); });
|
||||
siteConfirm(f.getAttribute('data-confirm')).then(function (ok) {
|
||||
if (ok) { f.submit(); } else { hpClearScrollY(); }
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/* ---------- 同页 POST 提交后保持滚动位置(整页刷新不再跳回顶部) ---------- */
|
||||
var HP_SCROLL_KEY = 'hp-scroll-pos';
|
||||
function hpSamePagePost(f) {
|
||||
if (!f || !f.method) return false;
|
||||
if (!/post/i.test(f.method)) return false;
|
||||
if (f.target === '_blank') return false;
|
||||
var a = (f.getAttribute('action') || '').trim();
|
||||
if (a === '') return true; // 无 action = 提交当前页
|
||||
try {
|
||||
var cur = new URL(location.href.split('#')[0]);
|
||||
var u = new URL(a, cur.href);
|
||||
return u.origin === cur.origin && u.pathname === cur.pathname;
|
||||
} catch (e) { return false; }
|
||||
}
|
||||
function hpSaveScrollY() {
|
||||
try {
|
||||
var y = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
|
||||
sessionStorage.setItem(HP_SCROLL_KEY, JSON.stringify({ p: location.pathname + location.search, y: y }));
|
||||
} catch (e) { /* ignore */ }
|
||||
}
|
||||
function hpClearScrollY() {
|
||||
try { sessionStorage.removeItem(HP_SCROLL_KEY); } catch (e) { /* ignore */ }
|
||||
}
|
||||
var hpScrollTarget = -1;
|
||||
function hpRestoreScrollY() {
|
||||
if (hpScrollTarget >= 0) { window.scrollTo(0, hpScrollTarget); return; }
|
||||
try {
|
||||
var raw = sessionStorage.getItem(HP_SCROLL_KEY);
|
||||
if (!raw) return;
|
||||
sessionStorage.removeItem(HP_SCROLL_KEY);
|
||||
var d = JSON.parse(raw);
|
||||
if (d && d.p === (location.pathname + location.search) && typeof d.y === 'number' && d.y > 0) {
|
||||
hpScrollTarget = d.y;
|
||||
window.scrollTo(0, hpScrollTarget);
|
||||
}
|
||||
} catch (e) { hpClearScrollY(); }
|
||||
}
|
||||
// 捕获阶段:同页 POST 提交前保存(按回车等也会触发 submit 事件)
|
||||
document.addEventListener('submit', function (ev) {
|
||||
if (hpSamePagePost(ev.target)) hpSaveScrollY();
|
||||
}, true);
|
||||
// 捕获阶段:点击提交按钮时也保存(bindConfirmForms 确认后走 f.submit() 不触发 submit 事件)
|
||||
document.addEventListener('click', function (ev) {
|
||||
var t = ev.target;
|
||||
var btn = (t && t.closest) ? t.closest('button[type="submit"], input[type="submit"], button:not([type])') : null;
|
||||
if (!btn) return;
|
||||
var f = btn.form || null;
|
||||
if (hpSamePagePost(f)) hpSaveScrollY();
|
||||
}, true);
|
||||
// 资源加载完成后再定位一次,防止图片等异步资源改变高度造成轻微偏移
|
||||
window.addEventListener('load', function () {
|
||||
if (hpScrollTarget >= 0) {
|
||||
window.scrollTo(0, hpScrollTarget);
|
||||
hpScrollTarget = -1;
|
||||
}
|
||||
});
|
||||
|
||||
/* ---------- 首页访客信息(hero 信息模式:补齐屏幕分辨率 / 系统语言) ---------- */
|
||||
function initVisitorInfo() {
|
||||
var box = $('.js-visitor-box');
|
||||
if (!box) return;
|
||||
var langEl = $('.js-vlang', box);
|
||||
if (langEl) {
|
||||
var lang = '';
|
||||
try { lang = navigator.language || (navigator.languages && navigator.languages[0]) || ''; } catch (e) { /* ignore */ }
|
||||
langEl.textContent = lang || '--';
|
||||
}
|
||||
var scrEl = $('.js-vscreen', box);
|
||||
if (scrEl) {
|
||||
var w = 0, h = 0, dpr = 1;
|
||||
try { w = window.screen.width || 0; h = window.screen.height || 0; dpr = window.devicePixelRatio || 1; } catch (e) { /* ignore */ }
|
||||
if (w && h) {
|
||||
var ratio = Math.round(dpr * 100);
|
||||
scrEl.textContent = (ratio !== 100) ? (w + ' × ' + h + '(' + ratio + '%)') : (w + ' × ' + h);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------- 返回顶部(右下角按钮,滚动后出现;兼容内滚容器页面) ---------- */
|
||||
function initToTop() {
|
||||
var btn = document.querySelector('.js-to-top');
|
||||
@@ -380,8 +460,101 @@
|
||||
measure();
|
||||
}
|
||||
|
||||
/* ---------- 功能区静态工具页:库卡片 ?from=nav 进入时,返回按钮改为“返回上一页” ---------- */
|
||||
function initFuncBack() {
|
||||
var el = document.querySelector('.js-fb-back');
|
||||
if (!el) return;
|
||||
if (!/(?:^|[?&])from=nav(?:&|$)/.test(location.search)) return;
|
||||
el.textContent = '← 返回上一页';
|
||||
el.title = '返回上一页(回到来源库首页)';
|
||||
el.addEventListener('click', function (ev) {
|
||||
// 有浏览历史时返回来源页;否则保留默认 href(功能区首页)
|
||||
if (window.history.length > 1) {
|
||||
ev.preventDefault();
|
||||
window.history.back();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/* ---------- 右下角 Toast 通知(后台整页刷新后的成功/失败提示使用,不影响页面布局) ---------- */
|
||||
function hpToast(kind, text, dur) {
|
||||
if (text === '' || text === null || typeof text === 'undefined') return;
|
||||
kind = (kind === 'ok' || kind === 'err') ? kind : 'ok';
|
||||
var wrap = document.querySelector('.hp-toasts');
|
||||
if (!wrap) {
|
||||
wrap = document.createElement('div');
|
||||
wrap.className = 'hp-toasts';
|
||||
document.body.appendChild(wrap);
|
||||
}
|
||||
var box = document.createElement('div');
|
||||
box.className = 'hp-toast ' + kind;
|
||||
var ic = document.createElement('span');
|
||||
ic.className = 'ht-ic';
|
||||
ic.textContent = kind === 'ok' ? '✓' : '!';
|
||||
var tx = document.createElement('div');
|
||||
tx.className = 'ht-tx';
|
||||
tx.textContent = String(text);
|
||||
var x = document.createElement('button');
|
||||
x.type = 'button';
|
||||
x.className = 'ht-x';
|
||||
x.setAttribute('aria-label', '关闭提示');
|
||||
x.textContent = '×';
|
||||
function close() {
|
||||
if (!box.parentNode) return;
|
||||
box.classList.add('hide');
|
||||
setTimeout(function () {
|
||||
if (box.parentNode) box.parentNode.removeChild(box);
|
||||
if (wrap.parentNode && !wrap.children.length) wrap.parentNode.removeChild(wrap);
|
||||
}, 240);
|
||||
}
|
||||
x.addEventListener('click', close);
|
||||
box.appendChild(ic);
|
||||
box.appendChild(tx);
|
||||
box.appendChild(x);
|
||||
wrap.appendChild(box);
|
||||
var delay = (typeof dur === 'number' && dur > 0) ? dur : (kind === 'err' ? 6000 : 3600);
|
||||
setTimeout(close, delay);
|
||||
}
|
||||
/* 由 PHP 注入的整页操作提示(window.hpToastMsg = {kind, text})自动弹出 */
|
||||
function hpShowPageToast() {
|
||||
var m = window.hpToastMsg;
|
||||
if (!m || typeof m !== 'object') return;
|
||||
hpToast(m.kind, m.text);
|
||||
}
|
||||
|
||||
/* ---------- 静态工具页 favicon 跟随后台站点 logo(api/site.php 探测,异常静默回退默认) ---------- */
|
||||
function initSiteIcon() {
|
||||
// 仅纯静态 .html 页需要(PHP 页面 favicon 已由 layout_head 服务端输出)
|
||||
if (!/\.html$/i.test(location.pathname)) return;
|
||||
var iconEl = document.querySelector('link[rel~="icon"]');
|
||||
if (!iconEl) return;
|
||||
var abs = '';
|
||||
try { abs = new URL(iconEl.getAttribute('href') || '', location.href).href; } catch (e) { return; }
|
||||
var marker = '/assets/img/logo.svg';
|
||||
var pos = abs.indexOf(marker);
|
||||
if (pos < 0) return; // 非默认图标(已自定义)则无需处理
|
||||
var root = abs.slice(0, pos + 1);
|
||||
var xhr = new XMLHttpRequest();
|
||||
try {
|
||||
xhr.open('GET', root + 'api/site.php', true);
|
||||
xhr.timeout = 4000;
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState !== 4) return;
|
||||
try {
|
||||
var d = JSON.parse(xhr.responseText || '{}');
|
||||
if (d && typeof d.logo === 'string' && d.logo !== '') {
|
||||
iconEl.href = root + d.logo;
|
||||
}
|
||||
} catch (e) { /* 接口异常:保持默认图标 */ }
|
||||
};
|
||||
xhr.onerror = function () { /* file:// 或网络异常:保持默认图标 */ };
|
||||
xhr.send();
|
||||
} catch (e) { /* 同源限制等:保持默认图标 */ }
|
||||
}
|
||||
|
||||
/* ---------- 自动初始化 ---------- */
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
initSiteIcon();
|
||||
initTheme();
|
||||
initClocks();
|
||||
initQuoteRefresh();
|
||||
@@ -390,11 +563,16 @@
|
||||
initIconControls();
|
||||
initCopyButtons();
|
||||
bindConfirmForms();
|
||||
initVisitorInfo();
|
||||
initToTop();
|
||||
initFuncBack();
|
||||
hpShowPageToast();
|
||||
});
|
||||
|
||||
global.HomePage = {
|
||||
$: $, $$: $$, copyText: copyText, applyTheme: applyTheme, currentTheme: currentTheme,
|
||||
confirm: siteConfirm, ask: askConfirm
|
||||
confirm: siteConfirm, ask: askConfirm, toast: hpToast
|
||||
};
|
||||
// 底部脚本执行时 DOM 已解析完毕:在首帧绘制前后尽早恢复滚动位置,避免“先停在顶部再跳回”的大幅跳动
|
||||
hpRestoreScrollY();
|
||||
})(window);
|
||||
+11
-8
@@ -1,7 +1,7 @@
|
||||
/* gmcrypto.js —— 国密 SM2 / SM3 / SM4 前端封装
|
||||
* SM1 为国密硬件算法(不公开、依赖专用加密芯片),无法在浏览器纯软件实现,
|
||||
* 故本页提供可在网页中直接使用的 SM2(非对称)/ SM3(摘要)/ SM4(对称分组)。
|
||||
* 底层使用 sm-crypto@0.3.13,运行时按需双 CDN 懒加载(jsdelivr → unpkg)。
|
||||
* 底层使用 sm-crypto@0.3.13:优先本地 assets/js/sm-crypto/ 目录,缺失则回退 CDN(jsdelivr → unpkg)。
|
||||
*/
|
||||
(function (global) {
|
||||
'use strict';
|
||||
@@ -11,22 +11,25 @@
|
||||
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'
|
||||
'../assets/js/sm-crypto/sm2.js', // 本地内置(离线可用)
|
||||
'https://cdn.jsdelivr.net/npm/sm-crypto@' + VERSION + '/dist/sm2.js', // 回退 1
|
||||
'https://unpkg.com/sm-crypto@' + VERSION + '/dist/sm2.js' // 回退 2
|
||||
]
|
||||
},
|
||||
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'
|
||||
'../assets/js/sm-crypto/sm3.js', // 本地内置(离线可用)
|
||||
'https://cdn.jsdelivr.net/npm/sm-crypto@' + VERSION + '/dist/sm3.js', // 回退 1
|
||||
'https://unpkg.com/sm-crypto@' + VERSION + '/dist/sm3.js' // 回退 2
|
||||
]
|
||||
},
|
||||
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'
|
||||
'../assets/js/sm-crypto/sm4.js', // 本地内置(离线可用)
|
||||
'https://cdn.jsdelivr.net/npm/sm-crypto@' + VERSION + '/dist/sm4.js', // 回退 1
|
||||
'https://unpkg.com/sm-crypto@' + VERSION + '/dist/sm4.js' // 回退 2
|
||||
]
|
||||
}
|
||||
};
|
||||
@@ -137,7 +140,7 @@
|
||||
|
||||
function need(name) {
|
||||
return loadLib(name).then(function (lib) {
|
||||
if (!lib) throw new Error('国密 ' + name.toUpperCase() + ' 组件加载失败,请检查网络后重试');
|
||||
if (!lib) throw new Error('国密 ' + name.toUpperCase() + ' 组件加载失败:请将 ' + name + '.js 放入 assets/js/sm-crypto/ 目录离线使用,或检查网络后重试');
|
||||
return lib;
|
||||
});
|
||||
}
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@
|
||||
*
|
||||
* 段按出现次数(段内全部 IP 原文出现次数之和)从高到低排列;
|
||||
* 「重点匹配 IP」:填写的 IP 命中后,其所在 /24 段优先置顶、对应 IP 红色标出。
|
||||
* CDN 段库由服务端通过 #ipCdnRaw 隐藏文本框注入,可在后台维护。
|
||||
* CDN 段库默认内置在页面 #ipCdnRaw 隐藏文本框中(func/ip.html),可直接用编辑器增补厂商。
|
||||
*/
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
Reference in new issue
Block a user