Skip to content

Instantly share code, notes, and snippets.

@thrau
Created April 8, 2017 17:27
Show Gist options
  • Save thrau/6b6debe982148b9644473c019360fa47 to your computer and use it in GitHub Desktop.
Save thrau/6b6debe982148b9644473c019360fa47 to your computer and use it in GitHub Desktop.
TUWEL automatic grade item mapper
// ==UserScript==
// @name TUWEL automatic grade item mapper
// @namespace http://dsg.tuwien.ac.at/staff/trausch/
// @version 0.1
// @description Automatically selects the form fields in the grade item mapper where the item name corresponds to the column name
// @author Thomas Rausch
// @match https://tuwel.tuwien.ac.at/grade/import/*
// @grant none
// ==/UserScript==
function setMapping(fitem) {
var title = fitem.querySelector(".fitemtitle label").innerHTML.trim();
var select = fitem.querySelector("select");
for (var i = 0; i < select.options.length; i++) {
var option = select.options[i];
var columnName = option.innerHTML.trim();
if(title.toLowerCase() == columnName.toLowerCase()) {
option.selected = true;
return;
}
}
console.log("Couldn't find data column", title);
}
(function() {
'use strict';
console.log("TUWEL automatic grade item mapper working");
var fieldset = document.getElementById("id_general_map");
if(!fieldset) {
return;
}
var nodes = document.querySelectorAll("#id_general_map .fitem");
for (var i = 0; i < nodes.length; i++) {
setMapping(nodes[i]);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment