Skip to content

Instantly share code, notes, and snippets.

@ozencb
Created December 27, 2020 14:17
Show Gist options
  • Save ozencb/16e1f9ecee2394707304a4ffca0431fc to your computer and use it in GitHub Desktop.
Save ozencb/16e1f9ecee2394707304a4ffca0431fc to your computer and use it in GitHub Desktop.
// Mark every video as watched or unwatched on udemy.com
//
// 1. Go to a Udemy course
// 2. Open the Developer Console. (COMMAND+ALT+I on Mac)
// 3. Paste this into the Developer Console and run it
(() => {
const markWatched = false;
let toggleCount = 0;
const sleep = ({seconds}) =>
new Promise((proceed) => {
console.log(`Waiting for ${seconds} seconds...`);
setTimeout(proceed, seconds * 1000);
});
const toggleAll = async () => {
const $sectionHeadings = '[data-purpose$="section-heading"]';
const sectionHeadings = Array.from(document.querySelectorAll($sectionHeadings)).filter(section => section.getAttribute('aria-expanded') === 'false');
await Promise.all(
sectionHeadings.map(async heading => {
heading && heading.click()
await sleep({
seconds: 3
});
}
));
const toggleButtons = Array.from(document.querySelectorAll('[data-purpose$="progress-toggle-button"]')).filter(btn => btn.checked !== markWatched);
console.log(`Marking ${toggleButtons.length} courses as watched...`);
await Promise.all(
toggleButtons.map(async toggleButton => {
toggleButton && toggleButton.click() && toggleCount++;
}
));
};
toggleAll();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment