Skip to content

Instantly share code, notes, and snippets.

@CodeByAidan
Created October 18, 2022 18:33
Show Gist options
  • Save CodeByAidan/8e15460c74313738f3d4606dc0c0875e to your computer and use it in GitHub Desktop.
Save CodeByAidan/8e15460c74313738f3d4606dc0c0875e to your computer and use it in GitHub Desktop.
Search through assignments in Google Classroom and return as an alert in JavaScript.
function checkForActiveAssignment() {
var activeClass = document.evaluate(
"//div[@class='hrUpcomingAssignmentGroup']//..//..//..//div//div//div",
document,
null,
XPathResult.FIRST_ORDERED_NODE_TYPE,
null
).singleNodeValue;
// i.e.
// activeClass = (class name, i.e. "AP Physics 1")
// check if <div class="hrUpcomingAssignmentGroup"> is active
// if it is, send a notification
// if it is not, do nothing
var activeAssignment = document.evaluate(
"//div[@class='hrUpcomingAssignmentGroup']",
document,
null,
XPathResult.FIRST_ORDERED_NODE_TYPE,
null
).singleNodeValue;
// i.e.
// activeAssignment = (homework name, i.e. "Packet pages 21 & 22")
// find the class that activeAssignment was found in
// if it is found, send a notification
// if it is not found, do nothing
var dueDate = document.evaluate(
"*//div[@class='hrUpcomingAssignmentGroup']//..//h2",
document,
null,
XPathResult.FIRST_ORDERED_NODE_TYPE,
null
).singleNodeValue;
// i.e.
// dueDate = Due Tomorrow
// check if there is another class a.k.a. another node
// if there is, send another notification
// if there is not, do nothing
// Find each & traverse using href
//
if (activeClass != null && activeAssignment != null && dueDate != null) {
// there is an active class
// send a notification
alert(
"Assignment found! \n" +
"\n" +
dueDate.innerText +
"\n" +
activeAssignment.innerText +
"\n" +
activeClass.innerText
);
// check if there is another assignment
// if there is, send another notification
// if there is not, do nothing
}
}
checkForActiveAssignment();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment