Created
March 26, 2018 17:28
-
-
Save Rplus/6631d4f2fd96f9090173f3d6290b66c6 to your computer and use it in GitHub Desktop.
壞小孩撈卡提諾文章…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let getUrl = (page) => `https://ck101.com/forum.php?mod=viewthread&tid=1762239&extra=&page=${page}`; | |
let toTxt = (d) => d.text(); | |
let hr = '\n\n=====\n\n'; | |
let getContent = (html) => { | |
let doc = document.implementation.createHTMLDocument(); | |
doc.body.innerHTML = html; | |
return [...doc.querySelectorAll('.t_f')].map(i => i.textContent).join(hr); | |
}; | |
let save = (page, text) => { | |
console.log(`save page ${page}`); | |
localStorage.setItem(`page-${page}`, text); | |
}; | |
let pages = new Array(48).fill(1).map((i, index) => index + 1); | |
pages.forEach(index => { | |
setTimeout(() => { | |
fetch(getUrl(index)) | |
.then(toTxt) | |
.then(getContent) | |
.then(d => save(index, d)); | |
}, index * 500); | |
}); | |
/// | |
/// | |
let allContents = pages.map(i => localStorage.getItem(`page-${i}`)).join(hr); | |
let file = new window.Blob([allContents], {type: 'text/plain'}); | |
let downloadLink = document.createElement('a'); | |
downloadLink.href = window.URL.createObjectURL(file); | |
downloadLink.innerHTML = `Download t.txt`; | |
downloadLink.onclick = () => { | |
downloadLink.download = `t.txt`; | |
}; | |
document.body.appendChild(downloadLink); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment