Last active
September 15, 2018 04:29
-
-
Save bishtawi/5d287fbdc6426c89803f608361b27dce to your computer and use it in GitHub Desktop.
Hacky way to auto advance Udacity's classroom lecture videos
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
// ==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