Skip to content

Instantly share code, notes, and snippets.

@Detry322
Created October 19, 2017 20:08
Show Gist options
  • Save Detry322/8982aa154d1e3b2fb657d89447e4a5b4 to your computer and use it in GitHub Desktop.
Save Detry322/8982aa154d1e3b2fb657d89447e4a5b4 to your computer and use it in GitHub Desktop.
Add grade notes to LMOD
/**
* Fire an event handler to the specified node. Event handlers can detect that the event was fired programatically
* by testing for a 'synthetic=true' property on the event object
* @param {HTMLNode} node The node to fire the event handler on.
* @param {String} eventName The name of the event without the "on" (e.g., "focus")
*/
function fireEvent(node, eventName) {
// Make sure we use the ownerDocument from the provided node to avoid cross-window problems
var doc;
if (node.ownerDocument) {
doc = node.ownerDocument;
} else if (node.nodeType == 9){
// the node may be the document itself, nodeType 9 = DOCUMENT_NODE
doc = node;
} else {
throw new Error("Invalid node passed to fireEvent: " + node.id);
}
if (node.dispatchEvent) {
// Gecko-style approach (now the standard) takes more work
var eventClass = "";
// Different events have different event classes.
// If this switch statement can't map an eventName to an eventClass,
// the event firing is going to fail.
switch (eventName) {
case "click": // Dispatching of 'click' appears to not work correctly in Safari. Use 'mousedown' or 'mouseup' instead.
case "mousedown":
case "mouseup":
eventClass = "MouseEvents";
break;
case "focus":
case "change":
case "blur":
case "select":
eventClass = "HTMLEvents";
break;
default:
throw "fireEvent: Couldn't find an event class for event '" + eventName + "'.";
break;
}
var event = doc.createEvent(eventClass);
event.initEvent(eventName, true, true); // All events created as bubbling and cancelable.
event.synthetic = true; // allow detection of synthetic events
// The second parameter says go ahead with the default action
node.dispatchEvent(event, true);
} else if (node.fireEvent) {
// IE-old school style, you can drop this if you don't need to support IE8 and lower
var event = doc.createEventObject();
event.synthetic = true; // allow detection of synthetic events
node.fireEvent("on" + eventName, event);
}
};
$('.icon-caret-right').each(function(_, a) { a.click() })
$('a').filter(function(i, a) { return a.innerHTML == 'grade note' }).each(function(_, a) { a.click() })
$('.assignment-table tr td .col-lg-offset-1 div div textarea[tabindex=1]').each(function(index, a) { a.value = notes[index]; fireEvent(a, 'change') })
$('.assignment-table .button--primary').filter(function(_, a) { return a.innerHTML.indexOf('Save') != -1 }).each(function(i, a) { a.click() })

Here's the way to export grade notes

  1. Sort the spreadsheet so it has the same sort order as LMOD (aka alphabetical by last name)
  2. open up lmod and then open up the javascript console
  3. Scroll to the bottom of the assignment you want to grade so everyone loads
  4. Create a javascript array in the console with all the grade notes as strings, call this array notes. This should be the same length as the number of students in the table!
  5. Run the following snippets in order (each snippet may take a while to run - up to 20 seconds each)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment