From 0e83abff65a041cfb6caff43e1d690e5d8a1c332 Mon Sep 17 00:00:00 2001 From: Drini Cami Date: Sat, 7 Mar 2015 18:27:32 -0500 Subject: [PATCH 1/9] Added support for desktop notifications in chrome --- MarmoUI-Chrome/manifest.json | 8 +++++- MarmoUI-Chrome/notifications.js | 37 ++++++++++++++++++++++++ MarmoUI-Chrome/script.js | 50 +++++++++++++++++++++++++++++++-- 3 files changed, 92 insertions(+), 3 deletions(-) create mode 100644 MarmoUI-Chrome/notifications.js diff --git a/MarmoUI-Chrome/manifest.json b/MarmoUI-Chrome/manifest.json index 68691d6..0f4ea4e 100644 --- a/MarmoUI-Chrome/manifest.json +++ b/MarmoUI-Chrome/manifest.json @@ -15,5 +15,11 @@ "matches": ["https://marmoset.student.cs.uwaterloo.ca/*"], "js": ["script.js"] } - ] + ], + + "background": { + "persistent": false, + "scripts": ["notifications.js"] + }, + "permissions": ["notifications"] } \ No newline at end of file diff --git a/MarmoUI-Chrome/notifications.js b/MarmoUI-Chrome/notifications.js new file mode 100644 index 0000000..5368ba3 --- /dev/null +++ b/MarmoUI-Chrome/notifications.js @@ -0,0 +1,37 @@ +// Notifications which have not been closed yet +var activeNotifications = {}; + +chrome.runtime.onMessage.addListener(function(request, sender) { + + if (request.type == "notification") { + chrome.notifications.create('', request.notification, + function(notificationId) { + // Add URL to activeNotifications so we can access it + // on button click + activeNotifications[notificationId] = { + url: request.options.url + } + }); + } +}); + +// Button handler for "View Results" +function openResults(notificationId, buttonIndex) { + // Open a new tab with the results + chrome.tabs.create(activeNotifications[notificationId], function(tab) { + + // Focus new tab's window + chrome.windows.update(tab.windowId, {focused: true}, function (){ }); + }); + + // Close notification + chrome.notifications.clear(notificationId, function() {}); +} + +function notificationDeactivated(notificationId) { + delete activeNotifications[notificationId]; +} + +// Registering listeners +chrome.notifications.onButtonClicked.addListener(openResults) +chrome.notifications.onClosed.addListener(notificationDeactivated); \ No newline at end of file diff --git a/MarmoUI-Chrome/script.js b/MarmoUI-Chrome/script.js index 69e0035..600889d 100644 --- a/MarmoUI-Chrome/script.js +++ b/MarmoUI-Chrome/script.js @@ -524,6 +524,23 @@ function runMarmoUI() function applyChangesProblemsList() { + + //After testing, loadSubmission and notify + function loadSubmissionAfterAsyncReload(tableCell, requestResult, requestURL) { + loadSubmission(tableCell, requestResult, requestURL); + + // If finished testing, display notification + if(tableCell.find("a:contains('Not tested')").length == 0) { + var $a = tableCell.find("a"); + + notifyTestingComplete({ + test: tableCell.parent().children().first().text().trim(), + result: $a.text().trim(), + url: 'https://marmoset.student.cs.uwaterloo.ca' + $a.attr('href') + }); + } + } + //When async callbacks, decrypt the result from the page and integrate into the page function loadSubmission(tableCell, requestResult, requestURL) { @@ -550,7 +567,7 @@ function runMarmoUI() if(firstLine.find("td:contains('tested yet')").length > 0) { tableCell.find("a").html("Not tested (reload in s)"); - queueAsyncReload(tableCell, requestURL, loadSubmission, reload_time); + queueAsyncReload(tableCell, requestURL, loadSubmissionAfterAsyncReload, reload_time); } //Check if latest solution failed to compile //If failed to compile, show it as uncompiled and exits @@ -859,8 +876,13 @@ function runMarmoUI() }); } - //Start of actual executing code + // Creates desktop notification + function notifyTestingComplete(notification) { + notification.type = "resultsNotification"; + window.postMessage(notification, "*"); + } + //Start of actual executing code //Find out which page we're on var path = $(location).attr("href"); //Check which page we're on @@ -940,4 +962,28 @@ function runMarmoUI() } } +// Listener to handle desktop notifications +// (notification goes from page context -> content-script -> background page (notifications.js)) +window.addEventListener("message", function(event) { + // We only accept messages from ourselves + if (event.source != window) + return; + + if (event.data.type && (event.data.type == "resultsNotification")) { + chrome.runtime.sendMessage({type: "notification", + notification: { + type: "basic", + iconUrl: chrome.extension.getURL("image/icon128.png"), + title: event.data.test + " Testing Complete", + message: event.data.result, + buttons: [{title: "View results"}], + }, + options: { + url:event.data.url + } + }); + } +}, false); + + loadMarmoUI(runMarmoUI); From 2f03140426540ad902fb229a56efa864bf2c8745 Mon Sep 17 00:00:00 2001 From: Drini Cami Date: Sat, 7 Mar 2015 19:41:29 -0500 Subject: [PATCH 2/9] Added notifications to SubmissionList, and added an onClicked event to the notification --- MarmoUI-Chrome/notifications.js | 49 +++++++++++++++++++++++++++++---- MarmoUI-Chrome/script.js | 21 +++++++++----- 2 files changed, 58 insertions(+), 12 deletions(-) diff --git a/MarmoUI-Chrome/notifications.js b/MarmoUI-Chrome/notifications.js index 5368ba3..973f82b 100644 --- a/MarmoUI-Chrome/notifications.js +++ b/MarmoUI-Chrome/notifications.js @@ -8,17 +8,17 @@ chrome.runtime.onMessage.addListener(function(request, sender) { function(notificationId) { // Add URL to activeNotifications so we can access it // on button click - activeNotifications[notificationId] = { - url: request.options.url - } + request.sender = sender; + activeNotifications[notificationId] = request; }); } }); // Button handler for "View Results" function openResults(notificationId, buttonIndex) { + // Open a new tab with the results - chrome.tabs.create(activeNotifications[notificationId], function(tab) { + chrome.tabs.create(activeNotifications[notificationId].options, function(tab) { // Focus new tab's window chrome.windows.update(tab.windowId, {focused: true}, function (){ }); @@ -32,6 +32,45 @@ function notificationDeactivated(notificationId) { delete activeNotifications[notificationId]; } +function focusMarmoUI(notificationId) { + var windowId = activeNotifications[notificationId].sender.tab.windowId; + var tabId = activeNotifications[notificationId].sender.tab.id; + var pageUrl = activeNotifications[notificationId].sender.url; + + //check if window still exists + chrome.windows.get(windowId, function() { + if(!chrome.runtime.lastError) { + // focus + chrome.windows.update(windowId, {focused: true}, function (){}); + } + else { + // otherwise open results at previous url + chrome.tabs.create({url: pageUrl}, function(tab) { + // Focus new tab's window + chrome.windows.update(tab.windowId, {focused: true}, function (){ }); + }); + } + }); + + // check if tab still exists + chrome.tabs.get(tabId, function() { + if(!chrome.runtime.lastError) { + // set active + chrome.tabs.update(tabId, {active: true}, function () {}); + } else { + // otherwise open results at previous url + chrome.tabs.create({url: pageUrl}, function(tab) { + // Focus new tab's window + chrome.windows.update(tab.windowId, {focused: true}, function (){ }); + }); + } + }); + + // Close notification + chrome.notifications.clear(notificationId, function() {}); +} + // Registering listeners chrome.notifications.onButtonClicked.addListener(openResults) -chrome.notifications.onClosed.addListener(notificationDeactivated); \ No newline at end of file +chrome.notifications.onClosed.addListener(notificationDeactivated); +chrome.notifications.onClicked.addListener(focusMarmoUI); \ No newline at end of file diff --git a/MarmoUI-Chrome/script.js b/MarmoUI-Chrome/script.js index 600889d..0160725 100644 --- a/MarmoUI-Chrome/script.js +++ b/MarmoUI-Chrome/script.js @@ -742,6 +742,9 @@ function runMarmoUI() } else { + notifyTestingComplete({ + test: $(".nav").children().last().text() + }) //No more untested solutions, reload to see results document.location.reload(true); } @@ -970,18 +973,22 @@ window.addEventListener("message", function(event) { return; if (event.data.type && (event.data.type == "resultsNotification")) { - chrome.runtime.sendMessage({type: "notification", + var toSend = {type: "notification", notification: { type: "basic", iconUrl: chrome.extension.getURL("image/icon128.png"), title: event.data.test + " Testing Complete", - message: event.data.result, - buttons: [{title: "View results"}], + message: (event.data.result ? "Result: " + event.data.result : "") }, - options: { - url:event.data.url - } - }); + options: {} + }; + + // Notification has "View results" button + if(event.data.url) { + toSend.notification.buttons = [{title: "View results"}]; + toSend.options.url = event.data.url + } + chrome.runtime.sendMessage(toSend); } }, false); From 5684cfe2af5d8ef3e7e26f6209e46727913f2af8 Mon Sep 17 00:00:00 2001 From: Drini Cami Date: Sat, 7 Mar 2015 19:54:43 -0500 Subject: [PATCH 3/9] Fixed edge case where both window and tab were closed. --- MarmoUI-Chrome/notifications.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/MarmoUI-Chrome/notifications.js b/MarmoUI-Chrome/notifications.js index 973f82b..00f76ac 100644 --- a/MarmoUI-Chrome/notifications.js +++ b/MarmoUI-Chrome/notifications.js @@ -43,13 +43,6 @@ function focusMarmoUI(notificationId) { // focus chrome.windows.update(windowId, {focused: true}, function (){}); } - else { - // otherwise open results at previous url - chrome.tabs.create({url: pageUrl}, function(tab) { - // Focus new tab's window - chrome.windows.update(tab.windowId, {focused: true}, function (){ }); - }); - } }); // check if tab still exists From f66cafa73af0bdf0c8f07edc697b05f185e6976a Mon Sep 17 00:00:00 2001 From: Drini Cami Date: Sun, 8 Mar 2015 16:02:49 -0400 Subject: [PATCH 4/9] Notifications no longer show if user has marmoset tab active + window focused --- MarmoUI-Chrome/notifications.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/MarmoUI-Chrome/notifications.js b/MarmoUI-Chrome/notifications.js index 00f76ac..40eb478 100644 --- a/MarmoUI-Chrome/notifications.js +++ b/MarmoUI-Chrome/notifications.js @@ -4,13 +4,20 @@ var activeNotifications = {}; chrome.runtime.onMessage.addListener(function(request, sender) { if (request.type == "notification") { - chrome.notifications.create('', request.notification, - function(notificationId) { - // Add URL to activeNotifications so we can access it - // on button click - request.sender = sender; - activeNotifications[notificationId] = request; - }); + + chrome.windows.get(sender.tab.windowId, function(win) { + // Don't show notification if user is still on marmoset + if (win.focused && sender.tab.active) return; + + chrome.notifications.create('', request.notification, + function(notificationId) { + // Add URL to activeNotifications so we can access it + // on button click + request.sender = sender; + activeNotifications[notificationId] = request; + }); + + }); } }); From c485f7d131f446a27a41c8ee68cc3fc29b0d4a2b Mon Sep 17 00:00:00 2001 From: Drini Cami Date: Sun, 8 Mar 2015 18:14:27 -0400 Subject: [PATCH 5/9] Added options page to enable/disable notifications --- MarmoUI-Chrome/background.js | 12 +++++++++ MarmoUI-Chrome/init.js | 12 +++++++++ MarmoUI-Chrome/manifest.json | 9 +++++-- MarmoUI-Chrome/notifications.js | 3 ++- MarmoUI-Chrome/options.html | 19 +++++++++++++ MarmoUI-Chrome/options.js | 47 +++++++++++++++++++++++++++++++++ 6 files changed, 99 insertions(+), 3 deletions(-) create mode 100644 MarmoUI-Chrome/background.js create mode 100644 MarmoUI-Chrome/init.js create mode 100644 MarmoUI-Chrome/options.html create mode 100644 MarmoUI-Chrome/options.js diff --git a/MarmoUI-Chrome/background.js b/MarmoUI-Chrome/background.js new file mode 100644 index 0000000..cdcd0c2 --- /dev/null +++ b/MarmoUI-Chrome/background.js @@ -0,0 +1,12 @@ +// Initialize default options +chrome.runtime.onInstalled.addListener(function() { + var defaults = { + showNotifications: { + type: "boolean", + label: "Display desktop notifications when testing completed", + value: true + } + }; + + localStorage["opts"] = JSON.stringify(defaults); +}); \ No newline at end of file diff --git a/MarmoUI-Chrome/init.js b/MarmoUI-Chrome/init.js new file mode 100644 index 0000000..dbd7779 --- /dev/null +++ b/MarmoUI-Chrome/init.js @@ -0,0 +1,12 @@ +// Initialize default options +chrome.runtime.onInstalled.addListener(function() { + var defaults = { + showNotifications: { + type: "checkbox", + label: "Display desktop notifications when testing completed", + value: true + } + }; + + localStorage["opts"] = JSON.stringify(defaults); +}); \ No newline at end of file diff --git a/MarmoUI-Chrome/manifest.json b/MarmoUI-Chrome/manifest.json index 0f4ea4e..b593483 100644 --- a/MarmoUI-Chrome/manifest.json +++ b/MarmoUI-Chrome/manifest.json @@ -19,7 +19,12 @@ "background": { "persistent": false, - "scripts": ["notifications.js"] + "scripts": ["notifications.js", "init.js"] }, - "permissions": ["notifications"] + "permissions": ["notifications"], + + "options_ui": { + "page": "options.html", + "chrome_style": true + } } \ No newline at end of file diff --git a/MarmoUI-Chrome/notifications.js b/MarmoUI-Chrome/notifications.js index 40eb478..4cbe574 100644 --- a/MarmoUI-Chrome/notifications.js +++ b/MarmoUI-Chrome/notifications.js @@ -2,8 +2,9 @@ var activeNotifications = {}; chrome.runtime.onMessage.addListener(function(request, sender) { + var opts = JSON.parse(localStorage["opts"]); - if (request.type == "notification") { + if (request.type == "notification" && opts.showNotifications.value) { chrome.windows.get(sender.tab.windowId, function(win) { // Don't show notification if user is still on marmoset diff --git a/MarmoUI-Chrome/options.html b/MarmoUI-Chrome/options.html new file mode 100644 index 0000000..d46c688 --- /dev/null +++ b/MarmoUI-Chrome/options.html @@ -0,0 +1,19 @@ + + + + MarmoUI Options + + + + +
+ +
+ + + + + \ No newline at end of file diff --git a/MarmoUI-Chrome/options.js b/MarmoUI-Chrome/options.js new file mode 100644 index 0000000..813704d --- /dev/null +++ b/MarmoUI-Chrome/options.js @@ -0,0 +1,47 @@ +// Load Options +var opts = JSON.parse(localStorage["opts"]); + +// Saves options to chrome.storage.sync. +function save_options() { + + for(var id in opts) { + var el = document.getElementById(id); + if(opts[id].type == 'checkbox') { + opts[id].value = el.checked; + } + } + + localStorage["opts"] = JSON.stringify(opts); + + // Update status to let user know options were saved. + var status = document.getElementById('status'); + status.textContent = 'Options saved.'; + setTimeout(function() { + status.textContent = ''; + }, 1200); +} + +// Restores options stored in localStorage +function restore_options() { + + var optsEl = document.getElementById('options'); + for(var id in opts) { + var opt = opts[id]; + if(opt.type == 'checkbox') { + // Create checkbox + var checkbox = document.createElement('input'); + checkbox.setAttribute('type', 'checkbox'); + checkbox.id = id; + checkbox.checked = opt.value; + optsEl.appendChild(checkbox); + // Create Label + var label = document.createElement('label'); + label.setAttribute('for', id); + label.textContent = opt.label + "\n"; + optsEl.appendChild(label); + } + } +} +document.addEventListener('DOMContentLoaded', restore_options); +document.getElementById('save').addEventListener('click', + save_options); \ No newline at end of file From c6a263b3807cef1661575ace20f23946abf5b6d4 Mon Sep 17 00:00:00 2001 From: Drini Cami Date: Sun, 8 Mar 2015 18:27:29 -0400 Subject: [PATCH 6/9] Restructured file hierarchy --- MarmoUI-Chrome/background.js | 12 ------------ MarmoUI-Chrome/{ => background}/init.js | 0 MarmoUI-Chrome/{ => background}/notifications.js | 0 MarmoUI-Chrome/{ => content}/script.js | 0 MarmoUI-Chrome/manifest.json | 6 +++--- MarmoUI-Chrome/{ => options}/options.html | 0 MarmoUI-Chrome/{ => options}/options.js | 0 7 files changed, 3 insertions(+), 15 deletions(-) delete mode 100644 MarmoUI-Chrome/background.js rename MarmoUI-Chrome/{ => background}/init.js (100%) rename MarmoUI-Chrome/{ => background}/notifications.js (100%) rename MarmoUI-Chrome/{ => content}/script.js (100%) rename MarmoUI-Chrome/{ => options}/options.html (100%) rename MarmoUI-Chrome/{ => options}/options.js (100%) diff --git a/MarmoUI-Chrome/background.js b/MarmoUI-Chrome/background.js deleted file mode 100644 index cdcd0c2..0000000 --- a/MarmoUI-Chrome/background.js +++ /dev/null @@ -1,12 +0,0 @@ -// Initialize default options -chrome.runtime.onInstalled.addListener(function() { - var defaults = { - showNotifications: { - type: "boolean", - label: "Display desktop notifications when testing completed", - value: true - } - }; - - localStorage["opts"] = JSON.stringify(defaults); -}); \ No newline at end of file diff --git a/MarmoUI-Chrome/init.js b/MarmoUI-Chrome/background/init.js similarity index 100% rename from MarmoUI-Chrome/init.js rename to MarmoUI-Chrome/background/init.js diff --git a/MarmoUI-Chrome/notifications.js b/MarmoUI-Chrome/background/notifications.js similarity index 100% rename from MarmoUI-Chrome/notifications.js rename to MarmoUI-Chrome/background/notifications.js diff --git a/MarmoUI-Chrome/script.js b/MarmoUI-Chrome/content/script.js similarity index 100% rename from MarmoUI-Chrome/script.js rename to MarmoUI-Chrome/content/script.js diff --git a/MarmoUI-Chrome/manifest.json b/MarmoUI-Chrome/manifest.json index b593483..399e71d 100644 --- a/MarmoUI-Chrome/manifest.json +++ b/MarmoUI-Chrome/manifest.json @@ -13,18 +13,18 @@ "content_scripts": [ { "matches": ["https://marmoset.student.cs.uwaterloo.ca/*"], - "js": ["script.js"] + "js": ["content/script.js"] } ], "background": { "persistent": false, - "scripts": ["notifications.js", "init.js"] + "scripts": ["background/notifications.js", "background/init.js"] }, "permissions": ["notifications"], "options_ui": { - "page": "options.html", + "page": "options/options.html", "chrome_style": true } } \ No newline at end of file diff --git a/MarmoUI-Chrome/options.html b/MarmoUI-Chrome/options/options.html similarity index 100% rename from MarmoUI-Chrome/options.html rename to MarmoUI-Chrome/options/options.html diff --git a/MarmoUI-Chrome/options.js b/MarmoUI-Chrome/options/options.js similarity index 100% rename from MarmoUI-Chrome/options.js rename to MarmoUI-Chrome/options/options.js From 8ba02df8737c540174be2ae2c7858e9bc66e6bc5 Mon Sep 17 00:00:00 2001 From: Drini Cami Date: Sun, 8 Mar 2015 19:06:45 -0400 Subject: [PATCH 7/9] Added options fallback; added showSettings listener to notifications --- MarmoUI-Chrome/background/notifications.js | 11 ++++++++++- MarmoUI-Chrome/manifest.json | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/MarmoUI-Chrome/background/notifications.js b/MarmoUI-Chrome/background/notifications.js index 4cbe574..72fc9f4 100644 --- a/MarmoUI-Chrome/background/notifications.js +++ b/MarmoUI-Chrome/background/notifications.js @@ -71,7 +71,16 @@ function focusMarmoUI(notificationId) { chrome.notifications.clear(notificationId, function() {}); } +// Opens the options page +function openOptions() { + chrome.tabs.create({url: 'chrome://extensions/?options=' + chrome.runtime.id}, function(tab) { + // Bring window to focus + chrome.windows.update(tab.windowId, {focused:true}, function() {}); + }); +} + // Registering listeners chrome.notifications.onButtonClicked.addListener(openResults) chrome.notifications.onClosed.addListener(notificationDeactivated); -chrome.notifications.onClicked.addListener(focusMarmoUI); \ No newline at end of file +chrome.notifications.onClicked.addListener(focusMarmoUI); +chrome.notifications.onShowSettings.addListener(openOptions); \ No newline at end of file diff --git a/MarmoUI-Chrome/manifest.json b/MarmoUI-Chrome/manifest.json index 399e71d..d265909 100644 --- a/MarmoUI-Chrome/manifest.json +++ b/MarmoUI-Chrome/manifest.json @@ -23,6 +23,7 @@ }, "permissions": ["notifications"], + "options_page": "options/options.html", "options_ui": { "page": "options/options.html", "chrome_style": true From b4293b14280a158062463a12b0abe68620bc8b73 Mon Sep 17 00:00:00 2001 From: Drini Cami Date: Sun, 8 Mar 2015 19:45:26 -0400 Subject: [PATCH 8/9] Added check if user disables notification permissions --- MarmoUI-Chrome/background/notifications.js | 27 ++++++++++++---------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/MarmoUI-Chrome/background/notifications.js b/MarmoUI-Chrome/background/notifications.js index 72fc9f4..819dc8b 100644 --- a/MarmoUI-Chrome/background/notifications.js +++ b/MarmoUI-Chrome/background/notifications.js @@ -5,19 +5,22 @@ chrome.runtime.onMessage.addListener(function(request, sender) { var opts = JSON.parse(localStorage["opts"]); if (request.type == "notification" && opts.showNotifications.value) { - - chrome.windows.get(sender.tab.windowId, function(win) { - // Don't show notification if user is still on marmoset - if (win.focused && sender.tab.active) return; - - chrome.notifications.create('', request.notification, - function(notificationId) { - // Add URL to activeNotifications so we can access it - // on button click - request.sender = sender; - activeNotifications[notificationId] = request; + // Check if we have permission + chrome.notifications.getPermissionLevel(function(level) { + if(level == "denied") return; + + chrome.windows.get(sender.tab.windowId, function(win) { + // Don't show notification if user is still on marmoset + if (win.focused && sender.tab.active) return; + + chrome.notifications.create('', request.notification, + function(notificationId) { + // Add URL to activeNotifications so we can access it + // on button click + request.sender = sender; + activeNotifications[notificationId] = request; }); - + }); }); } }); From bcfa09bdc4d0b534f8f0be9f959a95b8139f5e12 Mon Sep 17 00:00:00 2001 From: Drini Cami Date: Sun, 8 Mar 2015 19:55:48 -0400 Subject: [PATCH 9/9] Removed options page; Chrome has option built-in. --- MarmoUI-Chrome/background/init.js | 12 ----- MarmoUI-Chrome/manifest.json | 12 ++--- MarmoUI-Chrome/options/options.html | 19 -------- MarmoUI-Chrome/options/options.js | 47 ------------------- .../{background => scripts}/notifications.js | 19 +++----- MarmoUI-Chrome/{content => scripts}/script.js | 0 6 files changed, 9 insertions(+), 100 deletions(-) delete mode 100644 MarmoUI-Chrome/background/init.js delete mode 100644 MarmoUI-Chrome/options/options.html delete mode 100644 MarmoUI-Chrome/options/options.js rename MarmoUI-Chrome/{background => scripts}/notifications.js (81%) rename MarmoUI-Chrome/{content => scripts}/script.js (100%) diff --git a/MarmoUI-Chrome/background/init.js b/MarmoUI-Chrome/background/init.js deleted file mode 100644 index dbd7779..0000000 --- a/MarmoUI-Chrome/background/init.js +++ /dev/null @@ -1,12 +0,0 @@ -// Initialize default options -chrome.runtime.onInstalled.addListener(function() { - var defaults = { - showNotifications: { - type: "checkbox", - label: "Display desktop notifications when testing completed", - value: true - } - }; - - localStorage["opts"] = JSON.stringify(defaults); -}); \ No newline at end of file diff --git a/MarmoUI-Chrome/manifest.json b/MarmoUI-Chrome/manifest.json index d265909..e548181 100644 --- a/MarmoUI-Chrome/manifest.json +++ b/MarmoUI-Chrome/manifest.json @@ -13,19 +13,13 @@ "content_scripts": [ { "matches": ["https://marmoset.student.cs.uwaterloo.ca/*"], - "js": ["content/script.js"] + "js": ["scripts/script.js"] } ], "background": { "persistent": false, - "scripts": ["background/notifications.js", "background/init.js"] + "scripts": ["scripts/notifications.js"] }, - "permissions": ["notifications"], - - "options_page": "options/options.html", - "options_ui": { - "page": "options/options.html", - "chrome_style": true - } + "permissions": ["notifications"] } \ No newline at end of file diff --git a/MarmoUI-Chrome/options/options.html b/MarmoUI-Chrome/options/options.html deleted file mode 100644 index d46c688..0000000 --- a/MarmoUI-Chrome/options/options.html +++ /dev/null @@ -1,19 +0,0 @@ - - - - MarmoUI Options - - - - -
- -
- - - - - \ No newline at end of file diff --git a/MarmoUI-Chrome/options/options.js b/MarmoUI-Chrome/options/options.js deleted file mode 100644 index 813704d..0000000 --- a/MarmoUI-Chrome/options/options.js +++ /dev/null @@ -1,47 +0,0 @@ -// Load Options -var opts = JSON.parse(localStorage["opts"]); - -// Saves options to chrome.storage.sync. -function save_options() { - - for(var id in opts) { - var el = document.getElementById(id); - if(opts[id].type == 'checkbox') { - opts[id].value = el.checked; - } - } - - localStorage["opts"] = JSON.stringify(opts); - - // Update status to let user know options were saved. - var status = document.getElementById('status'); - status.textContent = 'Options saved.'; - setTimeout(function() { - status.textContent = ''; - }, 1200); -} - -// Restores options stored in localStorage -function restore_options() { - - var optsEl = document.getElementById('options'); - for(var id in opts) { - var opt = opts[id]; - if(opt.type == 'checkbox') { - // Create checkbox - var checkbox = document.createElement('input'); - checkbox.setAttribute('type', 'checkbox'); - checkbox.id = id; - checkbox.checked = opt.value; - optsEl.appendChild(checkbox); - // Create Label - var label = document.createElement('label'); - label.setAttribute('for', id); - label.textContent = opt.label + "\n"; - optsEl.appendChild(label); - } - } -} -document.addEventListener('DOMContentLoaded', restore_options); -document.getElementById('save').addEventListener('click', - save_options); \ No newline at end of file diff --git a/MarmoUI-Chrome/background/notifications.js b/MarmoUI-Chrome/scripts/notifications.js similarity index 81% rename from MarmoUI-Chrome/background/notifications.js rename to MarmoUI-Chrome/scripts/notifications.js index 819dc8b..3140b59 100644 --- a/MarmoUI-Chrome/background/notifications.js +++ b/MarmoUI-Chrome/scripts/notifications.js @@ -2,12 +2,14 @@ var activeNotifications = {}; chrome.runtime.onMessage.addListener(function(request, sender) { - var opts = JSON.parse(localStorage["opts"]); - if (request.type == "notification" && opts.showNotifications.value) { + if (request.type == "notification") { // Check if we have permission chrome.notifications.getPermissionLevel(function(level) { - if(level == "denied") return; + if(level == "denied") { + console.warn("Notification suppressed; Permission denied.") + return; + } chrome.windows.get(sender.tab.windowId, function(win) { // Don't show notification if user is still on marmoset @@ -74,16 +76,7 @@ function focusMarmoUI(notificationId) { chrome.notifications.clear(notificationId, function() {}); } -// Opens the options page -function openOptions() { - chrome.tabs.create({url: 'chrome://extensions/?options=' + chrome.runtime.id}, function(tab) { - // Bring window to focus - chrome.windows.update(tab.windowId, {focused:true}, function() {}); - }); -} - // Registering listeners chrome.notifications.onButtonClicked.addListener(openResults) chrome.notifications.onClosed.addListener(notificationDeactivated); -chrome.notifications.onClicked.addListener(focusMarmoUI); -chrome.notifications.onShowSettings.addListener(openOptions); \ No newline at end of file +chrome.notifications.onClicked.addListener(focusMarmoUI); \ No newline at end of file diff --git a/MarmoUI-Chrome/content/script.js b/MarmoUI-Chrome/scripts/script.js similarity index 100% rename from MarmoUI-Chrome/content/script.js rename to MarmoUI-Chrome/scripts/script.js