Last active
September 28, 2020 20:00
-
-
Save csbrown/fabcdaeea378d12dabb805ebbd656601 to your computer and use it in GitHub Desktop.
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
// The addSections function takes in a JS object containing info about which sections to add to which students. | |
// it doesn't have any logic to check the current status of assigned sections, so if you run this multiple times, | |
// I'm not sure what will happen. | |
function findEl(cssSelector, innerHTML) { | |
return Array.prototype.filter.call( | |
document.querySelectorAll(cssSelector), | |
x => {return x.innerHTML.includes(innerHTML);} | |
); | |
} | |
function peopleRows() { | |
return Array.from(document.querySelectorAll('.rosterUser')); | |
} | |
function sleep(ms) { | |
return new Promise(resolve => setTimeout(resolve, ms)); | |
} | |
async function openSectionAdder(userID) { | |
findEl("td",userID)[0].parentNode.children[8].children[0].children[0].click(); | |
await sleep(2000); | |
findEl("td",userID)[0].parentNode.children[8].children[0].children[1].children[2].children[0].click(); | |
} | |
async function addSection(Section) { | |
document.querySelector('.browser').click(); | |
await sleep(5000); | |
try { | |
findEl("b",Section)[0].parentNode.parentNode.parentNode.click(); } | |
catch(e) {} | |
} | |
async function closeSectionAdder() { | |
document.querySelector("button.btn-primary").click(); | |
} | |
async function addSections(allSections) { | |
for (const user in allSections) { | |
await openSectionAdder(user); | |
await sleep(2000); | |
for (const section of allSections[user]) { | |
await addSection(section); | |
await sleep(2000); | |
} | |
await closeSectionAdder(); | |
await sleep(2000); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment