Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name New Userscript
- // @namespace http://tampermonkey.net/
- // @version 0.1
- // @description try to take over the world!
- // @author You
- // @match https://notes.iut-nantes.univ-nantes.fr/
- // @grant none
- // ==/UserScript==
- (function() {
- 'use strict';
- class Note {
- constructor(htmlNote) {
- this.nom = parseFloat($(htmlNote.children()[2]).text());
- this.note = parseFloat($(htmlNote.children()[4]).text());
- let coeffString = $(htmlNote.children()[6]).text();
- this.coeff = parseFloat(coeffString.substr(1, coeffString.length-2));
- if(isNaN(this.note) || isNaN(this.coeff)) {
- this.note = 0;
- this.coeff = 0;
- }
- htmlNote.append('<td class="notesAdded"></td>');
- }
- }
- class Module {
- constructor(htmlModule) {
- this.number = parseFloat($(htmlModule.children()[1]).text());
- this.name = $(htmlModule.children()[2]).text();
- this.coeff = parseFloat($(htmlModule.children()[6]).text());
- this.notes = [];
- let nextRow = $(htmlModule);
- while(nextRow.next().length > 0 &&
- !$(nextRow.next()[0]).hasClass('notes_bulletin_row_mod')) {
- nextRow = nextRow.next();
- if(nextRow.hasClass('notes_bulletin_row_eval')) {
- this.notes.push(new Note(nextRow));
- }
- }
- htmlModule.append(`<td class="notesAdded">${(this.notes.length > 0) ?
- (Math.round(this.getMoyenne()*100)/100) : 'N.A.'}</td>`);
- }
- getMoyenne() {
- let notesSum = this.notes
- .reduce((sum, note) => sum+note.note*note.coeff, 0);
- let coeffSum = this.notes
- .map((note) => note.coeff)
- .reduce((sum, coeff) => sum+coeff, 0);
- if(coeffSum === 0 || notesSum === 0) {
- return 0;
- } else {
- return notesSum / coeffSum;
- }
- }
- }
- class UE {
- constructor(htmlUE) {
- this.numero = null;
- this.coeff = parseFloat($(htmlUE.children()[6]).text());
- this.modules = [];
- let nextRow = $(htmlUE);
- while(nextRow.next().length > 0 &&
- !$(nextRow.next()[0]).hasClass('notes_bulletin_row_ue')) {
- nextRow = nextRow.next();
- if(nextRow.hasClass('notes_bulletin_row_mod')) {
- this.modules.push(new Module(nextRow));
- }
- }
- htmlUE.append(`<td
- class="notesAdded">${Math.round(this.getMoyenne()*100)/100}</td>`);
- }
- getMoyenne() {
- let moyennesSum = this.modules
- .reduce((sum, module) => {
- return sum+module.getMoyenne()*module.coeff;
- }, 0);
- let coeffSum = this.modules
- .filter((module) => module.getMoyenne() > 0)
- .map((module) => module.coeff)
- .reduce((sum, coeff) => sum+coeff, 0);
- if(coeffSum === 0) {
- return 0;
- } else {
- return moyennesSum / coeffSum;
- }
- }
- }
- class Tableau {
- constructor(htmlTable) {
- this.ues = [];
- this.moyenne = -1;
- htmlTable.find('thead tr:first').append('<th class="notesAdded"></th>');
- let body = htmlTable.find('tbody');
- body.children().each((i, child) => {
- child = $(child);
- if(child.hasClass('notes_bulletin_row_ue')) {
- this.ues.push(new UE(child));
- }
- });
- }
- getMoyenne() {
- let moyennesSum = this.ues
- .reduce((sum, ue) => sum+ue.getMoyenne()*ue.coeff, 0);
- let coeffSum = this.ues
- .map((ue) => ue.coeff)
- .reduce((sum, coeff) => sum+coeff, 0);
- return moyennesSum / coeffSum;
- }
- }
- let tab;
- function render() {
- $('.notesAdded').remove();
- tab = new Tableau($('table.notes_bulletin'));
- console.log(tab);
- $('table').before(`<span class="notesAdded"style="text-align: center;
- padding: 20px; border: 3px solid red; display: block; margin: 0 20px
- 20px;"><b>Moyenne générale:
- ${Math.round(tab.getMoyenne()*100)/100}</b></span>`);
- // alert('Votre moyenne est ' + Math.round(tab.getMoyenne()*100)/100);
- }
- render();
- if($('table.notes_bulletin')) {
- render();
- } else {
- console.log('Le tableau de note n\'à pas été trouvé');
- }
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement