Average Sime

Cyberpunk Coding

当前为 2022-11-04 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Average Sime
  3. // @namespace http://tampermonkey.net/
  4. // @version 2077v.2
  5. // @description Cyberpunk Coding
  6. // @author ezX
  7. // @match https://agenda.sime.md/ords/f?p=*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=sime.md
  9. // @require http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. /*
  14. _________ ___. __
  15. \_ ___ \___.__.\_ |__ _________________ __ __ ____ | | __
  16. / \ \< | | | __ \_/ __ \_ __ \____ \| | \/ \| |/ /
  17. \ \___\___ | | \_\ \ ___/| | \/ |_> > | / | \ <
  18. \______ / ____| |___ /\___ >__| | __/|____/|___| /__|_ \
  19. \/\/ \/ \/ |__| \/ \/
  20. _________ __
  21. / _____// |_ ____ ___________ ______
  22. \_____ \\ __\/ __ \_/ __ \_ __ \/ ___/
  23. / \| | \ ___/\ ___/| | \/\___ \
  24. /_______ /|__| \___ >\___ >__| /____ >
  25. \/ \/ \/ \/
  26. */
  27.  
  28. (function() {
  29. 'use strict';
  30.  
  31. function average(arr) {
  32. var finalstate = arr.reduce(
  33. function (state, a) {
  34. state.sum += a;
  35. state.count += 1;
  36. return state;
  37. },
  38. { sum: 0, count: 0 }
  39. );
  40. return finalstate.sum / finalstate.count;
  41. }([2, , , 6]);
  42.  
  43. function nextnote(arr, avg) {
  44. let nextn = Math.floor(avg);
  45. nextn++
  46.  
  47. let x = arr.slice();
  48. while (average(x) < nextn) {
  49. let i = nextn;
  50. while (i < 10) {
  51. i++
  52. x.push(i)
  53. if (average(x) < nextn) {
  54. if (i != 10) {
  55. x.splice(x.length--, 1);
  56. }
  57. } else {break}
  58. }
  59. }
  60. x.splice(0, arr.length);
  61. return x;
  62. }
  63.  
  64. function editnotelist(btnid) {
  65. let notes = document.querySelectorAll('tbody')[26].childNodes[btnid];
  66. if (parseInt($(notes).find('td')[2].innerHTML) >= 9) {
  67. return alert('Вам не поднять свою оценку');
  68. }
  69.  
  70. let note_arr;
  71.  
  72. try {
  73. let note = $(notes).find('td')[1];
  74. note = $(note).find('span');
  75. let both_notes = note[0].innerHTML+note[1].innerHTML;
  76. note_arr = both_notes.split(', ');
  77. } catch {
  78. note_arr = $(notes).find('td')[1].innerHTML.split(', ');
  79. }
  80.  
  81. let nn = nextnote(note_arr.map(Number), parseInt($(notes).find('td')[2].innerHTML));
  82. //return alert('Вам нужно: ' + nn);
  83.  
  84. let old_notes = $(notes).find('td')[1];
  85. let sp_old = document.createElement('span');
  86. sp_old.innerHTML = old_notes.innerHTML;
  87. $(old_notes).empty();
  88. old_notes.append(sp_old);
  89. let sp_new = document.createElement('span');
  90. sp_new.innerHTML = ', '+nn.join(', ');
  91. sp_new.style.color = 'red';
  92. old_notes.append(sp_new);
  93.  
  94.  
  95. let new_avgavg = note_arr.slice().map(Number);
  96. Array.prototype.push.apply(new_avgavg,nn);
  97. $(notes).find('td')[2].innerHTML = average(new_avgavg);
  98. $(notes).find('td')[2].style.color = 'red';
  99.  
  100. return;
  101. }
  102.  
  103. try {
  104. let avg_i = document.createElement('th');
  105. avg_i.className = 't-Report-colHead';
  106. avg_i.align = 'left';
  107. avg_i.innerHTML = 'Average';
  108.  
  109. let avg = document.querySelectorAll('tr')[72];
  110. $(avg).append(avg_i);
  111.  
  112. let lessons = document.querySelectorAll('tbody')[26].childNodes;
  113. let avgavg = [];
  114. let count = -1;
  115. for (let lesson of lessons) {
  116. count++
  117. if (lesson.nodeName == 'TR') {
  118. let childsec = $(lesson).children()[0];
  119. if ($(childsec).children()[0].innerHTML != 'Educație pentru societate' ) {
  120. let note = document.createElement('td');
  121. note.className = 't-Report-cell';
  122. let mathavg = parseInt(average($(lesson).children()[1].innerHTML.split(', ').map(Number)) * 100) / 100;
  123. if (mathavg) {
  124. note.innerHTML = mathavg;
  125. avgavg.push(note.innerHTML);
  126.  
  127.  
  128. $(lesson).append(note);
  129. let btnplus = document.createElement('a');
  130. btnplus.href='#';
  131. btnplus.innerHTML = '+';
  132. btnplus.className = 't-Report-cell';
  133. btnplus.id = 'EDITNLIST:' + count;
  134. btnplus.onclick = function() { editnotelist(btnplus.id.split(':')[1]);};
  135. $(lesson).append(btnplus);
  136. }
  137. }
  138. }
  139. }
  140.  
  141. let ntr = document.createElement('tr');
  142. let aa = document.createElement('td');
  143. aa.className='t-Report-cell';
  144. aa.style.cssText = 'color: skyblue; font-weight:bold;';
  145. aa.innerHTML='A/A';
  146. $(ntr).append(aa);
  147. $(ntr).append(document.createElement('td'));
  148. let ntd = document.createElement('td');
  149. ntd.className = 't-Report-cell';
  150. ntd.innerHTML = parseInt(average(avgavg.filter(f => f != 'NaN').map(Number)) * 100) / 100;
  151. $(ntr).append(ntd);
  152. $(document.querySelectorAll('tbody')[26]).append(ntr);
  153. } catch {}
  154. })();