跳至內容

讨论:倭使日記

頁面內容不支援其他語言。
新增話題
維基文庫,自由的圖書館
由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)回覆