Skip to content

Instantly share code, notes, and snippets.

@stq
Created June 9, 2022 15:21
Show Gist options
  • Save stq/25258f1db4f7ebcc2f2196e812e0adcd to your computer and use it in GitHub Desktop.
Save stq/25258f1db4f7ebcc2f2196e812e0adcd to your computer and use it in GitHub Desktop.
Ranobe.me download all books for pocketbook
function downloadFile(url) {
var loaded = $.Deferred();
var request = new XMLHttpRequest();
request.open('GET', url);
// ! setting the responseType has to be after the `request.open`
// `arraybuffer` is necessary for Internet Explorer and Edge becuase
// they do not support `blob` as response type
request.responseType = "arraybuffer";
request.onload = function() {
loaded.resolve();
var contentDisposition = this.getResponseHeader('content-disposition');
var contentType = this.getResponseHeader('content-type');
var filename = contentDisposition.match(/filename=(.+)/)[1];
var file = new Blob([this.response], { type: contentType });
// For Internet Explorer and Edge
if ('msSaveOrOpenBlob' in window.navigator) {
window.navigator.msSaveOrOpenBlob(file, filename);
}
// For Firefox and Chrome
else {
// Bind blob on disk to ObjectURL
var data = URL.createObjectURL(file);
var a = document.createElement("a");
a.style = "display: none";
a.href = data;
a.download = filename;
document.body.appendChild(a);
a.click();
// For Firefox
setTimeout(function(){
document.body.removeChild(a);
// Release resource on disk after triggering the download
window.URL.revokeObjectURL(data);
}, 100);
}
};
request.onloadend = function() { loaded.resolve(); };
request.send();
return loaded;
}
var i = 0;
function go() {
downloadFile("https://ranobe.me/section_fictofile_download.php?id=" + i + "&format=fb2");
if( i < 500 ) {
i++;
setTimeout(go, 10000);
}
}
go();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment