Skip to content

Instantly share code, notes, and snippets.

@nervetattoo
Last active May 14, 2016 10:38
Show Gist options
  • Save nervetattoo/3bf0380ca7023b1b36ed to your computer and use it in GitHub Desktop.
Save nervetattoo/3bf0380ca7023b1b36ed to your computer and use it in GitHub Desktop.
its-karakterer
// ==UserScript==
// @name its-karakterpoeng
// @namespace http://your.homepage/
// @version 0.8
// @description enter something useful
// @author You
// @match http*://hfk.itslearning.com/*
// @grant unsafeWindow
// @run-at context-menu
// ==/UserScript==
var win = unsafeWindow;
var points = win.prompt('Hva er maks poeng på prøven?', 10);
function getPoint(percent) {
var dec = Number(percent.replace(',','.'));
return Math.round(dec * points) / 100;
}
var iframe = win.document.querySelector('iframe').contentDocument;
var tableRows = iframe.body.querySelectorAll('.nttinputtable tr');
var tableHead = tableRows[0];
var th = iframe.createElement('th');
th.innerHTML = 'Maks: ' + points;
tableHead.appendChild(th);
tableRows = Array.prototype.slice.call(tableRows, 1);
Array.prototype.forEach.call(tableRows, function(row) {
var t = row.querySelectorAll('td');
var html = getPoint(t[1].querySelector('input').value);
var td = iframe.createElement('td');
td.appendChild(iframe.createTextNode(html));
row.appendChild(td);
});
@nervetattoo
Copy link
Author

nervetattoo commented Sep 27, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment