Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save blewert/55add55b3fbccb668693d146e59933ca to your computer and use it in GitHub Desktop.

Select an option

Save blewert/55add55b3fbccb668693d146e59933ca to your computer and use it in GitHub Desktop.
(function() {
function GetAllSubmissionRows()
{
return Array.from(document.querySelectorAll(".submission-list-row"));
}
function GetStatus(row)
{
return row.querySelector(".status-header").innerText;
}
function GetStudent(row)
{
return row.querySelector("bdi").innerText;
}
function GetAllUnprocessed()
{
let subRows = GetAllSubmissionRows();
subRows= subRows.filter(x => GetStatus(x) != "Submitted");
return subRows;
}
function GetNextUnprocessed()
{
var unproc = GetAllUnprocessed();
if(unproc.length <= 0)
return null;
return unproc[0];
}
function GetCloseButton()
{
return document.querySelector("button[analytics-id='bb-close.course.grades.flexibleAttemptGrading.title']");
}
function GetSaveButton()
{
return document.querySelector(".buttons-2.equal-buttons.panel-footer-right > button.js-save");
}
function delay(ms)
{
return new Promise(res => setTimeout(res, ms));
}
async function ScrollToBottom()
{
let container = document.querySelector("#learningModulePanelContainerId");
if(!container)
return;
let iter = 0;
while(iter++ < 10)
{
container.scrollTop += 999;
await delay(250);
}
}
async function GetElement(fnToCall, iters=10, name="element")
{
let element = fnToCall();
let breakOutMain = true;
let innerIter = 0;
while (innerIter++ < iters)
{
element = fnToCall();
if (element)
{
console.log("Found " + name + " after " + innerIter + " tries");
breakOutMain = false;
break;
}
await delay(250);
}
return {
elem: element,
failed: breakOutMain
}
}
async function main()
{
var nextToProcess = null;
let iter = 0;
var allUnProc = GetAllUnprocessed();
console.log("%cThere are " + allUnProc.length + " students to process");
while(iter < 100)
{
console.log("Scrolling to bottom");
await ScrollToBottom();
var unproc = GetAllUnprocessed();
console.log(">> There are " + unproc.length + " left to process");
let nextToProcess = GetNextUnprocessed();
if(!nextToProcess)
break;
let student = GetStudent(nextToProcess);
console.log(">> Next to process is " + student);
console.group("Processing " + student);
nextToProcess.click();
let saveButton = await GetElement(GetSaveButton, 10, "save button");
if(saveButton.failed)
{
console.log("Couldn't find save button; breaking.");
break;
}
saveButton.elem.click();
console.log("Clicked save");
await delay(500);
let exitButton = await GetElement(GetCloseButton, 10, "close button");
if(exitButton.failed)
{
console.log("Couldn't find exit button; breaking.");
break;
}
await delay(1000);
let innerIter = 0;
while (innerIter++ <= 10)
{
if(!exitButton.elem)
break;
exitButton.elem.click();
await delay(500);
exitButton.elem = GetCloseButton();
if (exitButton.elem)
{
console.log("That didn't work, trying again");
continue;
}
}
if(innerIter >= 10)
{
console.log("Couldnt click exit button. stopping.");
break;
}
console.log("Clicked exit");
console.groupEnd();
await delay(500);
iter++;
}
console.groupEnd();
console.log("Finished processing");
}
main();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment