Skip to content

Commit

Permalink
Added option for scale assumption, modified update indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
aopell committed Jan 27, 2018
1 parent f5d61b7 commit 9a76bdd
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 37 deletions.
10 changes: 0 additions & 10 deletions .github/ISSUE_TEMPLATE.md

This file was deleted.

60 changes: 41 additions & 19 deletions js/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,26 @@ document.getElementById("home").innerHTML = svg;
document.documentElement.style.setProperty("--default-visibility", "visible");
document.body.appendChild(createElement("script", undefined, { src: "https://cdnjs.cloudflare.com/ajax/libs/gist-embed/2.7.1/gist-embed.min.js" }));

let footerText = `&copy; Aaron Opell 2018 | <a href="https://chrome.google.com/webstore/detail/${chrome.runtime.id}">Schoology Plus v${chrome.runtime.getManifest().version}${chrome.runtime.getManifest().update_url ? '' : ' dev'}</a> | <a href="https://github.com/aopell/SchoologyPlus">View Source and Contribute</a> | <a href="#" id="open-contributors">Contributors</a> | <a href="#" id="open-changelog"> Changelog</a>`;
let footerText = `&copy; Aaron Opell 2018 | <a href="https://chrome.google.com/webstore/detail/${chrome.runtime.id}">Schoology Plus v${chrome.runtime.getManifest().version}${chrome.runtime.getManifest().update_url ? '' : ' dev'}</a> | <a href="https://github.com/aopell/SchoologyPlus/issues/new" title="Submit bug report or feature request">Send Feedback</a> | <a href="https://github.com/aopell/SchoologyPlus">View Source & Contribute</a> | <a href="#" id="open-contributors">Contributors</a> | <a href="#" id="open-changelog"> Changelog</a>`;

let frame = document.createElement("iframe");
frame.src = "data:text/html;charset=utf-8,<script src='https://gist.github.com/aopell/2cc6e752ee4dcee9b2f44fa3862f2886.js'></script>";

let modals = [
new Modal("settings-modal", "Schoology Plus Settings", getModalContents(), footerText, openOptionsMenu),
new Modal(
"settings-modal",
"Schoology Plus Settings",
getModalContents(),
footerText,
openOptionsMenu
),
new Modal(
"changelog-modal",
"Schoology Plus Changelog",
frame,
"&copy; Aaron Opell 2018",
() => {
let updateText = document.querySelector(".new-update");
if (updateText) updateText.outerHTML = "";
let notifier = document.querySelector(".schoology-plus-icon .nav-icon-button .notifier");
if (notifier) notifier.outerHTML = "";
chrome.storage.sync.set({ newVersion: chrome.runtime.getManifest().version });
function () {
clearNewUpdate(true);
}
),
new Modal(
Expand Down Expand Up @@ -53,25 +55,32 @@ let modals = [
)
];

chrome.storage.sync.get("newVersion", s => {
chrome.storage.sync.get(["newVersion", "hideUpdateIndicator"], s => {
if (!s.newVersion || s.newVersion != chrome.runtime.getManifest().version) {
document.getElementById("open-changelog")
.insertAdjacentElement(
"afterbegin",
createElement(
"span",
["new-update"],
{ textContent: "New Update" }
));
chrome.storage.sync.set({ hideUpdateIndicator: false }, showUpdateIndicator);
document.querySelector(".schoology-plus-icon .nav-icon-button")
.appendChild(createElement(
"span",
["notifier"],
{ textContent: "!!" }
));
} else if (!s.hideUpdateIndicator) {
showUpdateIndicator();
}
});

function showUpdateIndicator() {
console.log("Showing update indicator");
document.getElementById("open-changelog")
.insertAdjacentElement(
"afterbegin",
createElement(
"span",
["new-update"],
{ textContent: "New Update" }
));
}

let video = document.body.appendChild(createElement("video", ["easter-egg"], {
onended: function () {
this.style.visibility = "hidden";
Expand Down Expand Up @@ -118,11 +127,23 @@ window.onclick = function (event) {
}
}

function clearNewUpdate(clearAll) {
let notifier = document.querySelector(".schoology-plus-icon .nav-icon-button .notifier");
if (notifier) notifier.outerHTML = "";
chrome.storage.sync.set({ newVersion: chrome.runtime.getManifest().version });
if (clearAll) {
chrome.storage.sync.set({ hideUpdateIndicator: true });
let updateText = document.querySelector(".new-update");
if (updateText) updateText.outerHTML = "";
}
}

function openOptionsMenu(settingsModal) {
settingsModal.body.innerHTML = "";
settingsModal.body.appendChild(getModalContents());
settingsModal.element.querySelector("#open-changelog").addEventListener("click", () => openModal("changelog-modal"));
settingsModal.element.querySelector("#open-contributors").addEventListener("click", () => openModal("contributors-modal"));
settingsModal.element.querySelector("#open-changelog").addEventListener("click", () => openModal("changelog-modal"), { once: true });
settingsModal.element.querySelector("#open-contributors").addEventListener("click", () => openModal("contributors-modal"), { once: true });
clearNewUpdate(false);
}

function openModal(id) {
Expand All @@ -142,6 +163,7 @@ function modalClose(element) {
if (!confirm("You have unsaved settings.\nAre you sure you want to exit?")) return;
updateSettings();
}

element.style.display = "none";
}

Expand Down
6 changes: 1 addition & 5 deletions js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,7 @@ function onAlarm(alarm) {
if (notificationDate > time) {
time = notificationDate;
timeModified = true;
let count = 0;
if (extraTextElement) {
count = +extraTextElement.textContent.match(/\d+/)[0];
}
totalAssignments += count + assignments.length;
totalAssignments++;
console.dir(notification);
}
}
Expand Down
4 changes: 2 additions & 2 deletions js/grades.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ for (let course of courses) {

let grade = createElement("span",["awarded-grade","injected-title-grade",courseGrade ? "grade-active-color" : "grade-none-color"]);
grade.textContent = courseGrade ? courseGrade.textContent : "—";
if (grade.textContent.match(/^\d+\.?\d*%/) !== null) {
if (storage["assumeScale"] != "disabled" && grade.textContent.match(/^\d+\.?\d*%/) !== null) {
let percent = Number.parseFloat(grade.textContent.substr(0, grade.textContent.length - 1));
let letterGrade = percent >= 90 ? "A" : (percent >= 80 ? "B" : (percent >= 70 ? "C" : (percent >= 60 ? "D" : "F")));
grade.textContent = `${letterGrade} (${percent}%)`;
Expand Down Expand Up @@ -246,7 +246,7 @@ function setGradeText(gradeElement, sum, max, row, doNotDisplay) {
// move the letter grade over to the right
span = row.querySelector(".comment-column").firstChild;
span.textContent = text;
if (span.textContent.match(/^\d+\.?\d*%/) !== null) {
if (storage["assumeScale"] != "disabled" && span.textContent.match(/^\d+\.?\d*%/) !== null) {
let percent = Number.parseFloat(span.textContent.substr(0, span.textContent.length - 1));
let letterGrade = percent >= 90 ? "A" : (percent >= 80 ? "B" : (percent >= 70 ? "C" : (percent >= 60 ? "D" : "F")));
span.textContent = `${letterGrade} (${percent}%)`;
Expand Down
21 changes: 21 additions & 0 deletions js/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,27 @@ function updateSettings() {
undefined,
element => element.value
),
createSetting(
"assumeScale",
"Assume Grading Scale",
"[Refresh required] Assumes a 10%-based grading scale (90-100 A, 80-89 B, etc.) when a class has no grading scale",
"select",
{
options: [
{
text: "Enabled",
value: "tenPercent"
},
{
text: "Disabled",
value: "disabled"
}
]
},
(value, element) => element.value = value || "tenPercent",
undefined,
element => element.value
),
createElement("div", ["settings-buttons-wrapper"], undefined, [
createElement("span", ["submit-span-wrapper", "modal-button"], { onclick: saveSettings }, [createElement("input", ["form-submit"], { type: "button", value: "Save Settings", id: "save-settings" })]),
createElement("a", ["restore-defaults"], { textContent: "Restore Defaults", onclick: restoreDefaults, href: "#" })
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Schoology Plus",
"short_name": "Schoology+",
"description": "Provides some enhancements to your LAUSD Schoology experience",
"version": "3.4",
"version": "3.5",
"icons": {
"128": "imgs/[email protected]",
"64": "imgs/[email protected]",
Expand Down

0 comments on commit 9a76bdd

Please sign in to comment.