NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript==
// @name WhatIf?
// @namespace imtony@protonmail.com
// @version 0.6
// @description Co się stanie jeżeli dostanę jakąś ocenę?
// @author Antoni Siek
// @match https://dziennik.oswiatawradomiu.pl/przegladaj_oceny/uczen
// @match https://dziennik.librus.pl/przegladaj_oceny/uczen
// @match https://synergia.librus.pl/przegladaj_oceny/uczen
// @updateURL https://openuserjs.org/meta/ImToNy/WhatIf.meta.js
// @downloadURL https://openuserjs.org/install/ImToNy/WhatIf.user.js
// @require https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js
// @require https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js
// @grant GM_setValue
// @grant GM_getValue
// ==/UserScript==
(function() {
'use strict';
function start() {
$("h3:contains('Oceny bieżące')").append("<br><br><span style='color:red'>WhatIf? v" + GM_info.script.version + " by Antoni Siek</span>");
var blocked = $("img[title='Podgląd średniej ocen został wyłączony przez administratora szkoły.']").length;
$("tr.line1,tr.line0").has("td.micro").not("tr.bolded").each(function() {
$('td:eq(2),td:eq(6)', this).append("<span class='grade-box whatif' title='What if?'>?</span>");
if(blocked) {
$('td:eq(3)', this).text($('td:eq(2)', this).getGrades());
$('td:eq(7)', this).text($('td:eq(6)', this).getGrades());
}
});
$('.whatif').css({
"background-color": "#c4c4c4",
"cursor": "pointer"
});
$('.whatif').click(function() {
var grade = prompt("Proszę podać ocenę:") || 0;
if(grade < 1 || grade > 6) {
alert("Zła ocena! Powinno być: 1-6, podano: " + grade);
return;
}
var weight = prompt("Proszę podać wagę oceny:") || 0;
if(weight < 1) {
alert("Zła waga! Powinno być >1, podano: " + weight);
return;
}
var toPush = {};
toPush[grade] = [weight];
var grades = $(this).closest('td').getGrades(toPush);
if(!grades) {
alert('Niestety, ale wygląda na to, że w systemie twojej szkoły wyłączone są wagi ocen lub wybrałeś przedmiot w którym wszystkie oceny nie posiadają wag.');
} else {
alert("Twoja średnia wynosiłaby: " + grades);
}
});
}
Array.prototype.clean = function() {
for (var i = 0; i < this.length; i++) {
if (this[i] === "") {
this.splice(i, 1);
i--;
}
}
return this;
};
jQuery.fn.getGrades = function(toAdd=false) {
var somethinghave = false,
parent = $(this[0]),
current = {
1:[],
2:[],
3:[],
4:[],
5:[],
6:[],
};
if(toAdd) {
$.each(toAdd, function(element, index) {
$.each(index, function(parent, grade) {
current[element].push(grade);
});
});
}
parent.find('.grade-box:not(.whatif)>a').each(function() {
var grade = $(this);
var title = grade.attr('title').split(/<br>|<br\/>/gi).clean();
var data = {};
for (var i = 0; i < title.length; i++) {
var split = title[i].split(': ');
data[split[0].trim()] = split[1].trim();
}
if(typeof data.Waga == 'undefined') {
return;
}
var exact,
imported = grade.text(), trimmed = grade.text().replace(/\D+/g, '');
if(imported.indexOf("+") !== -1) {
exact = trimmed + 0.25;
} else if (imported.indexOf("-") !== -1) {
exact = trimmed - 0.15;
} else {
exact = trimmed;
}
somethinghave = true;
var weight = data.Waga;
current[exact].push(weight);
});
if(!somethinghave) {
return false;
} else {
var upper = 0, lower = 0;
var formattedList = {};
$.each(current, function(grade, value) {
$.each(value, function(i, weight) {
if (typeof formattedList[weight] !== 'undefined') {
formattedList[weight].push(grade);
} else {
formattedList[weight] = [grade];
}
});
});
$.each(formattedList, function(key, value) {
var sum = 0;
if(value.length < 1) {
return;
}
$.each(value, function(i, number) {
sum += Number(number);
});
upper += sum * key;
lower += value.length * key;
});
var average = upper / lower;
return Math.round(average * 100) / 100;
}
};
$(start());
})();