-
-
Save rcz0001/b753455ee9f73d68c4629ec97cb11178 to your computer and use it in GitHub Desktop.
Schoology userscript to analyze grades
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Schoology grade analyzer | |
// @namespace http://tesd.net | |
// @version 0.2.7 | |
// @author Mihir Dhamankar <[email protected]> | |
// @license MIT | |
// @icon https://i.imgur.com/jN8uZGF.jpg | |
// @match *://app.schoology.com/* | |
// @match *://schoology.tesd.net/* | |
// @grant none | |
// @homepage https://gist.github.com/Mdkar/579b95041969c0753d4d421ebbc95311 | |
// @downloadURL https://gist.github.com/Mdkar/579b95041969c0753d4d421ebbc95311/raw/f40465bbbefbbb303ed31b8ec2ade6f376b3b816/Schoology%2520grade%2520analyzer.user.js | |
// @noframes | |
// @require https://unpkg.com/[email protected]/es5.js | |
// @require https://cdnjs.cloudflare.com/ajax/libs/canvasjs/1.7.0/canvasjs.min.js | |
// ==/UserScript== | |
//install a userscript manager on your browser and click the RAW button on this page to install this script | |
;(function() { | |
// lets try not to kill schoology: 10 per 5s | |
var limiter = new Bottleneck({ | |
reservoir: 10, | |
reservoirRefreshAmount: 100, | |
reservoirRefreshInterval: 5 * 1000 | |
}); | |
var courses = []; | |
var tempCourses = []; | |
class Course { | |
constructor(name, mpItems) { | |
this.name = name; | |
this.mpItems = mpItems; | |
this.mpNames = []; | |
this.mpGrades = []; | |
var mpNum = 0; | |
for (var i = 0; i < mpItems.length; i++) { | |
this.mpNames[i] = mpItems[i].name; | |
this.mpGrades[i] = mpItems[i].getGrade(); | |
} | |
var examIndex = Math.min(4, mpItems.length); | |
this.mpNames[examIndex] = "Midterm/Final Exam average"; | |
this.mpGrades[examIndex] = null; | |
this.grade = this.getGrade(); | |
this.mpCurrent = 0; | |
for (var i = this.mpGrades.length - 1; i >= 0; i--) { | |
if (this.mpGrades[i] === null) | |
this.mpCurrent = i - 1; | |
else break; | |
} | |
this.level = "X"; | |
} | |
getGrade() { | |
var mpNum = 0; | |
var grade0 = 0; | |
for (var i = 0; i < this.mpGrades.length; i++) { | |
if (this.mpGrades[i] !== null) { | |
grade0 += this.mpGrades[i]; | |
mpNum++; | |
} | |
} | |
return grade0 / mpNum; | |
} | |
getUnweighted() { | |
var rounded = Math.round(this.grade); | |
if (rounded >= 90) | |
return 4.0; | |
if (rounded >= 80) | |
return 3.0; | |
if (rounded >= 70) | |
return 2.0; | |
if (rounded >= 65) | |
return 1.0; | |
return 0; | |
} | |
getWeighted() { | |
var gpa = 0; | |
if (this.grade >= 65) { | |
if (this.grade >= 94) { | |
if (this.grade >= 95) { | |
if (this.grade >= 98) | |
gpa = 4.0; | |
else gpa = 3.95 + (this.grade - 95) * 0.05 / 3; | |
} | |
else gpa = 3.9 + (this.grade - 94) * 0.05; | |
} | |
else gpa = 1.0 + (this.grade - 65) * 0.1; | |
} | |
else gpa = 0; | |
switch (this.level) { | |
case "AP": | |
gpa += 1.3; | |
break; | |
case "H": | |
gpa += 1.0; | |
break; | |
case "X": | |
gpa += 0.5; | |
break; | |
} | |
return gpa; | |
} | |
} | |
class MPGrade { | |
constructor(name, labels, weights, points, totals) { | |
this.name = name; | |
this.labels = labels; | |
this.weights = weights; | |
this.points = []; | |
this.totals = []; | |
this.active = false; | |
for (var i = 0; i < points.length; i++) { | |
this.points[i] = 0; | |
this.totals[i] = 0; | |
if (points[i].length > 0) | |
this.active = true; | |
for (var j = 0; j < points[i].length; j++) { | |
this.points[i] += points[i][j]; | |
this.totals[i] += totals[i][j]; | |
} | |
} | |
} | |
getGrade() { | |
if (this.weights[0] === 0) { | |
var points0 = 0; | |
var totals0 = 0; | |
for (var i = 0; i < this.labels.length; i++) { | |
points0 += this.points[i]; | |
totals0 += this.totals[i]; | |
} | |
if (totals0 === 0) return null; | |
return 100 * points0 / totals0; | |
} | |
else { | |
var grade0 = 0; | |
var sumWeights = 1; | |
for (var i = 0; i < this.labels.length; i++) { | |
if (this.totals[i] === 0) sumWeights -= this.weights[i]; | |
else grade0 += this.weights[i] * this.points[i] / this.totals[i]; | |
} | |
if (sumWeights === 0) return null; | |
return 100 * grade0 / sumWeights; | |
} | |
} | |
addAssignment(category, p, t) { | |
this.points[category] += p; | |
this.totals[category] += t; | |
} | |
} | |
function getCourses(){ | |
var tempCourses = []; | |
var eleCourseLbl = $(".gradebook-course-title a"); | |
var grades = $(".gradebook-course-grades"); | |
for(var i = 0; i < eleCourseLbl.length; i++) { | |
var rows = $(grades[i]).find(".report-row"); | |
var mpLabels = []; | |
var mpPoints = []; | |
var mpTotals = []; | |
var mpIndex = -1; | |
var categories = []; | |
var catIndex = -1; | |
var weights = []; | |
for (var j = 0; j < rows.length; j++) { | |
var item = $(rows[j]); | |
if (item.hasClass("period-row")) { | |
mpIndex++; | |
mpPoints[mpIndex] = []; | |
mpTotals[mpIndex] = []; | |
catIndex = -1; | |
mpLabels.push($(item.find(".title")[0]).text()); | |
} | |
else if (item.hasClass("category-row")) { | |
catIndex++; | |
mpPoints[mpIndex][catIndex] = []; | |
mpTotals[mpIndex][catIndex] = []; | |
if (mpIndex === 0) { | |
var catName = $(item.find(".title")[0]).text(); | |
categories.push(catName.substring(0, catName.length - 8)); | |
var weight0 = item.find(".percentage-contrib"); | |
if (weight0.length > 0) { | |
var weight1 = $(weight0[0]).text(); | |
var weight2 = weight1.substring(1, weight1.length - 2); | |
weights.push(parseFloat(weight2) / 100); | |
} | |
else weights.push(0); | |
} | |
} | |
else if (item.hasClass("item-row")) { | |
var total0 = item.find(".max-grade"); | |
if (total0.length > 0) { | |
var points0 = item.find(".rounded-grade"); | |
if (points0.length === 0) | |
points0 = item.find(".rubric-grade-value"); | |
var points3 = parseFloat($(points0[0]).text()); | |
var total1 = $(total0[0]).text(); | |
var total3 = parseFloat(total1.substring(3)); | |
mpPoints[mpIndex][catIndex].push(points3); | |
mpTotals[mpIndex][catIndex].push(total3); | |
} | |
} | |
} | |
var mpGrades = []; | |
for (var j = 0; j < mpLabels.length; j++) | |
mpGrades.push(new MPGrade(mpLabels[j], categories, weights, mpPoints[j], mpTotals[j])); | |
var name = $(eleCourseLbl[i]).text(); | |
name = name.substring(0, name.length - 6); | |
var course = new Course(name, mpGrades); | |
tempCourses[i] = course; | |
} | |
return tempCourses; | |
} | |
var menuExtended = false; | |
function toggleMenu() { | |
if (menuExtended) | |
$("#assistMenu").css("right", "-250px"); | |
else $("#assistMenu").css("right", "0px"); | |
menuExtended = !menuExtended; | |
} | |
function addCourse(i0) { | |
var course = tempCourses[i0]; | |
if (courses.includes(course)) { | |
var index = courses.indexOf(course); | |
courses.splice(index, index + 1); | |
$("#assistCourseAddButton" + i0).text("Add"); | |
} | |
else { | |
courses.push(course); | |
course.level = $("#assistLevelSelector" + i0).val(); | |
$("#assistCourseAddButton" + i0).text("Remove"); | |
} | |
} | |
var wrapperStyle = { | |
"position": "absolute", | |
"left": "30px", | |
"top": "0px", | |
"width": "250px", | |
"height": "400px", | |
"background-color": "#f2f2f2" | |
}; | |
var titleStyle = { | |
"position": "absolute", | |
"left": "0px", | |
"top": "0px", | |
"width": "250px", | |
"height": "30px", | |
"background-color": "#005193", | |
"text-align": "center", | |
"font-size": "20px", | |
"color": "white" | |
}; | |
var contentStyle = { | |
"position": "absolute", | |
"left": "0px", | |
"top": "30px", | |
"width": "250px", | |
"height": "370px", | |
"overflow-y": "scroll" | |
}; | |
var subtitleStyle = { | |
"width": "100%", | |
"margin-top": "10px", | |
"margin-bottom": "10px", | |
"text-align": "center", | |
"font-size": "15px", | |
"color": "black" | |
}; | |
var buttonStyle0 = { | |
"width": "92%", | |
"height": "30px", | |
"margin-left": "4%", | |
"margin-right": "4%", | |
"margin-top": "10px", | |
"margin-bottom": "10px", | |
"background-color": "#007fe8", | |
"cursor": "pointer", | |
"text-align": "center", | |
"font-size": "20px", | |
"color": "white" | |
}; | |
var addButtonStyle = { | |
"float": "right", | |
"height": "25px", | |
"margin-right": "4%", | |
"cursor": "pointer", | |
"text-align": "right", | |
"font-size": "15px", | |
"color": "#007fe8" | |
}; | |
var addedAssignments = 0; | |
function addAssignment(i0, i1) { | |
var points = parseFloat($("#assistAssignmentCreatePoints").val()); | |
var total = parseFloat($("#assistAssignmentCreateTotal").val()); | |
if (!isNaN(points) && !isNaN(total)) { | |
var course = courses[i0]; | |
var mp = course.mpItems[course.mpCurrent]; | |
var category = parseInt($("#assistAssignmentCategory").val()); | |
mp.addAssignment(category, points, total); | |
course.mpGrades[i1] = mp.getGrade(); | |
$("#assistMPGradeInput" + i1).val(course.mpGrades[i1].toFixed(3)); | |
if (addedAssignments === 0) { | |
$("#assistAssignmentView").css("margin-bottom", "10px"); | |
var addedAssignmentsLine = { | |
"type": "hr", | |
"id": "assistAddedAssignmentsLine" | |
}; | |
appendJSON(addedAssignmentsLine, "assistAssignmentView"); | |
var addedAssignmentsLabel = { | |
"type": "div", | |
"id": "assistAddedAssignmentsLabel", | |
"text": "Added assignments", | |
"style": {}, | |
"styleClasses": [subtitleStyle] | |
}; | |
appendJSON(addedAssignmentsLabel, "assistAssignmentView"); | |
} | |
addedAssignments++; | |
var addedAssignmentEntry = { | |
"type": "div", | |
"id": "assistAddedAssignmentEntry" + addedAssignments, | |
"text": mp.labels[category], | |
"children": [] | |
}; | |
addedAssignmentEntry.style = { | |
"width": "92%", | |
"margin-left": "4%", | |
"margin-right": "4%", | |
"height": "20px", | |
"text-align": "left", | |
"font-size": "12px", | |
"color": "black" | |
}; | |
var addedAssignmentEntryGrade = { | |
"type": "span", | |
"id": "assistAddedAssignmentEntryGrade" + addedAssignments, | |
"text": points + " / " + total | |
}; | |
addedAssignmentEntryGrade.style = { | |
"float": "right", | |
"font-size": "12px", | |
"color": "black" | |
}; | |
addedAssignmentEntry.children.push(addedAssignmentEntryGrade); | |
appendJSON(addedAssignmentEntry, "assistAssignmentView"); | |
} | |
} | |
function updateCourse(i0) { | |
var course = courses[i0]; | |
for (var i = 0; i < course.mpGrades.length; i++) { | |
if (i >= course.mpCurrent) { | |
var grade = parseFloat($("#assistMPGradeInput" + i).val()); | |
if (!isNaN(grade)) | |
course.mpGrades[i] = grade; | |
} | |
} | |
course.grade = course.getGrade(); | |
var gpa = 0; | |
for (var i = 0; i < courses.length; i++) | |
gpa += courses[i].getWeighted(); | |
gpa /= courses.length; | |
addedAssignments = 0; | |
$("#assistCourseContent").remove(); | |
$("#assistMainTitle").text("Weighted GPA: " + gpa.toFixed(3)); | |
} | |
function editCourse(i0) { | |
var course = courses[i0]; | |
var content = { | |
"type": "div", | |
"id": "assistCourseContent", | |
"style": {"background-color": "#f2f2f2"}, | |
"styleClasses": [contentStyle], | |
"children": [] | |
}; | |
var nameStr = "(AP)"; | |
if (course.level === "H") nameStr = "(Honors)"; | |
else if (course.level === "X") nameStr = "(Accelerated)"; | |
else if (course.level === "A") nameStr = "(Academic)"; | |
var subtitle0 = { | |
"type": "div", | |
"id": "assistCourseSubtitle", | |
"text": course.name + " " + nameStr, | |
"style": {}, | |
"styleClasses": [subtitleStyle] | |
}; | |
content.children.push(subtitle0); | |
var mpBoxStyle = { | |
"width": "100%", | |
"height": "55px", | |
"overflow": "hidden", | |
"margin-top": "10px", | |
"margin-bottom": "10px", | |
"background-color": "#e0e0e0" | |
}; | |
var mpTitleStyle = { | |
"width": "92%", | |
"height": "25px", | |
"margin-left": "4%", | |
"margin-right": "4%", | |
"overflow": "hidden", | |
"text-align": "left", | |
"font-size": "15px", | |
"color": "black" | |
}; | |
var mpGradeStyle = { | |
"width": "92%", | |
"height": "35px", | |
"margin-left": "4%", | |
"margin-right": "4%", | |
"overflow": "hidden", | |
"text-align": "right", | |
"font-size": "15px", | |
"color": "#565656" | |
}; | |
var mpGradeInputStyle = { | |
"vertical-align": "middle", | |
"width": "60px", | |
"height": "20px", | |
"margin": "0px", | |
"padding": "0px", | |
"background": "none", | |
"border-top": "none", | |
"border-left": "none", | |
"border-right": "none", | |
"border-bottom": "solid 2px #007fe8", | |
"text-align": "center", | |
"font-size": "15px", | |
"color": "#565656" | |
}; | |
for (var i = 0; i < course.mpGrades.length; i++) { | |
var mpBox = { | |
"type": "div", | |
"id": "assistMPBox" + i, | |
"style": {}, | |
"styleClasses": [mpBoxStyle], | |
"children": [] | |
}; | |
content.children.push(mpBox); | |
var mpTitle = { | |
"type": "div", | |
"id": "assistMPTitle" + i, | |
"text": course.mpNames[i], | |
"style": {}, | |
"styleClasses": [mpTitleStyle] | |
}; | |
mpBox.children.push(mpTitle); | |
var mpGrade = { | |
"type": "div", | |
"id": "assistMPGrade" + i, | |
"text": "Grade: ", | |
"style": {}, | |
"styleClasses": [mpGradeStyle], | |
"children": [] | |
}; | |
mpBox.children.push(mpGrade); | |
if (i < course.mpCurrent) | |
mpGrade.text = "Grade: " + course.mpGrades[i].toFixed(3) + "%"; | |
else { | |
var mpGradeInput = { | |
"type": "input", | |
"noClosingTag": true, | |
"id": "assistMPGradeInput" + i, | |
"attributes": {"type": "text", "value": ""}, | |
"style": {}, | |
"styleClasses": [mpGradeInputStyle], | |
"children": [] | |
}; | |
if (course.mpGrades[i] !== null) | |
mpGradeInput.attributes.value = course.mpGrades[i].toFixed(3); | |
mpGrade.children.push(mpGradeInput); | |
mpGrade.afterText = "%"; | |
if (i === course.mpCurrent) { | |
mpBox.style.height = "auto"; | |
mpBox.style["padding-bottom"] = "10px"; | |
var assignmentView = { | |
"type": "div", | |
"id": "assistAssignmentView", | |
"children": [] | |
}; | |
assignmentView.style = { | |
"width": "100%" | |
}; | |
mpBox.children.push(assignmentView); | |
var createAssignmentLine = { | |
"type": "hr", | |
"id": "assistCreateAssignmentLine" | |
}; | |
mpBox.children.push(createAssignmentLine); | |
var createAssignmentLabel = { | |
"type": "div", | |
"id": "assistCreateAssignmentLabel", | |
"text": "New assignment", | |
"style": {}, | |
"styleClasses": [subtitleStyle] | |
}; | |
mpBox.children.push(createAssignmentLabel); | |
var assignmentCreateStyle = { | |
"height": "35px", | |
"margin-left": "4%", | |
"text-align": "left", | |
"font-size": "15px", | |
"color": "black" | |
}; | |
var assignmentCreate0 = { | |
"type": "div", | |
"id": "assistAssignmentCreate0", | |
"text": "Category: ", | |
"style": {}, | |
"styleClasses": [assignmentCreateStyle], | |
"children": [] | |
}; | |
mpBox.children.push(assignmentCreate0); | |
var assignmentCategory = { | |
"type": "select", | |
"id": "assistAssignmentCategory", | |
"style": {}, | |
"children": [] | |
}; | |
assignmentCategory.style = { | |
"vertical-align": "middle", | |
"width": "120px", | |
"height": "20px", | |
"margin": "0px", | |
"padding": "0px", | |
"font-size": "10px" | |
}; | |
assignmentCreate0.children.push(assignmentCategory); | |
var catLabels = course.mpItems[0].labels; | |
for (var j = 0; j < catLabels.length; j++) { | |
var catOption = { | |
"type": "option", | |
"id": "assistAssigmentCategoryOption" + j, | |
"attributes": {"value": j}, | |
"text": catLabels[j] | |
}; | |
assignmentCategory.children.push(catOption); | |
} | |
var assignmentCreate1 = { | |
"type": "span", | |
"id": "assistAssignmentCreate1", | |
"text": "Grade: ", | |
"style": {}, | |
"styleClasses": [assignmentCreateStyle], | |
"children": [] | |
}; | |
mpBox.children.push(assignmentCreate1); | |
var assignmentCreatePoints = { | |
"type": "input", | |
"noClosingTag": true, | |
"id": "assistAssignmentCreatePoints", | |
"attributes": {"type": "text", "value": "", "Placeholder": "points"}, | |
"style": {"width": "50px"}, | |
"styleClasses": [mpGradeInputStyle], | |
"children": [] | |
}; | |
assignmentCreate1.children.push(assignmentCreatePoints); | |
var assignmentCreateBackslash = { | |
"type": "span", | |
"id": "assistAssignmentCreateBackslash", | |
"text": " / " | |
}; | |
assignmentCreateBackslash.style = { | |
"font-size": "15px", | |
"color": "black" | |
}; | |
assignmentCreate1.children.push(assignmentCreateBackslash); | |
var assignmentCreateTotal = { | |
"type": "input", | |
"noClosingTag": true, | |
"id": "assistAssignmentCreateTotal", | |
"attributes": {"type": "text", "value": "", "Placeholder": "total"}, | |
"style": {"width": "50px"}, | |
"styleClasses": [mpGradeInputStyle], | |
"children": [] | |
}; | |
assignmentCreate1.children.push(assignmentCreateTotal); | |
var assignmentAddButton = { | |
"type": "span", | |
"id": "assistAssignmentAddButton", | |
"onclick": addAssignment, | |
"onclickParams": [i0, i], | |
"text": "Add", | |
"style": {}, | |
"styleClasses": [addButtonStyle] | |
}; | |
mpBox.children.push(assignmentAddButton); | |
} | |
} | |
} | |
var updateCourseButton = { | |
"type": "div", | |
"id": "assistUpdateCourse", | |
"onclick": updateCourse, | |
"onclickParams": [i0], | |
"text": "Update", | |
"style": {}, | |
"styleClasses": [buttonStyle0] | |
}; | |
content.children.push(updateCourseButton); | |
appendJSON(content, "assistMainWrapper"); | |
} | |
function createMainOnclick() { | |
for (var i = 0; i < tempCourses.length; i++) | |
tempCourses[i].level = $("#assistLevelSelector" + i).val(); | |
if (courses.length > 0) { | |
var courseLabels = {}; | |
for (var i = 0; i < courses.length; i++) | |
courseLabels[courses[i].name] = courses[i].level; | |
// window.localStorage.setItem("GPAssistCourses", courseLabels); | |
$("#assistSetupWrapper").remove(); | |
var wrapper = createMain(); | |
appendJSON(wrapper, "assistMenu"); | |
} | |
} | |
function createMain() { | |
var gpa = 0; | |
for (var i = 0; i < courses.length; i++) | |
gpa += courses[i].getWeighted(); | |
gpa /= courses.length; | |
var wrapper = { | |
"type": "div", | |
"id": "assistMainWrapper", | |
"style": {}, | |
"styleClasses": [wrapperStyle], | |
"children": [] | |
}; | |
var title = { | |
"type": "div", | |
"id": "assistMainTitle", | |
"text": "Weighted GPA: " + gpa.toFixed(3), | |
"style": {}, | |
"styleClasses": [titleStyle] | |
}; | |
wrapper.children.push(title); | |
var content = { | |
"type": "div", | |
"id": "assistMainContent", | |
"style": {}, | |
"styleClasses": [contentStyle], | |
"children": [] | |
}; | |
wrapper.children.push(content); | |
var subtitle0 = { | |
"type": "div", | |
"id": "assistCoursesSubtitle", | |
"text": "Courses", | |
"style": {}, | |
"styleClasses": [subtitleStyle] | |
}; | |
content.children.push(subtitle0); | |
var courseBoxStyle = { | |
"width": "100%", | |
"height": "25px", | |
"overflow": "hidden", | |
"margin-top": "10px", | |
"margin-bottom": "10px", | |
"background-color": "#e0e0e0", | |
"cursor": "pointer" | |
}; | |
var courseTitleStyle = { | |
"width": "92%", | |
"height": "25px", | |
"margin-left": "4%", | |
"margin-right": "4%", | |
"overflow": "hidden", | |
"text-align": "left", | |
"font-size": "15px", | |
"color": "black" | |
}; | |
for (var i = 0; i < courses.length; i++) { | |
var courseBox = { | |
"type": "div", | |
"id": "assistCourseBox" + i, | |
"onclick": editCourse, | |
"onclickParams": [i], | |
"style": {}, | |
"styleClasses": [courseBoxStyle], | |
"children": [] | |
}; | |
content.children.push(courseBox); | |
var courseTitle = { | |
"type": "div", | |
"id": "assistCourseTitle" + i, | |
"text": courses[i].name, | |
"style": {}, | |
"styleClasses": [courseTitleStyle] | |
}; | |
courseBox.children.push(courseTitle); | |
} | |
return wrapper; | |
} | |
function createMenu() { | |
var menu = { | |
"type": "div", | |
"id": "assistMenu", | |
"children": [] | |
}; | |
menu.style = { | |
"position": "fixed", | |
"right": "-250px", | |
"top": "100px", | |
"width": "280px", | |
"height": "400px", | |
"overflow": "hidden", | |
"background-color": "white", | |
"border-radius": "30px 0px 0px 30px", | |
"border-left": "solid 1px #007fe8", | |
"border-top": "solid 1px #007fe8", | |
"border-bottom": "solid 1px #007fe8" | |
}; | |
var tab = { | |
"type": "div", | |
"id": "assistTab", | |
"onclick": toggleMenu, | |
"text": "GPAssist" | |
}; | |
tab.style = { | |
"position": "absolute", | |
"left": "-185px", | |
"top": "185px", | |
"width": "400px", | |
"height": "30px", | |
"transform": "rotate(270deg)", | |
"cursor": "pointer", | |
"text-align": "center", | |
"font-size": "20px", | |
"color": "#007fe8" | |
}; | |
menu.children.push(tab); | |
var courseLabels = window.localStorage.getItem("GPAssistCourses"); | |
tempCourses = getCourses(); | |
if (courseLabels === null) { | |
var wrapper = { | |
"type": "div", | |
"id": "assistSetupWrapper", | |
"style": {}, | |
"styleClasses": [wrapperStyle], | |
"children": [] | |
}; | |
menu.children.push(wrapper); | |
var title = { | |
"type": "div", | |
"id": "assistSetupTitle", | |
"text": "Add core courses", | |
"style": {}, | |
"styleClasses": [titleStyle] | |
}; | |
wrapper.children.push(title); | |
var content = { | |
"type": "div", | |
"id": "assistSetupContent", | |
"style": {}, | |
"styleClasses": [contentStyle], | |
"children": [] | |
}; | |
wrapper.children.push(content); | |
var courseBoxStyle = { | |
"width": "100%", | |
"height": "50px", | |
"overflow": "hidden", | |
"margin-top": "10px", | |
"margin-bottom": "10px", | |
"background-color": "#e0e0e0" | |
}; | |
var courseTitleStyle = { | |
"width": "92%", | |
"height": "25px", | |
"margin-left": "4%", | |
"margin-right": "4%", | |
"overflow": "hidden", | |
"text-align": "left", | |
"font-size": "15px", | |
"color": "black" | |
}; | |
var courseLevelStyle = { | |
"float": "left", | |
"width": "56%", | |
"height": "25px", | |
"margin-left": "4%", | |
"text-align": "left", | |
"font-size": "15px", | |
"color": "#565656" | |
}; | |
var levelSelectorStyle = { | |
"height": "20px", | |
"margin": "0px", | |
"padding": "0px", | |
"font-size": "10px" | |
}; | |
for (var i = 0; i < tempCourses.length; i++) { | |
var courseBox = { | |
"type": "div", | |
"id": "assistCourseBox" + i, | |
"style": {}, | |
"styleClasses": [courseBoxStyle], | |
"children": [] | |
}; | |
content.children.push(courseBox); | |
var courseTitle = { | |
"type": "div", | |
"id": "assistCourseTitle" + i, | |
"text": tempCourses[i].name, | |
"style": {}, | |
"styleClasses": [courseTitleStyle] | |
}; | |
courseBox.children.push(courseTitle); | |
var courseLevel = { | |
"type": "span", | |
"id": "assistCourseLevel" + i, | |
"text": "Level: ", | |
"style": {}, | |
"styleClasses": [courseLevelStyle], | |
"children": [] | |
}; | |
courseBox.children.push(courseLevel); | |
var levelSelector = { | |
"type": "select", | |
"id": "assistLevelSelector" + i, | |
"style": {}, | |
"styleClasses": [levelSelectorStyle], | |
"children": [] | |
}; | |
courseLevel.children.push(levelSelector); | |
var levelAP = { | |
"type": "option", | |
"id": "assistLevelAP" + i, | |
"attributes": {"value": "AP"}, | |
"text": "AP" | |
}; | |
levelSelector.children.push(levelAP); | |
var levelH = { | |
"type": "option", | |
"id": "assistLevelH" + i, | |
"attributes": {"value": "H"}, | |
"text": "H" | |
}; | |
levelSelector.children.push(levelH); | |
var levelX = { | |
"type": "option", | |
"id": "assistLevelX" + i, | |
"attributes": {"value": "X"}, | |
"text": "X" | |
}; | |
levelSelector.children.push(levelX); | |
var levelA = { | |
"type": "option", | |
"id": "assistLevelA" + i, | |
"attributes": {"value": "A"}, | |
"text": "A" | |
}; | |
levelSelector.children.push(levelA); | |
var courseAddButton = { | |
"type": "span", | |
"id": "assistCourseAddButton" + i, | |
"onclick": addCourse, | |
"onclickParams": [i], | |
"text": "Add", | |
"style": {}, | |
"styleClasses": [addButtonStyle] | |
}; | |
courseBox.children.push(courseAddButton); | |
} | |
var setupDone = { | |
"type": "div", | |
"id": "assistSetupDone", | |
"onclick": createMainOnclick, | |
"text": "Continue", | |
"style": {}, | |
"styleClasses": [buttonStyle0] | |
}; | |
content.children.push(setupDone); | |
} | |
else { | |
for (var i = 0; i < tempCourses.length; i++) { | |
var course = tempCourses[i]; | |
if (courseLabels[course.name] !== undefined) { | |
course.level = courseLabels[course.name]; | |
courses.push(tempCourses[i]); | |
} | |
var wrapper = createMain(); | |
menu.children.push(wrapper); | |
} | |
} | |
appendJSON(menu, "body"); | |
} | |
if (window.location.pathname.indexOf("grades/grades") === 1) | |
createMenu(); | |
function appendJSON(elem, parent) { | |
var type = elem.type; | |
var id = elem.id; | |
var attr = ""; | |
if (elem.attributes !== undefined) { | |
for (var key in elem.attributes) { | |
var value = elem.attributes[key]; | |
attr += " " + key + "=\"" + value + "\""; | |
} | |
} | |
if (elem.style !== undefined) { | |
var style0 = {}; | |
if (elem.styleClasses !== undefined) { | |
for (var i = 0; i < elem.styleClasses.length; i++) | |
Object.assign(style0, elem.styleClasses[i]); | |
} | |
Object.assign(style0, elem.style); | |
var style1 = []; | |
for (var key in style0) { | |
var value = style0[key]; | |
style1.push(key + ": " + value + "; "); | |
} | |
var style = ""; | |
for (var i = 0; i < style1.length; i++) { | |
style += style1[i]; | |
if (i < style1.length - 1) | |
style += " "; | |
} | |
attr += " style=\"" + style + "\""; | |
} | |
var text = ""; | |
if (elem.text !== undefined) | |
text = elem.text; | |
if (elem.noClosingTag === undefined) | |
$("#" + parent).append("<" + type + " id=\"" + id + "\"" + attr + ">" + text + "</" + type + ">"); | |
else $("#" + parent).append("<" + type + " id=\"" + id + "\"" + attr + ">"); | |
if (elem.children !== undefined) { | |
for (var i = 0; i < elem.children.length; i++) | |
appendJSON(elem.children[i], id); | |
} | |
if (elem.afterText !== undefined) | |
$("#" + id).append(elem.afterText); | |
if (elem.onclick !== undefined) { | |
if (elem.onclickParams !== undefined) | |
document.getElementById(id).addEventListener("click", function() {elem.onclick(...elem.onclickParams);}, false); | |
else document.getElementById(id).addEventListener("click", elem.onclick, false); | |
} | |
} | |
//injectCSS(); | |
//if (window.location.pathname.indexOf("grades")!=-1){ | |
// if (window.location.pathname.indexOf("student_grades")!=-1){//grade page in course | |
// injectAnalyze();//creates button | |
// var MPgrades = new Array;//Average of each MP | |
// var MPlabels = new Array;//Names of MPs | |
// var MPcats = new Array();//2D array of averages in each category in each MP (MPcats[0][1] is average grade of 2nd category (e.g. 98 in Lab Reports) in 1st MP | |
// var MPcatLabels = new Array();//2D array of names of categories in each MP (MPcatLabels[0][1] is name of 2nd category in 1st MP (e.g. Lab Reports) | |
// populateMPArrays();//uses lots of jQuery to parse the grades page | |
// | |
// | |
// } else { //all grades page | |
// alert("Disclaimer: the extension you are using is not official and operates on the limited information provided by your browser. The GPA calculated by this extension is just an estimate and does not reflect your actual GPA. Use at your own risk.");//better safe than sorry | |
// var courseLbl = new Array();//Names of courses | |
// var courseAverages = new Array();//Average so far in each course | |
// populateCourseArrays();//uses more jQuery | |
// var unweighted; | |
// var weighted; | |
// calculateGPA(); | |
// injectGPA();//TODO | |
// } | |
//} | |
// | |
//function noop() {} | |
// | |
//function injectCSS() { | |
// $("head").append("<style type=\"text/css\">.grade-analyzer-style:hover { text-decoration: underline; cursor: pointer; }</style>"); | |
// console.log("CSS injected"); | |
//} | |
// | |
//function populateMPArrays(){ | |
// var MPlist = $(".period-row .rounded-grade"); | |
// for(var i = 0; i<MPlist.length; i++){ | |
// var MPid = $(".period-row:not(.grades-processed)").attr("data-id"); | |
// var catEls = $('[data-parent-id='+ MPid + '] .rounded-grade'); | |
// var catElsL = $('[data-parent-id='+ MPid + '] .title') | |
// var temp = new Array(); | |
// var tempL = new Array(); | |
// for(var j = 0; j < catEls.length; j++){ | |
// temp.push(parseFloat(catEls[j].title,10)); | |
// var k = catElsL[j].innerText.indexOf("Category"); | |
// tempL.push(catElsL[j].innerText.substring(0,k)); | |
// } | |
// MPcats.push(temp); | |
// MPcatLabels.push(tempL); | |
// $(".period-row:not(.grades-processed)").first().addClass("grades-processed"); | |
// MPgrades.push(parseFloat(MPlist[i].title,10)); | |
// if(i<4) | |
// MPlabels.push("MP " + (i+1)); | |
// else | |
// MPlabels.push("NGP"); | |
// } | |
//} | |
// | |
//function populateCourseArrays(){ | |
// var eleCourseLbl = $(".gradebook-course-title a"); | |
// for(var i = 0; i < eleCourseLbl.length; i++){ | |
// var MPgrades = new Array(); | |
// var courseID = $(".gradebook-course")[i].id.substring(22); | |
// var MPgradeEls = $('[data-parent-id='+ courseID + '] .rounded-grade'); | |
// for(var j = 0; j < MPgradeEls.length; j++){ | |
// MPgrades.push(parseFloat(MPgradeEls[j].title,10)); | |
// } | |
// var sum = 0; | |
// for(var j = 0; j < MPgrades.length; j++) | |
// sum += MPgrades[j]; | |
// courseAverages.push(sum/MPgrades.length); | |
// var k = eleCourseLbl[i].innerText.indexOf("Course"); | |
// courseLbl.push(eleCourseLbl[i].innerText.substring(0,k-1)); | |
// } | |
//} | |
// | |
//function calculateGPA(){ | |
// var coreGrd = new Array(); | |
// var coreLbl = new Array(); | |
// var coreSum = 0; | |
// for(var i = 0; i < courseLbl.length; i++){ | |
// if(courseLbl[i].indexOf("Sec")==-1){ | |
// coreGrd.push(courseAverages[i]); | |
// coreSum+=courseAverages[i]; | |
// coreLbl.push(courseLbl[i]); | |
// } | |
// } | |
// var uwPercent = round(coreSum/coreGrd.length,0); | |
// unweighted = 0.0; | |
// if(uwPercent>=65) | |
// unweighted = 1.0; | |
// if(uwPercent>=70) | |
// unweighted = 2.0; | |
// if(uwPercent>=80) | |
// unweighted = 3.0; | |
// if(uwPercent>=90) | |
// unweighted = 4.0; | |
//} | |
// | |
//function injectGPA(){ | |
// $("#center-top").append('<span class="grade-analyzer-style">Unweighted GPA: ~'+ unweighted.toFixed(1)+ '</span>'); | |
// console.log(courseLbl); | |
// console.log(courseAverages); | |
//} | |
// | |
//function graphGrades(domain,lbls,graphArr){ | |
// $(".content-top").append('<div id="chartContainer" style="height: 300px; width: 100%;"></div><script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>'); | |
// var dps = []; //dataPoints. | |
// for (var i = dps.length; i < graphArr.length; i++) | |
// dps.push({ | |
// y: graphArr[i], | |
// label: lbls[i] | |
// }); | |
// var chart = new CanvasJS.Chart("chartContainer", { | |
// title: { | |
// text: "Grades" | |
// }, | |
// axisX: { | |
// title: domain | |
// }, | |
// axisY: { | |
// title: "Percentage (%)" | |
// }, | |
// data: [{ | |
// type: "column", | |
// dataPoints: dps | |
// }] | |
// }); | |
// chart.options.data[0].dataPoints = dps; | |
// chart.render(); | |
//} | |
// | |
//function injectAnalyze() { | |
// $(".content-top").append(`<span class="analyze-grade grade-analyzer-style">Get Grade Analysis</span>`); | |
// $(".analyze-grade").click(function() { | |
// graphGrades("Marking Period",MPlabels,MPgrades); | |
// //console.log(grades); | |
// //console.log(maxgrades); | |
// console.log(MPgrades); | |
// console.log(MPlabels); | |
// console.log(MPcats); | |
// console.log(MPcatLabels); | |
// }); | |
//} | |
// | |
//function round(value, decimals) {//better rounding function | |
// return Number(Math.round(value+'e'+decimals)+'e-'+decimals); | |
//} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment