NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name mashov avg // @namespace http://tampermonkey.net/ // @version 0.2 // @description try to take over the world! // @author amit sivan // @match https://hibbard.eu/tampermonkey-tutorial/ // @grant none // @license MIT // @include https://web.mashov.info* // @include https://web.mashov.info/students/#!/student/*/grades // @run-at document-idle // ==/UserScript== (function() { 'use strict'; function avgCalc(){ let a = document.querySelectorAll('strong[ng-if="((item.grade !== undefined) && (item.grade !== null)) || ((item.rangeGrade !== undefined) && (item.rangeGrade !== null))"].ng-scope'); let avg = 0; for (let i = 0; i < a.length; i += 2) { avg += parseInt(a[i].innerText); } /*var bod = document.getElementsByTagName("body")[0]; bod.innerHTML = "<h6>" + avg / (a.length / 2) + "</h6>" + bod.innerHTML;*/ return avg/(a.length/2); } function Check(str,arr) { for (let i = 0; i < arr.length; i++) { if (encodeURI(str) == encodeURI(arr[i].subject)) { return i; } } return -1 } function addButton() { if(document.getElementById("loader")!=null) { document.getElementById("loader").remove(); } var notificationButton = document.getElementsByTagName("mshv-notifications-bar")[0]; notificationButton.outerHTML = '<button id="avgButton" style="background-color: transparent; border: none; outline-style: none; cursor: pointer;">averages</button>' + notificationButton.outerHTML; document.getElementById("avgButton").addEventListener("click", function() { let a = document.querySelectorAll('strong[ng-if="((item.grade !== undefined) && (item.grade !== null)) || ((item.rangeGrade !== undefined) && (item.rangeGrade !== null))"].ng-scope'); let gradeList = []; let next = 0; for (let i = 0; i < a.length; i += 2) { gradeList[next] = parseInt(a[i].innerText); next++; } let subjectsData = document.querySelectorAll('strong[ng-bind-html="item.groupName"]'); let subjects = []; let temp; for (let i = 0; i < subjectsData.length; i++) { temp = Check(subjectsData[i].innerText, subjects); if (temp == -1) { subjects.push({ subject: subjectsData[i].innerText, length: 1, sum: gradeList[i] }) } else { subjects[temp].length++; subjects[temp].sum += gradeList[i]; } } //let gradeBody = document.querySelectorAll('md-list-item[ng-class="{ \'mshv-highlight\': vm.highlightGradingEventId == item.id }"]'); let gradeBody = document.querySelectorAll('md-list[ng-if="vm.data && vm.data.length > 0"]')[0]; let date = document.querySelectorAll('div.md-list-item-text.hide-xs.layout-fill.layout-padding.layout-row >div.text-right.flex > h4.ng-binding')[0].innerText; gradeBody.innerHTML = ""; for (let i = 0; i < subjects.length; i++) { gradeBody.innerHTML += `<md-list-item class="md-2-line md-no-proxy ng-scope _md md-ink-ripple" md-ink-ripple="" ng-repeat="item in vm.data | orderBy:vm.orderBy:vm.reverse" ng-class="{ 'mshv-highlight': vm.highlightGradingEventId == item.id }" role="listitem"> <div class="md-list-item-text hide-gt-xs layout-fill show-xs layout-row" layout="row" layout-fill="" hide-gt-xs="" show-xs=""> <div class="text-left flex-66" flex="66"> <h3 style="white-space: inherit;"><strong ng-bind-html="item.gradingEvent" class="ng-binding">הממוצע שלך הוא: </strong></h3> <h4 class="ng-binding">(הממוצע אינו שקול)</h4> </div> <div class="text-right flex-33" flex="33"> <h3 style="white-space: pre-line;"> <!-- ngIf: ((item.grade === undefined) || (item.grade === null)) && ((item.rangeGrade === undefined) || (item.rangeGrade === null)) && ((item.textualGrade === undefined) || (item.textualGrade === null)) --> <!-- ngIf: ((item.grade !== undefined) && (item.grade !== null)) || ((item.rangeGrade !== undefined) && (item.rangeGrade !== null)) --><strong ng-if="((item.grade !== undefined) && (item.grade !== null)) || ((item.rangeGrade !== undefined) && (item.rangeGrade !== null))" class="ng-binding ng-scope">${Math.round( (subjects[i].sum / subjects[i].length) * 10 ) / 10} </strong><!-- end ngIf: ((item.grade !== undefined) && (item.grade !== null)) || ((item.rangeGrade !== undefined) && (item.rangeGrade !== null)) --><!-- ngIf: (((item.grade !== undefined) && (item.grade !== null)) || ((item.rangeGrade !== undefined) && (item.rangeGrade !== null))) && (item.textualGrade !== undefined) && (item.textualGrade !== null) --><!-- ngIf: (item.textualGrade !== undefined) && (item.textualGrade !== null) --> </h3> <h4 class="ng-binding"></h4> </div> </div> <div class="md-list-item-text hide-xs layout-fill layout-padding layout-row" layout="row" layout-fill="" layout-padding="" hide-xs=""> <div class="text-left flex" flex=""> <h3 style="white-space: pre-line"><strong ng-bind-html="item.gradingEvent" class="ng-binding">הממוצע שלך הוא: </strong></h3> <h4 ng-bind-html="item.gradeType" class="ng-binding">(הממוצע אינו שקול)</h4> </div> <div class="text-left flex" flex=""> <h3 style="white-space: pre-line;"> <!-- ngIf: ((item.grade === undefined) || (item.grade === null)) && ((item.rangeGrade === undefined) || (item.rangeGrade === null)) && ((item.textualGrade === undefined) || (item.textualGrade === null) || (item.textualGrade === '')) --> <!-- ngIf: ((item.grade !== undefined) && (item.grade !== null)) || ((item.rangeGrade !== undefined) && (item.rangeGrade !== null)) --><strong ng-if="((item.grade !== undefined) && (item.grade !== null)) || ((item.rangeGrade !== undefined) && (item.rangeGrade !== null))" class="ng-binding ng-scope">${Math.round( (subjects[i].sum / subjects[i].length) * 10 ) / 10} </strong><!-- end ngIf: ((item.grade !== undefined) && (item.grade !== null)) || ((item.rangeGrade !== undefined) && (item.rangeGrade !== null)) --><!-- ngIf: (((item.grade !== undefined) && (item.grade !== null)) || ((item.rangeGrade !== undefined) && (item.rangeGrade !== null))) && (item.textualGrade !== undefined) && (item.textualGrade !== null) && (item.textualGrade !== '') --><!-- ngIf: (item.textualGrade !== undefined) && (item.textualGrade !== null) && (item.textualGrade !== '') --> </h3> </div> <div class="text-left flex" flex=""> <h4 class="ng-binding"><strong ng-bind-html="item.groupName" class="ng-binding">${subjects[i].subject}</strong></h4> </div> <div class="text-right flex" flex=""> <h4 class="ng-binding"></h4> </div> </div> <!-- ngIf: !$last --> <md-divider ng-if="!$last" class="ng-scope"></md-divider> <!-- end ngIf: !$last --> <div class="md-secondary-container"></div> <div class="md-ripple-container" style=""></div> </md-list-item>`; } document.getElementById("avgButton").remove(); let avg = 0; for(let i = 0;i< subjects.length;i++){ avg += subjects[i].sum / subjects[i].length; } avg /= subjects.length; addTotalAvg(Math.round(avg*100)/100); }); //document.querySelectorAll('li[ng-repeat="item in vm.menu"')[2].outerHTML += "<li ng-repeat=\"item in vm.menu\" ng-init=\"pIndex = $index\" ng-include=\"'components/mainmenu/mainmenuItem.template.html'\" class=\"ng-scope\"><!-- ngIf: item.heading --><!-- ngIf: !item.heading && !item.submenu && (!vm.isDevice || !item.onlyWeb) --><button class=\"md-button ng-scope md-ink-ripple\" type=\"button\" ng-transclude=\"\" ng-if=\"!item.heading && !item.submenu && (!vm.isDevice || !item.onlyWeb)\" ng-class=\"{ 'active' : vm.isActive(item) }\" ng-click=\"vm.goToItem(item)\" title=\"Regular Grades\" style=\"\"><div flex=\"\" layout=\"row\" class=\"ng-binding ng-scope layout-row flex\"><!-- ngIf: item.icon --><em ng-if=\"item.icon\" class=\"menu-icon fa fa-bar-chart\"></em><!-- end ngIf: item.icon --> ממוצעים <!-- ngIf: vm.isActive(item) --></div><div class=\"md-ripple-container\" style=\"\"></div></button><!-- end ngIf: !item.heading && !item.submenu && (!vm.isDevice || !item.onlyWeb) --><!-- ngIf: item.submenu --></li>"; /*'<li ng-repeat="item in vm.menu" ng-init="pIndex = $index" ng-include="'components/mainmenu/mainmenuItem.template.html'" class="ng-scope"><!-- ngIf: item.heading --><!-- ngIf: !item.heading && !item.submenu && (!vm.isDevice || !item.onlyWeb) --><button class="md-button ng-scope md-ink-ripple" type="button" ng-transclude="" ng-if="!item.heading && !item.submenu && (!vm.isDevice || !item.onlyWeb)" ng-class="{ 'active' : vm.isActive(item) }" ng-click="vm.goToItem(item)" title="Regular Grades" style=""><div flex="" layout="row" class="ng-binding ng-scope layout-row flex"><!-- ngIf: item.icon --><em ng-if="item.icon" class="menu-icon fa fa-bar-chart"></em><!-- end ngIf: item.icon --> ממוצעים <!-- ngIf: vm.isActive(item) --></div><div class="md-ripple-container" style=""></div></button><!-- end ngIf: !item.heading && !item.submenu && (!vm.isDevice || !item.onlyWeb) --><!-- ngIf: item.submenu --></li>'\*/ } function addTotalAvg(avg) { var topGrade = document.getElementsByTagName("md-list-item")[0]; topGrade.outerHTML = '<md-list-item><div style="font-size: 20px;margin: auto;font-weight: 700;margin-top: 7px;">Your average grade is: ' + avg + '</div><md-divider ng-if="!$last" class="ng-scope"></md-divider></md-list-item>' + topGrade.outerHTML; } setTimeout(function(){document.getElementsByTagName("head")[0].innerHTML = "<style>.loader { border: 4px solid #f3f3f3; border-radius: 50%; border-top: 4px solid #3498db; width: 35px; height: 35px; animation: spin 2s linear infinite;}@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); }}</style>" + document.getElementsByTagName("head")[0].innerHTML;}, 1); if(window.location.href.endsWith("grades")){setTimeout(addButton, 5000);} window.onhashchange = function() { let notificationButt = document.getElementsByTagName("mshv-notifications-bar")[0]; if(window.location.href.endsWith("grades")) { notificationButt.innerHTML = '<div class="loader" id="loader" style="display: -webkit-inline-box;"></div>' + notificationButt.innerHTML; setTimeout(addButton, 5000); } else { document.getElementById("avgButton").remove(); } } })();