Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.53 KB | None | 0 0
  1. // ==UserScript==
  2. // @name New Userscript
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description try to take over the world!
  6. // @author You
  7. // @match https://notes.iut-nantes.univ-nantes.fr/
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. class Note {
  15. constructor(htmlNote) {
  16. this.nom = parseFloat($(htmlNote.children()[2]).text());
  17. this.note = parseFloat($(htmlNote.children()[4]).text());
  18. let coeffString = $(htmlNote.children()[6]).text();
  19. this.coeff = parseFloat(coeffString.substr(1, coeffString.length-2));
  20.  
  21. if(isNaN(this.note) || isNaN(this.coeff)) {
  22. this.note = 0;
  23. this.coeff = 0;
  24. }
  25.  
  26. htmlNote.append('<td class="notesAdded"></td>');
  27. }
  28. }
  29.  
  30. class Module {
  31. constructor(htmlModule) {
  32. this.number = parseFloat($(htmlModule.children()[1]).text());
  33. this.name = $(htmlModule.children()[2]).text();
  34. this.coeff = parseFloat($(htmlModule.children()[6]).text());
  35. this.notes = [];
  36.  
  37. let nextRow = $(htmlModule);
  38. while(nextRow.next().length > 0 &&
  39. !$(nextRow.next()[0]).hasClass('notes_bulletin_row_mod')) {
  40. nextRow = nextRow.next();
  41. if(nextRow.hasClass('notes_bulletin_row_eval')) {
  42. this.notes.push(new Note(nextRow));
  43. }
  44. }
  45.  
  46. htmlModule.append(`<td class="notesAdded">${(this.notes.length > 0) ?
  47. (Math.round(this.getMoyenne()*100)/100) : 'N.A.'}</td>`);
  48. }
  49.  
  50. getMoyenne() {
  51. let notesSum = this.notes
  52. .reduce((sum, note) => sum+note.note*note.coeff, 0);
  53. let coeffSum = this.notes
  54. .map((note) => note.coeff)
  55. .reduce((sum, coeff) => sum+coeff, 0);
  56.  
  57. if(coeffSum === 0 || notesSum === 0) {
  58. return 0;
  59. } else {
  60. return notesSum / coeffSum;
  61. }
  62. }
  63. }
  64.  
  65. class UE {
  66. constructor(htmlUE) {
  67. this.numero = null;
  68. this.coeff = parseFloat($(htmlUE.children()[6]).text());
  69. this.modules = [];
  70.  
  71. let nextRow = $(htmlUE);
  72. while(nextRow.next().length > 0 &&
  73. !$(nextRow.next()[0]).hasClass('notes_bulletin_row_ue')) {
  74. nextRow = nextRow.next();
  75. if(nextRow.hasClass('notes_bulletin_row_mod')) {
  76. this.modules.push(new Module(nextRow));
  77. }
  78. }
  79.  
  80. htmlUE.append(`<td
  81. class="notesAdded">${Math.round(this.getMoyenne()*100)/100}</td>`);
  82. }
  83.  
  84. getMoyenne() {
  85. let moyennesSum = this.modules
  86. .reduce((sum, module) => {
  87. return sum+module.getMoyenne()*module.coeff;
  88. }, 0);
  89. let coeffSum = this.modules
  90. .filter((module) => module.getMoyenne() > 0)
  91. .map((module) => module.coeff)
  92. .reduce((sum, coeff) => sum+coeff, 0);
  93.  
  94. if(coeffSum === 0) {
  95. return 0;
  96. } else {
  97. return moyennesSum / coeffSum;
  98. }
  99. }
  100. }
  101.  
  102. class Tableau {
  103. constructor(htmlTable) {
  104. this.ues = [];
  105. this.moyenne = -1;
  106.  
  107. htmlTable.find('thead tr:first').append('<th class="notesAdded"></th>');
  108.  
  109. let body = htmlTable.find('tbody');
  110.  
  111. body.children().each((i, child) => {
  112. child = $(child);
  113. if(child.hasClass('notes_bulletin_row_ue')) {
  114. this.ues.push(new UE(child));
  115. }
  116. });
  117. }
  118.  
  119. getMoyenne() {
  120. let moyennesSum = this.ues
  121. .reduce((sum, ue) => sum+ue.getMoyenne()*ue.coeff, 0);
  122. let coeffSum = this.ues
  123. .map((ue) => ue.coeff)
  124. .reduce((sum, coeff) => sum+coeff, 0);
  125.  
  126. return moyennesSum / coeffSum;
  127. }
  128. }
  129.  
  130. let tab;
  131. function render() {
  132. $('.notesAdded').remove();
  133. tab = new Tableau($('table.notes_bulletin'));
  134. console.log(tab);
  135. $('table').before(`<span class="notesAdded"style="text-align: center;
  136. padding: 20px; border: 3px solid red; display: block; margin: 0 20px
  137. 20px;"><b>Moyenne générale:
  138. ${Math.round(tab.getMoyenne()*100)/100}</b></span>`);
  139. // alert('Votre moyenne est ' + Math.round(tab.getMoyenne()*100)/100);
  140. }
  141. render();
  142.  
  143. if($('table.notes_bulletin')) {
  144. render();
  145. } else {
  146. console.log('Le tableau de note n\'à pas été trouvé');
  147. }
  148.  
  149. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement