Created
December 26, 2020 18:00
-
-
Save ozencb/ac7ed14ae87aac5ce49e5c2dd376b42c to your computer and use it in GitHub Desktop.
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
// Archive every course on udemy.com | |
// This script is pretty much a copy of: https://gist.github.com/JamieMason/7580315 | |
// | |
// 1. Go to https://www.udemy.com/home/my-courses/learning/ | |
// 2. Open the Developer Console. (COMMAND+ALT+I on Mac) | |
// 3. Paste this into the Developer Console and run it | |
(() => { | |
const $archiveButtons = '[data-purpose$="toggle-archived"]'; | |
const retry = { | |
count: 0, | |
limit: 3, | |
}; | |
const retryLimitReached = () => retry.count === retry.limit; | |
const addNewRetry = () => retry.count++; | |
const sleep = ({ seconds }) => | |
new Promise((proceed) => { | |
console.log(`Waiting for ${seconds} seconds...`); | |
setTimeout(proceed, seconds * 1000); | |
}); | |
const archiveAll = async (archiveButtons) => { | |
console.log(`Archiving ${archiveButtons.length} courses...`); | |
await Promise.all( | |
archiveButtons.map(async (archiveButton) => { | |
archiveButton && archiveButton.click(); | |
await sleep({ seconds: 1 }); | |
}) | |
); | |
}; | |
const nextBatch = async () => { | |
await sleep({ seconds: 2 }); | |
const archiveButtons = Array.from(document.querySelectorAll($archiveButtons)); | |
const archiveButtonsWereFound = archiveButtons.length > 0; | |
if (archiveButtonsWereFound) { | |
await archiveAll(archiveButtons); | |
await sleep({ seconds: 3 }); | |
return nextBatch(); | |
} else { | |
addNewRetry(); | |
} | |
if (retryLimitReached()) { | |
console.log(`No more courses left`); | |
} else { | |
await sleep({ seconds: 3 }); | |
return nextBatch(); | |
} | |
}; | |
nextBatch(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment