Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mrandri19/9378127f2596e5817dd3a4051719b992 to your computer and use it in GitHub Desktop.
Save mrandri19/9378127f2596e5817dd3a4051719b992 to your computer and use it in GitHub Desktop.
/* jshint esnext: true */
// ==UserScript==
// @name Registro Elettronico Spaggiari Enanched
// @namespace https://web.spaggiari.eu/
// @version 0.1
// @description New functions for the grade page.
// @author Andrea Cognolato
// @match https://web.spaggiari.eu/cvv/app/default/genitori_voti.php
// @grant none
// @require http://code.jquery.com/jquery-2.1.4.min.js
// ==/UserScript==
function grade_to_float(grade) {
let table = {
'10': 10,
'9/10': 9.75,
'9½': 9.5,
'9+': 9.25,
'9': 9,
'8/9': 8.75,
'8½': 8.5,
'8+': 8.25,
'8': 8,
'7/8': 7.75,
'7½': 7.5,
'7+': 7.25,
'7': 7,
'6/7': 6.75,
'6½': 6.5,
'6+': 6.25,
'6': 6,
'5/6': 5.75,
'5½': 5.5,
'5+': 5.25,
'5': 5,
'4/5': 4.75,
'4½': 4.5,
'4+': 4.25,
'4': 4,
'3/4': 3.75,
'3½': 3.5,
'3+': 3.25,
'3': 3,
'2/3': 2.75,
'2½': 2.5,
'2+': 2.25,
'2': 2
};
return table[grade];
}
function createElem(mean) {
let meanElement = document.createElement('td');
let style = 'vertical-align: middle;';
if (mean > 6) {
meanElement.style = (style + 'color: green;');
} else {
meanElement.style = (style + 'color: red;');
}
meanElement.textContent = mean.toPrecision(4);
meanElement.width = '350';
meanElement.classList.add('registro');
meanElement.classList.add('grautext');
meanElement.classList.add('open_sans_condensed_bold');
meanElement.classList.add('font_size_14');
meanElement.align = 'left';
return meanElement;
}
let grades = $('#data_table_2 tr').slice(4).map(function() {
return $(this).find('.q3').find('p').map(function() {
return $(this).text();
});
});
let table = $('#data_table_2 tr').slice(4);
// Foreach subject
for (let i = 0; i < grades.length; i++) {
// Get the grades for a subject
let subject = grades[i];
// Remove the empty ('') ones
let real_grades = subject.filter((i) => subject[i] !== '').toArray();
real_grades = real_grades.map(grade_to_float);
if (real_grades.length === 0) continue;
// Get the mean
let mean = real_grades.reduce((a, b) => a + b, 0) / real_grades.length;
// Add the element to the DOM
table[i].appendChild(createElem(mean));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment