-
-
Save bgerd/ee5404a962ac54ee3a01ecef3ebb2965 to your computer and use it in GitHub Desktop.
Download all classwork from a google classroom topic page
This file contains 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
/** | |
HOW TO USE | |
1. go to classwork topic page ( URL should look like https://classroom.google.com/w/(.*)/tc/(.*) ) | |
2. open developer console ( F12 or right click > inspect element > console in top) | |
3. copy and paste this code, assignments will be downloaded in 5 second intervals | |
NOTE: CHANGE auth_user IF NECESSARY | |
if you are signed in to multiple google accounts, you need to select whichever you use for classroom | |
(ie freeuni account). If that account is the default one, leave at 0. Otherwise, sign in to gmail with that account | |
and the number will be displayed in url bar (https://mail.google.com/mail/u/$number), enter that | |
NOTE files will be downloaded to default download location (~/Downloads) | |
move all zips/rars from there before launching the script, afterwards you can easily select | |
newly downloaded files and move elsewhere | |
*/ | |
const auth_user=0 | |
// these ids work on paradigms, methodologies | |
const downloadDiv = "maXJsd" | |
const INTERVAL = 5000 | |
function downloadAllClasswork() { | |
Array.from(document.getElementsByClassName(downloadDiv)) | |
.map(getCourseWorkLink) | |
.map(extractId) | |
.map(createDownloadLink) | |
.map(downloadAtInterval) | |
} | |
function getCourseWorkLink(elem) { | |
return elem.href | |
} | |
function extractId(driveUrl) { | |
const rx = /https:\/\/drive.google.com\/file\/d\/(.*)\/view\?usp=drive_web&authuser=?/ | |
const res = rx.exec(driveUrl) | |
return res[1] | |
} | |
// See: https://www.labnol.org/internet/direct-links-for-google-drive/28356/ | |
function createDownloadLink(id) { | |
return `https://drive.google.com/uc?authuser=${auth_user}&export=download&id=${id}` | |
} | |
// See: https://stackoverflow.com/questions/38364400/index-inside-map-function | |
function downloadAtInterval(url, index) { | |
setTimeout(function() { | |
console.log(`downloading file ${index}`) | |
window.open(url) | |
}, index*INTERVAL); | |
} | |
downloadAllClasswork() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment