Last active
June 11, 2020 23:07
-
-
Save DavidPu/fb48da860d868585228fa579e77f0302 to your computer and use it in GitHub Desktop.
download all class dojo media files.
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
| (function classdojo_scroll() { | |
| var page_scroll_delay = 5000; // ms | |
| var offset = 0; // localStorage.getItem('offset') || 0; | |
| console.log('inital offset:', offset); | |
| window.all_media_urls = new Map(); | |
| // return false if scroll to the end.. | |
| function scroll_down() { | |
| offset += 800; | |
| window.scroll(0, offset); | |
| console.log('offset:' + offset); | |
| localStorage.setItem('offset', offset); | |
| // return Math.abs(window.scrollY - offset) < 10; | |
| } | |
| // all_media_urls.forEach(function(e) {if (e.indexOf('.mp4') > 0) {console.log(e);}}) | |
| function download(url) { | |
| var ajax = new XMLHttpRequest(); | |
| ajax.open('GET', url, true); | |
| ajax.responseType = 'blob'; | |
| //ajax.setRequestHeader('referer', 'https://home.classdojo.com/'); | |
| //ajax.setRequestHeader('sec-fetch-dest', 'video'); | |
| //ajax.setRequestHeader('sec-fetch-mode', 'no-cors'); | |
| //ajax.setRequestHeader('sec-fetch-site', 'same-site'); | |
| ajax.onload = function (evt) { | |
| var f = url.split('/'); | |
| f = f[f.length-1]; | |
| var a = document.createElement('a'); | |
| a.href = URL.createObjectURL(evt.target.response); | |
| a.setAttribute('download', f); | |
| a.style.display = 'None'; | |
| a.addEventListener('click', function(e){ | |
| e.stopPropagation(); | |
| this.removeEventListener('click', arguments.callee); | |
| }); | |
| document.body.appendChild(a); | |
| a.click(); | |
| document.body.removeChild(a); | |
| }; | |
| ajax.send(); | |
| } | |
| function get_media_urls() { | |
| document.getElementsByTagName('div').forEach(function(e) { | |
| if (e.style.backgroundImage && e.style.backgroundImage.indexOf('url("') >= 0) { | |
| // console.log(e.style.backgroundImage); | |
| url = e.style.backgroundImage; | |
| url = url.split('"'); | |
| if (url.length > 1) { | |
| url = url[1].split('?')[0]; | |
| } | |
| if (url.toLowerCase().indexOf('.jpg') > 0) { | |
| if (! window.all_media_urls.has(url)) { | |
| window.all_media_urls.set(url, url); | |
| console.log(url); | |
| download(url); | |
| } | |
| } | |
| } | |
| }); | |
| document.getElementsByTagName('video').forEach(function(vid) { | |
| vid.children.forEach(function(e) { | |
| if (e.tagName.toLowerCase() == 'source' && e.src) { | |
| if (! window.all_media_urls.has(e.src)) { | |
| window.all_media_urls.set(e.src, e.src); | |
| console.log(e.src); | |
| download(e.src); | |
| } | |
| } | |
| }); | |
| }); | |
| } | |
| window.media_url_list = function() { | |
| var urls = []; | |
| window.all_media_urls.forEach(function(k){ urls.push(k);}); | |
| var a = document.createElement('a'); | |
| a.href = URL.createObjectURL(new Blob([urls.join('\n')], {type: "text/plain;charset=utf-8;"})); | |
| a.setAttribute('download', 'media_url_list.txt'); | |
| a.style.display = 'None'; | |
| a.addEventListener('click', function(e){ | |
| e.stopPropagation(); | |
| this.removeEventListener('click', arguments.callee); | |
| }); | |
| document.body.appendChild(a); | |
| a.click(); | |
| document.body.removeChild(a); | |
| } | |
| function click_pic() { | |
| var e = document.querySelector('.glyphicon-chevron-right'); | |
| var timeout = page_scroll_delay; | |
| var to_scroll = false; | |
| get_media_urls(); | |
| if (e) { | |
| e.click(); | |
| console.log("clicked!"); | |
| timeout = 1000; | |
| } else { | |
| //offset += 800; | |
| //window.scroll(0, offset); | |
| scroll_down(); | |
| } | |
| get_media_urls(); | |
| setTimeout(click_pic, timeout); | |
| } | |
| setTimeout(click_pic, page_scroll_delay); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment