Greasy Fork 还支持 简体中文。

Average Sime

Adds to the website agenda.sime.md the function of calculating the average score | Cyberpunk Coding

  1. // ==UserScript==
  2. // @name Average Sime
  3. // @namespace https://github.com/ecXbe/cps
  4. // @version 2077v.4.2
  5. // @description Adds to the website agenda.sime.md the function of calculating the average score | 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. const $ = jQuery.noConflict(true);
  32.  
  33. function average(arr) {
  34. var finalstate = arr.reduce(
  35. function (state, a) {
  36. state.sum += a;
  37. state.count += 1;
  38. return state;
  39. },
  40. { sum: 0, count: 0 }
  41. );
  42. return finalstate.sum / finalstate.count;
  43. }([2, , , 6]);
  44.  
  45. function nextscore(arr, avg) {
  46. let nextn = Math.floor(avg);
  47. nextn++
  48.  
  49. let x = arr.slice();
  50. while (average(x) < nextn) {
  51. let i = nextn;
  52. while (i < 10) {
  53. i++
  54. x.push(i)
  55. if (average(x) < nextn) {
  56. if (i != 10) {
  57. x.splice(x.length--, 1);
  58. }
  59. } else {break}
  60. }
  61. }
  62. x.splice(0, arr.length);
  63. return x;
  64. }
  65.  
  66. function editscorelist(id) {
  67. let $scores = $table.find(`tbody tr:eq(${id})`).children().eq(-2).text();
  68. if (parseInt($scores) >= 9) return alert('Вам не поднять свою оценку')
  69.  
  70. let $arr_of_scores = $table.find(`tbody tr:eq(${id}) td:eq(1)`).contents().filter(function() {return this.nodeType === 3}).text().split(', ').map(Number);
  71. let $Need_scores = nextscore($arr_of_scores, parseInt($scores));
  72.  
  73. $table.find(`tbody tr:eq(${id}) td:eq(1)`).text($arr_of_scores.join(', ')).append(($('<span>', {style: 'color: red', text: `, ${$Need_scores.join(', ')}`})));
  74. $table.find(`tbody tr:eq(${id})`).children().eq(-2).text(average($table.find(`tbody tr:eq(${id}) td:eq(1)`).text().split(', ').map(Number))).css('color', 'red');
  75.  
  76. let $New_Average_of_averages = [];
  77. $table.find('tbody').children().filter(s => s.nodeType !== 1).each(function() {
  78. if ($(this).find('td:eq(0)').text() !== 'Educația fizică' && $(this).find('td:eq(0)').text() !== 'Educație pentru societate' && $(this).find('td:eq(0)').text() !== 'Dezvoltarea personală' && $(this).find('td:eq(0)').text() !== 'A/A') {$New_Average_of_averages.push(parseFloat(average($(this).find('td:eq(1)').text().split(', ').map(Number)).toFixed(2)))}
  79. });
  80.  
  81. $table.find('tbody tr:last').children().eq(-1).text(parseFloat(average($New_Average_of_averages.map(Number))).toFixed(2)).css('color', 'red');
  82. }
  83.  
  84. let currentDate = new Date();
  85. let semestrul = ''; if (currentDate.getMonth() >= 8 && currentDate.getMonth() <= 11) {semestrul = 'Semestrul I'} else {
  86. semestrul = 'Semestrul II';
  87.  
  88. $(`[summary="Semestrul I"]`).find('thead tr').append($('<th>', {'class': 't-Report-colHead', 'align': 'left', 'html': 'Average'}));
  89. let average_of_averages = [];
  90. $(`[summary="Semestrul I"]`).find('tbody').children().filter(s => s.nodeType !== 1).each(function() {
  91. if ($(this).find('td:eq(0)').text() !== 'Educație pentru societate') {let average_score = parseFloat(average($(this).find('td:eq(1)').text().split(', ').map(Number)).toFixed(2)); if (average_score) {average_of_averages.push(average_score); $(this).append( $('<td>', {class: 't-Report-cell', html: average_score}))}}
  92. });
  93.  
  94. let c_ch = $(`[summary="Semestrul I"]`).find('tbody tr:eq(0)').children().length - 2;
  95. console.log(c_ch)
  96. $(`[summary="Semestrul I"]`).find('tbody').append($('<tr>', {class: 'a-a_I'}).append($('<td>', {class: 't-Report-cell', headers: 'DISCIPLINA'}).append($('<span>', {style: 'color: skyblue; font-weight:bold;', text: 'A/A'}))));
  97.  
  98. for (let i = 0; i < c_ch; i++) {
  99. $('tr.a-a_I').append($('<td>'));
  100. }
  101.  
  102. $('tr.a-a_I').append($('<td>', {class: 't-Report-cell', text: parseFloat(average(average_of_averages)).toFixed(2)}))
  103. }
  104.  
  105. const $table = $(`[summary="${semestrul}"]`);
  106. let c_ch = $table.find('tbody tr:eq(0)').children().length - 1;
  107. $table.find('thead tr').append($('<th>', {'class': 't-Report-colHead', 'align': 'left', 'html': 'Average'}));
  108.  
  109. let average_of_averages = [];
  110. let count = -1
  111. $table.find('tbody').children().filter(s => s.nodeType !== 1).each(function() {
  112. count++
  113. if ($(this).find('td:eq(0)').text() !== 'Educație pentru societate') {let average_score = parseFloat(average($(this).find('td:eq(1)').text().split(', ').map(Number)).toFixed(2)); if (average_score) {average_of_averages.push(average_score); $(this).append( $('<td>', {class: 't-Report-cell', html: average_score})); let $PlusButton = $('<a>', {href: '#', id: count, text: '+'}); $(this).append($('<td>', {class: 't-Report-cell'}).append($PlusButton.click(function() {editscorelist($PlusButton.attr('id'))})))}}
  114. });
  115. $table.find('tbody').append($('<tr>', {class: 'a-a'}).append($('<td>', {class: 't-Report-cell', headers: 'DISCIPLINA'}).append($('<span>', {style: 'color: skyblue; font-weight:bold;', text: 'A/A'}))));
  116.  
  117. console.log(c_ch);
  118. for (let i = 0; i < c_ch; i++) {
  119. $('tr.a-a').append($('<td>'));
  120. }
  121.  
  122. $('tr.a-a').append($('<td>', {class: 't-Report-cell', text: parseFloat(average(average_of_averages)).toFixed(2)}))
  123. })();