Created
May 14, 2015 08:00
-
-
Save GeorgeHahn/7ba9d7ed62ff816eea7d to your computer and use it in GitHub Desktop.
Download Slideshare slide sets for which saving has been disabled
This file contains hidden or 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
| // Browser must be ignoring CORS | |
| // Chrome: Disable web security | |
| // Firefox: Requires proxy or Cors Everywhere extension (https://github.com/spenibus/cors-everywhere-firefox-addon) | |
| function loadScript(url, callback) | |
| { | |
| // Adding the script tag to the head as suggested before | |
| var head = document.getElementsByTagName('head')[0]; | |
| var script = document.createElement('script'); | |
| script.type = 'text/javascript'; | |
| script.src = url; | |
| // Then bind the event to the callback function. | |
| // There are several events for cross browser compatibility. | |
| script.onreadystatechange = callback; | |
| script.onload = callback; | |
| // Fire the loading | |
| head.appendChild(script); | |
| } | |
| function downloadslide(zip, slides, number, cb) { | |
| var slide = slides[number]; | |
| var slideurl = slide.children[0]; | |
| if(slideurl.tagName.toLowerCase() !== "img") | |
| slideurl = slide.children[1]; | |
| slideurl = slideurl.getAttribute("data-full"); | |
| if(slideurl !== undefined && slideurl !== null) { | |
| JSZipUtils.getBinaryContent(slideurl, function(err, data) { | |
| if(err) { | |
| console.error("Slide download error: " + slideurl); | |
| } else { | |
| cb(data, number); | |
| } | |
| }); | |
| } | |
| } | |
| loadScript("https://raw.githubusercontent.com/Stuk/jszip/master/dist/jszip.min.js", function() { | |
| loadScript("https://raw.githubusercontent.com/eligrey/FileSaver.js/master/FileSaver.min.js", function() { | |
| loadScript("https://raw.githubusercontent.com/Stuk/jszip-utils/master/dist/jszip-utils.min.js", function() { | |
| var slides = document.getElementsByClassName("slide"); | |
| var zip = new JSZip(); | |
| var schedslide = function(i) { | |
| downloadslide(zip, slides, i, function(data, i) { | |
| console.log("Got slide " + i); | |
| zip.file("slide" + i + ".jpg", data, {binary:true}); | |
| if(i == slides.length - 1) { | |
| console.log("Saving zip"); | |
| var content = zip.generate({type : "blob"}); | |
| saveAs(content, document.title + ".zip"); | |
| } | |
| else | |
| schedslide(i + 1); | |
| }); | |
| } | |
| schedslide(0); | |
| }) | |
| }) | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment