Day3 | 取模強轉
在JAVA中,為了防止相加的溢出,常對數(shù)進行取模(1e9+7),但在取模后需要強轉為int,不然會報錯。
如:
百度文庫 使用控制臺轉化doc文檔文字??
//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.創(chuàng)建下載鏈接,下載到本地
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);