跳转到内容

讨论:倭使日記

页面内容不支持其他语言。
添加话题
維基文庫,自由的圖書館
最新留言:DuckSoft在1年前发布在话题原文格式清理脚本

原文[编辑]

Blahhmosh留言2022年6月28日 (二) 22:33 (UTC)回复

https://jsg.aks.ac.kr/viewer/viewTxt?dataId=K2-3492%7C001#node?dataId=ARC_23492_001_0001 (感谢 User:BlahhmoshDuckSoft留言2022年7月2日 (六) 13:49 (UTC)回复

原文格式清理脚本[编辑]

因原文格式复杂,直接复制浏览器网页内容会引起内容错位,故制此脚本,用时贴于浏览器之控制台即可。

document.querySelectorAll("span[data-xsl-tag='page']").forEach(i => i.parentNode.remove());
[".xsl_para", "span"].forEach(selector => document.querySelectorAll(selector).forEach(para => {
    [].filter.call(para.childNodes, node => node.nodeName === "#text").forEach(node => {
        let trimmed = node.textContent.trim();
        if (trimmed.length === 0) node.remove();
        else node.textContent = trimmed;
    });
    [].filter.call(para.childNodes, node => node.nodeName === "BR").forEach(node => node.remove());
}));
document.querySelectorAll("span[data-xsl-tag='kspace']").forEach(i => i.innerHTML = ' ');
document.querySelectorAll(".xsl_para_tit").forEach(i => {if (!/^== /.test(i.innerText)) i.innerText = `== ${i.innerText.trim()} ==`});
document.body.appendChild(document.createTextNode(`<!-- ${window.location} -->`))

能力有限,抛砖引玉,请多指教。 DuckSoft留言2022年7月2日 (六) 14:55 (UTC)回复

這是什麽code?哪一個PROGRAM的? Blahhmosh留言2022年7月2日 (六) 21:03 (UTC)回复
此为 JavaScript,浏览器有调试控制台(F12 或右键——审查元素可唤出),贴代码按回车执行即可。 DuckSoft留言2022年7月2日 (六) 21:09 (UTC)回复
附加更新:自动处理原文注解:
document.querySelectorAll("span[data-xsl-tag='note']").forEach(e => e.innerText = e.innerText.replace(/\s+/g, '').replace(/\[주:(.+)\]/g, '{{*|$1}}'))
需在上述代码基础上运行。 DuckSoft留言2022年7月2日 (六) 22:07 (UTC)回复