diff --git a/css/all.css b/css/all.css index 545e8c6..e8e5e69 100644 --- a/css/all.css +++ b/css/all.css @@ -73,9 +73,14 @@ nav.nav-breadcrumb-nav-1251684582 span { /* Kept old classes to remain compatible with older versions of Schoology */ .StandardHeader-header-drop-menu-YShpU, -.Header-header-drop-menu-3SaYV, -.HeaderDropMenu-menu-border-3vo5S { +.Header-header-drop-menu-3SaYV:not(.util-width-thirty-nine-1B-gb), +.HeaderDropMenu-menu-border-3vo5S:not(.util-width-thirty-nine-1B-gb) { background-color: var(--hover-color) !important; + color: var(--contrast-text-color) !important; +} + +#header > header ul.util-width-thirty-nine-1B-gb { + background-color: white !important; } a.StandardHeader-header-drop-menu-YShpU:hover, diff --git a/js/all.js b/js/all.js index 80aa685..3ddfeaa 100644 --- a/js/all.js +++ b/js/all.js @@ -1225,6 +1225,23 @@ async function createQuickAccess() { rightCol.append(wrapper); } +function getAssignmentId(url) { + if (url.includes("/assignment/")) { + return url.match(/assignment\/(\d+)/)[1]; + } else if (url.includes("/course/")) { + // Discussion boards, maybe other assignments as well + return url.match(/course\/\d+\/.*\/(\d+)/)[1]; + } else if (url.includes("/event/")) { + // Calendar events + return url.match(/event\/(\d+)/)[1]; + } else if (url.includes("/external_tool/")) { + // External tools + return url.match(/external_tool\/(\d+)/)[1]; + } + + return null; +} + function indicateSubmittedAssignments() { let upcomingList = document.querySelector(".upcoming-events .upcoming-list"); const completionOverridesSetting = "assignmentCompletionOverrides"; @@ -1313,19 +1330,7 @@ function indicateSubmittedAssignments() { let assignmentElement = infotipElement.querySelector("a[href]"); // TODO errorcheck the assignmentId match - let assignmentId = null; - if (assignmentElement.href.includes("/assignment/")) { - assignmentId = assignmentElement.href.match(/assignment\/(\d+)/)[1]; - } else if (assignmentElement.href.includes("/course/")) { - // Discussion boards, maybe other assignments as well - assignmentId = assignmentElement.href.match(/course\/\d+\/.*\/(\d+)/)[1]; - } else if (assignmentElement.href.includes("/event/")) { - // Calendar events - assignmentId = assignmentElement.href.match(/event\/(\d+)/)[1]; - } else if (assignmentElement.href.includes("/external_tool/")) { - // External tools - assignmentId = assignmentElement.href.match(/external_tool\/(\d+)/)[1]; - } + let assignmentId = getAssignmentId(assignmentElement.href); // add a CSS class for both states, so we can distinguish 'loading' from known-(in)complete let isMarkedComplete = isAssignmentMarkedComplete(assignmentId); @@ -1411,4 +1416,94 @@ function indicateSubmittedAssignments() { setTimeout(indicateSubmitted, 1000); } +function getRecentlyCompletedDenominators() { + let recentlyCompletedList = document.querySelector(".recently-completed-wrapper .recently-completed-list"); + + async function getDirectAssignmentDenominatorAsync(assignmentId) { + try { + let json = await fetchApiJson(`sections/${sectionId}/assignments/${assignmentId}`); + return json.max_points; + } + catch (err) { + return null; + } + } + + async function getAssignmentDenominatorAsync(sectionId, assignmentId) { + if (assignmentId == null) { + return null; + } + + let directDenominator = await getDirectAssignmentDenominatorAsync(assignmentId); + if (directDenominator !== null && !Number.isNaN(directDenominator)) { + Logger.debug(`Found direct denominator for assignment ${assignmentId} in section ${sectionId}: ${directDenominator}`); + return directDenominator; + } + + try { + let json = await fetchApiJson(`users/${getUserId()}/grades?section_id=${sectionId}`); + + if (json.section.length === 0) { + throw new Error("Assignment details could not be read"); + } + + const assignments = json.section[0].period.reduce((prevVal, curVal) => prevVal.concat(curVal.assignment), []);//combines the assignment arrays from each period + + let denom = Number.parseFloat(assignments.filter(x => x.assignment_id == assignmentId)[0].max_points); + + Logger.debug(`Found indirect denominator for assignment ${assignmentId} in section ${sectionId}: ${denom}`); + + return denom; + } catch (err) { + Logger.error(`Failed finding denominator for assignment ${assignmentId} in section ${sectionId}`, err); + return null; + } + } + + async function getSectionIdMap() { + let sections = await fetchApiJson(`users/${getUserId()}/sections`); + let sectionMap = {}; + + for (let section of sections.section) { + sectionMap[section.course_title + " : " + section.section_title] = section.id; + } + + return sectionMap; + } + + // Indicate submitted assignments in Upcoming + async function getDenominators() { + let sectionMap = await getSectionIdMap(); + + for (let recentEvent of recentlyCompletedList.querySelectorAll(".recently-completed-event")) { + try { + let eventLink = recentEvent.querySelector("a[href]"); + let assignmentId = getAssignmentId(eventLink.href); + let sectionId = sectionMap[recentEvent.querySelector(".realm-title-course-title .realm-main-titles").textContent.trim()]; + + if (sectionId && assignmentId) { + Logger.debug(`Getting denominator for assignment ${assignmentId} in section ${sectionId}`); + let denominator = await getAssignmentDenominatorAsync(sectionId, assignmentId); + Logger.debug(`Got denominator for assignment ${assignmentId} in section ${sectionId}: ${denominator}`); + + if (denominator) { + let prevElement = recentEvent.querySelector("span.infotip.grade-infotip span.recently-completed-grade"); + + if (prevElement) { + let denominatorElement = createElement("span", ["splus-recent-denominator"], { textContent: ` / ${denominator}` }); + prevElement.insertAdjacentElement("afterend", denominatorElement); + } else { + recentEvent.querySelector("span.recently-completed-grade").textContent += ` / ${denominator}`; + } + } + } + } catch (err) { + Logger.error(`Failed finding denominator for recent assignment '${recentEvent.querySelector(".infotip a[href]")?.href}' : `, err); + } + } + } + + setTimeout(getDenominators, 1000); +} + Logger.debug("Finished loading all.js"); diff --git a/js/grades.js b/js/grades.js index f1cd81b..d0837a7 100644 --- a/js/grades.js +++ b/js/grades.js @@ -201,6 +201,12 @@ var fetchQueue = []; let processAssignment = async function (assignment) { let maxGrade = assignment.querySelector(".max-grade"); let score = assignment.querySelector(".rounded-grade") || assignment.querySelector(".rubric-grade-value"); + + if (!maxGrade && !score && !assignment.querySelector(".no-grade")) { + // some schoology assignments don't display a grade, so we need to create a placeholder + assignment.querySelector(".grade-column > .td-content-wrapper").prepend(createElement("span", ["no-grade"], { textContent: "—" })); + } + if (score) { let assignmentScore = Number.parseFloat(score.textContent); let assignmentMax = Number.parseFloat(maxGrade.textContent.substring(3)); diff --git a/js/home.js b/js/home.js index 7d7f860..91a754b 100644 --- a/js/home.js +++ b/js/home.js @@ -203,6 +203,7 @@ function reorderSidebar() { (async function () { indicateSubmittedAssignments(); + getRecentlyCompletedDenominators(); await createQuickAccess(); setTimeout(() => { reorderSidebar(); diff --git a/manifest.json b/manifest.json index 7b8873a..d2d8a2b 100644 --- a/manifest.json +++ b/manifest.json @@ -10,7 +10,7 @@ "update_url": "https://schoologypl.us/firefox_updates.json" } }, - "version": "7.9", + "version": "7.10", "icons": { "128": "imgs/icon@128.png", "64": "imgs/icon@64.png",