Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save GerardoNevarez/aadf97be85622d9e07fab55802cba657 to your computer and use it in GitHub Desktop.
Save GerardoNevarez/aadf97be85622d9e07fab55802cba657 to your computer and use it in GitHub Desktop.
Hacky way to auto advance Udacity's classroom lecture videos
// ==UserScript==
// @name Udacity Auto Advance
// @namespace https://omscs.gatech.edu/
// @description Auto advance Udacity's classroom lecture videos
// @date 2017.01.25
// @version 1.0.1
// @match https://classroom.udacity.com/*
// @run-at document-end
// @run_at document_end
// @grant none
// ==/UserScript==
const checkMe = link => {
if (link.innerText.trim().toLowerCase() === 'play next' &&
link.className.trim().toLowerCase().startsWith('_auto-advance-overlay--button--')) {
link.click()
}
}
const checkInsideMe = parent => {
const links = parent.getElementsByTagName('a')
for (let i = 0, length = links.length; i < length; i++) {
checkMe(links[i])
}
}
const observer = new MutationObserver(mutations => {
for (let i = 0, length = mutations.length; i < length; i++) {
if (mutations[i].target.nodeName === 'A') {
checkMe(mutations[i].target)
}
for (let j = 0, len = mutations[i].addedNodes.length; j < len; j++) {
switch (mutations[i].addedNodes[j].nodeName) {
case 'A':
checkMe(mutations[i].addedNodes[j])
break
case 'DIV':
checkInsideMe(mutations[i].addedNodes[j])
break
}
}
}
})
observer.observe(document, { childList: true, subtree: true })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment