Skip to content

Instantly share code, notes, and snippets.

@Rplus
Created March 26, 2018 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rplus/6631d4f2fd96f9090173f3d6290b66c6 to your computer and use it in GitHub Desktop.
Save Rplus/6631d4f2fd96f9090173f3d6290b66c6 to your computer and use it in GitHub Desktop.
壞小孩撈卡提諾文章…
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