Skip to content

Instantly share code, notes, and snippets.

@adammw
Created November 4, 2015 14:08
Show Gist options
  • Save adammw/10a438f93d96e9ac31df to your computer and use it in GitHub Desktop.
Save adammw/10a438f93d96e9ac31df to your computer and use it in GitHub Desktop.
// Downloads unwatermarked invidiual pages of books from EBSCOhost
var data = /\/ebook\/(.+?)\?sid=(.+?)&/.exec(location.href);
$.getJSON(`/ehost/ebookViewer/DigitalObject/${data[1]}?sid=${data[2]}&vid=0&theFormat=EB`).then(function(json) {
var pages = json.pageData.map(function(page) {
return {
filename: `${json.title.replace(/\s/,'_')}_${page.id}`,
url: `${location.origin}/ehost/ebookviewer/artifact/${data[1]}/EB/${data[2]}/0/${page.artifactId}`
};
});
// this fails for >~ 40 pages due to too many simultaneous downloads
// consider logging the file urls and downloading separately
pages.forEach(function(page) {
var a = document.createElement('a');
a.download = page.filename;
a.href = page.url;
a.click();
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment