Skip to content

Commit

Permalink
Added ability to disable notifications, added grades link
Browse files Browse the repository at this point in the history
Closes #2 (finally, I think, it seems to work)
Closes #17
  • Loading branch information
aopell committed Jan 17, 2018
1 parent 4a7e1db commit 491f7b7
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 40 deletions.
11 changes: 9 additions & 2 deletions css/all.css
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ video.easter-egg {
}

.setting-entry {
padding-bottom: 4px;
margin-bottom: 8px;
}

.setting-modified {
Expand All @@ -190,5 +190,12 @@ video.easter-egg {

.modal-button {
margin-left: 0 !important;
margin-top: 4px;
margin-top: 8px;
}

.modal-body input[type=text], .modal-body input[type=number] {
color: #333;
border: 1px solid #c7c7c7;
font-family: "Lucida Grande", Verdana, Helvetica, Arial, sans-serif;
padding: 4px;
}
18 changes: 10 additions & 8 deletions js/all.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
// Page Modifications

let svg = '<a href="/home"><svg id="logo" viewBox="0 -2 220 31" width="174" height="31" style="fill: white;"><path d="M15.4 30.7C6.9 30.7 0 23.8 0 15.4 0 6.9 6.9 0 15.4 0s15.4 6.9 15.4 15.4c-.1 8.4-7 15.3-15.4 15.3zm0-28.1C8.3 2.6 2.6 8.3 2.6 15.4c0 7.1 5.8 12.8 12.8 12.8 7.1 0 12.8-5.8 12.8-12.8 0-7.1-5.8-12.8-12.8-12.8z"></path><path d="M14.7 16.3c-2.5-.6-5.6-1.3-5.6-4.6 0-2.9 2.4-4.7 6.1-4.7 3 0 6.2 1.4 6.7 5.1l-2.9.4c0-1-.1-1.7-1.1-2.5s-2.2-.9-3-.9c-2.1 0-3.1 1.2-3.1 2.3 0 1.5 1.7 2 3.8 2.5l1.5.4c1.9.4 5.2 1.2 5.2 4.5 0 2.6-2.3 5-6.6 5-1.8 0-3.6-.4-4.9-1.3-.5-.4-2-1.6-2.3-4.3l3-.5c0 .7 0 2 1.2 3.1.9.8 2.1.9 3.2.9 2.3 0 3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.2c.2 0 .4-.1.4-.2 0-.2-.1-.3-.4-.3h-.2v.5z"></path></g></svg></a>';
let modalHTML = '<div id="settings-modal" class="modal"> <div class="modal-content"> <div class="modal-header"> <span class="close">&times;</span> <p class="modal-title">Schoology Plus Settings</p> </div><div class="modal-body"> </div><div class="modal-footer"> <p class="modal-footer-text">&copy; Aaron Opell 2018</p></div></div></div>';
let modalHTML = `<div id="settings-modal" class="modal"> <div class="modal-content"> <div class="modal-header"> <span class="close">&times;</span> <p class="modal-title">Schoology Plus Settings</p> </div><div class="modal-body"> </div><div class="modal-footer"> <p class="modal-footer-text">&copy; Aaron Opell 2018 | Schoology Plus v${chrome.runtime.getManifest().version}${chrome.runtime.getManifest().update_url ? '' : ' dev'}</p></div></div></div>`;
document.getElementById("primary-home").insertAdjacentElement("afterEnd", createElement("li", undefined, { id: "primary-home", innerHTML: '<a href="/grades"><span>Grades</span></a>' }));
document.getElementById("home").innerHTML = svg;
document.body.appendChild(document.createElement("div")).innerHTML = modalHTML;

let modal = document.getElementById("settings-modal");

let modalFooterText = document.querySelector(".modal-footer-text");
modalFooterText.textContent += ` | Schoology Plus v${chrome.runtime.getManifest().version}`;

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

function openOptionsMenu() {
modalBody.innerHTML = "";
modalBody.appendChild(getModalContents());
document.getElementById("settings-modal").style.display = "block";
}

function modalClose() {
if(anySettingsModified()){
if(!confirm("You have unsaved settings.\nAre you sure you want to exit?")) return;
if (anySettingsModified()) {
if (!confirm("You have unsaved settings.\nAre you sure you want to exit?")) return;
updateSettings();
modalBody.innerHTML = "";
modalBody.appendChild(getModalContents());
}
modal.style.display = "none";
}
56 changes: 34 additions & 22 deletions js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ chrome.browserAction.onClicked.addListener(function () {
});

function onAlarm(alarm) {
if (alarm && alarm.name === "notification") {
try {
console.log(`[${new Date()}] Checking for new notifications`);
fetch("https://lms.lausd.net/home/notifications?filter=all", {
credentials: "same-origin"
}).then(function (response) {
if (response.ok) {
return response.json();
}
throw new Error("Error loading notifications: " + response);
}).then(function (response) {
chrome.storage.sync.get("lastTime", function (value) {
console.log(value);
chrome.storage.sync.get(null, function (value) {
if (alarm && alarm.name === "notification" && value.notifications != "disabled") {
try {
console.log(`[${new Date()}] Checking for new notifications`);
fetch("https://lms.lausd.net/home/notifications?filter=all", {
credentials: "same-origin"
}).then(function (response) {
if (response.ok) {
return response.json();
}
throw new Error("Error loading notifications: " + response);
}).then(function (response) {
console.log("Last new grade: " + new Date(value.lastTime).toString());
let time = value.lastTime;
let timeModified = false;
if (!time) {
Expand Down Expand Up @@ -94,22 +94,34 @@ function onAlarm(alarm) {
isClickable: true
};
console.dir(n);
chrome.browserAction.getBadgeText({}, x => {
let num = Number.parseInt(x);
chrome.browserAction.setBadgeText({ text: (num ? num + totalAssignments : totalAssignments).toString() });
});
chrome.notifications.create("gradeNotification", n, null);
if (!value.notifications || value.notifications == "enabled" || value.notifications == "badge") {
chrome.browserAction.getBadgeText({}, x => {
let num = Number.parseInt(x);
chrome.browserAction.setBadgeText({ text: (num ? num + totalAssignments : totalAssignments).toString() });
});
} else {
console.log("Number badge is disabled");
}
if (!value.notifications || value.notifications == "enabled" || value.notifications == "popup") {
chrome.notifications.create("gradeNotification", n, null);
} else {
console.log("Popup notifications are disabled");
}
}

if (timeModified) {
chrome.storage.sync.set({ lastTime: time }, () => { console.log("Set new time " + new Date(time)) });
} else {
console.log("No new notifications");
}

});
});
} catch (error) {
console.error(error);
} catch (error) {
console.error(error);
}
}
else if (value.notifications === "disabled") {
console.log("Notifications are disabled");
}
}
});
}
39 changes: 32 additions & 7 deletions js/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ function getModalContents() {
return modalContents;
}

function openOptionsMenu() {
document.getElementById("settings-modal").style.display = "block";
}

let rainbowInterval = undefined;
let rainbowColor = 0;
function colorLoop() {
Expand Down Expand Up @@ -102,6 +98,35 @@ function updateSettings() {
},
element => element.value === "true"
),
createSetting(
"notifications",
"Desktop Notifications",
"Displays desktop notifications and a number badge on the extension button when new grades are entered",
"select",
{
options: [
{
text: "Number Badge and Desktop Notifications",
value: "enabled"
},
{
text: "Number Badge Only",
value: "badge"
},
{
text: "Desktop Notifications Only",
value: "popup"
},
{
text: "Disabled",
value: "disabled"
}
]
},
(value, element) => element.value = value || "enabled",
undefined,
element => element.value
),
createElement("span", ["submit-span-wrapper", "modal-button"], { onclick: saveSettings }, [createElement("input", ["form-submit"], { type: "button", value: "Save Settings", id: "save-settings" })])
]);
});
Expand Down Expand Up @@ -174,16 +199,16 @@ function settingModified(event) {
let element = event.target || event;
let parent = element.parentElement;
if (parent && !parent.querySelector(".setting-modified")) {
parent.appendChild(createElement("span", ["setting-modified"], { textContent: " *" }));
parent.appendChild(createElement("span", ["setting-modified"], { textContent: " *", title: "This setting has been modified from its saved value" }));
}
let setting = settings[element.dataset.settingName];
setting.modified = true;
setting.onmodify(event);
}

function anySettingsModified() {
for(let setting in settings) {
if(settings[setting].modified) {
for (let setting in settings) {
if (settings[setting].modified) {
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 2,
"name": "Schoology Plus",
"description": "Provides some enhancements to your LAUSD Schoology experience",
"version": "3.0.2",
"version": "3.1",
"icons": {
"128": "imgs/[email protected]",
"64": "imgs/[email protected]",
Expand Down

0 comments on commit 491f7b7

Please sign in to comment.