Last active
April 25, 2018 18:28
-
-
Save dumbasPL/9fd8c8fd71551713ed71d1750d211fdc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name avregae calc | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description avregae calc | |
// @author dumbasPL | |
// @match *.eszkola.opolskie.pl/* | |
// @grant none | |
// ==/UserScript== | |
var table = document.getElementsByClassName('ocenyZwykle-table')[0]; | |
if(table){ | |
let totalIlosc = 0; | |
let totalSuma = 0; | |
for(var i = 1; i < table.rows.length; i++){ | |
let suma = 0; | |
let ilosc = 0; | |
var oceny = table.rows[i].getElementsByClassName('break-word')[0]; | |
if(oceny){ | |
var o = oceny.getElementsByTagName('span'); | |
if(o){ | |
for(var j = 0; j < o.length; j++){ | |
var xx = /[0-9]{1}[+-]{0,1}/g.exec(o[j].innerHTML); | |
if(xx && xx.length == 1){ | |
var ocena = parseFloat(eval(xx[0].replace("+", " + 0.33").replace("-", " - 0.33"))); | |
var alt = o[j].getAttribute('alt'); | |
var vv = /Waga: ([0-9]+,[0-9]+)/g.exec(alt); | |
var waga = parseFloat(vv[1].replace(",", ".")); | |
suma += parseFloat(ocena * waga); | |
ilosc += parseFloat(waga); | |
} | |
} | |
} | |
} | |
var span = document.createElement("span"); | |
span.style.color = "#f00"; | |
let value = Math.round((suma / ilosc)*100)/100; | |
span.innerHTML = "Średnia: " + value; | |
if(suma) table.rows[i].getElementsByClassName('break-word')[0].appendChild(span); | |
if(!isNaN(value)){ | |
totalIlosc++; | |
totalSuma += parseFloat(value); | |
} | |
} | |
let total = document.createElement("span"); | |
total.style.color = "#f00"; | |
let totalValue = Math.round((totalSuma / totalIlosc)*100)/100; | |
total.innerHTML = "Średnia wszystkiego: " + totalValue; | |
table.parentNode.appendChild(total); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment