Files
python/文档/百度文库下载脚本.txt

26 lines
747 B
Plaintext
Raw Permalink Normal View History

2025-08-30 18:35:01 +08:00
//1.获取文本
let topDiff = -1;
let content = "";
var filename= document.getElementsByClassName('doc-title')[0].innerText;
const target = document.querySelectorAll(".reader-word-layer");
target.forEach(x => {
if (x.style.top !== topDiff) {
content += "\n";
topDiff = x.style.top;
};
content += x.innerText;
});
//2.创建下载链接,下载到本地
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(content));
element.setAttribute('download', filename+".doc");
element.style.display = ".reader-word-layer";
document.body.appendChild(element);
element.click();
document.body.removeChild(element);