oc-wiki/docs/js/quote-translate.js
小橘 973bdddbf8
Some checks failed
Deploy MkDocs to GitHub Pages / build (push) Has been cancelled
Deploy MkDocs to GitHub Pages / deploy (push) Has been cancelled
fix: data-cn 移到 p 标签,JS 只替换文本内容
2026-04-16 04:37:01 +00:00

23 lines
772 B
JavaScript

document.addEventListener('DOMContentLoaded', function () {
document.querySelectorAll('blockquote').forEach(function (el) {
const ps = el.querySelectorAll('p[data-cn]');
if (!ps.length) return;
const originals = Array.from(ps).map(p => p.textContent);
const translations = Array.from(ps).map(p => p.getAttribute('data-cn'));
let showing = 'orig';
function swap(to) {
ps.forEach((p, i) => {
p.textContent = to === 'cn' ? translations[i] : originals[i];
});
showing = to;
}
el.style.cursor = 'pointer';
el.addEventListener('mouseenter', () => swap('cn'));
el.addEventListener('mouseleave', () => swap('orig'));
el.addEventListener('click', () => swap(showing === 'orig' ? 'cn' : 'orig'));
});
});