Skip to content

Instantly share code, notes, and snippets.

@SgtPooki
Last active June 7, 2019 18:45
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save SgtPooki/6d43d319246115f3b97935787741e610 to your computer and use it in GitHub Desktop.
Save SgtPooki/6d43d319246115f3b97935787741e610 to your computer and use it in GitHub Desktop.
Script to automatically download free ebooks listed on oreilly
/*
Just paste into your console.. or make a tampermonkey/greasemonkey script out of it.
Only tested in Chrome. Be careful.. three tabs are opened per book.
If a books image is not removed, you'll need to try to download that book yourself.
Use this script (enter into the console of your browser) on the following pages:
http://www.oreilly.com/programming/free/
http://www.oreilly.com/business/free/
http://www.oreilly.com/data/free/
http://www.oreilly.com/iot/free/
http://www.oreilly.com/security/free/
http://www.oreilly.com/web-platform/free/
http://www.oreilly.com/webops-perf/free/
*/
var jq = document.createElement('script');
jq.src = "https://code.jquery.com/jquery-latest.min.js";
jq.onload= function() {
var $downloadableBooks = $('a[href*="/free/"]').filter(function(i, el){
return $(el).find('img').length > 0;
});
var wgetList = '';
$downloadableBooks.each(function (i, el) {
var link = $(el).attr('href').split('?')[0];
if (link.indexOf('.csp') < 0) {
return;
}
$(el).remove();
link = link.split('.');
link.splice(-1,1);
$(['mobi', 'epub', 'pdf']).each(function(i2, format) {
var bookUrl = [].concat(link, format).join('.').replace('/free/', '/free/files/');
wgetList += 'wget ' + bookUrl + '\n';
window.open(bookUrl);
});
});
console.log(wgetList);
}
document.getElementsByTagName('head')[0].appendChild(jq);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment