Site updated: 2026-05-13 16:50:34

This commit is contained in:
llbzow
2026-05-13 16:50:38 +08:00
parent 8f2e89e58c
commit 54f0d09b31
361 changed files with 204078 additions and 0 deletions

62
js/tools/hash.js Normal file
View File

@@ -0,0 +1,62 @@
(function() {
function initHashTool() {
const container = document.getElementById('tool-hash-container');
if (!container) return;
container.addEventListener('click', (e) => e.stopPropagation());
const inputText = document.getElementById('input-text');
const resMd5 = document.getElementById('res-md5');
const resSha1 = document.getElementById('res-sha1');
const resSha256 = document.getElementById('res-sha256');
const resSha512 = document.getElementById('res-sha512');
const copyBtns = document.querySelectorAll('.copy-btn');
function calculateHash() {
const text = inputText.value;
if (!text) {
resMd5.innerText = '-';
resSha1.innerText = '-';
resSha256.innerText = '-';
resSha512.innerText = '-';
return;
}
if (typeof CryptoJS === 'undefined') {
resMd5.innerText = '加载核心库失败,请检查网络...';
return;
}
resMd5.innerText = CryptoJS.MD5(text).toString();
resSha1.innerText = CryptoJS.SHA1(text).toString();
resSha256.innerText = CryptoJS.SHA256(text).toString();
resSha512.innerText = CryptoJS.SHA512(text).toString();
}
inputText.addEventListener('input', calculateHash);
copyBtns.forEach(btn => {
btn.addEventListener('click', (e) => {
const targetId = e.target.getAttribute('data-copy-target');
const text = document.getElementById(targetId).innerText;
if (text === '-' || text.includes('失败')) return;
navigator.clipboard.writeText(text).then(() => {
const originalText = e.target.innerText;
e.target.innerText = '已复制';
setTimeout(() => e.target.innerText = originalText, 1000);
});
});
});
// Check if library loaded
const checkLib = setInterval(() => {
if (typeof CryptoJS !== 'undefined') {
clearInterval(checkLib);
calculateHash();
}
}, 500);
}
document.addEventListener('DOMContentLoaded', initHashTool);
document.addEventListener('pjax:complete', initHashTool);
})();