-
Notifications
You must be signed in to change notification settings - Fork 0
/
honor-code.js
56 lines (47 loc) · 1.63 KB
/
honor-code.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copy paste this first into inspect element console.
/*
* Returns the the index of the rubric item to be selected. If the honor code
* is non-empty, FILLED is returned, else BLANK.
*/
function score() {
const FILLED = 0;
const BLANK = 1;
const textBox = document.querySelector("[id^='question_'] .form--textInput span");
const text = textBox.innerHTML;
const isBlank = text.search(/[^\s]/) != -1; // Look for anything other than whitespace.
return isBlank ? FILLED : BLANK;
}
// Run score() on console to see if it produces the correct grade.
// Next, copy paste this into the console.
/*
* Grades the current submission based on the return value of score().
*/
function grade() {
let scoredRubric = score();
let rubric = document.querySelectorAll('.rubricItem--key');
rubric[scoredRubric].click();
}
// Run grade() on console to see if the correct choice is selected.
// If it works, paste this input into the console to start the autograding
// procedure.
/*
* Starts the autograding by polling for changes in the href of the window.
* When it changes, we have successfully loaded the next submission, so we
* grade and then hit the "Next Ungraded" button again.
*/
{
let href = window.location.href;
let nextGraded = document.querySelector('[title="Shortcut: Z"]')
setInterval(() => {
/* Wait for updated URL. */
if (href != window.location.href) {
href = window.location.href;
/* Grade the submission. */
grade();
/* Go to next ungraded. */
nextGraded.click();
}
}, 50);
grade();
nextGraded.click();
}