diff --git a/icons/icon128.png b/icons/icon128.png index 2596067a..a875bcb4 100644 Binary files a/icons/icon128.png and b/icons/icon128.png differ diff --git a/icons/icon16.png b/icons/icon16.png index b81e4475..ac603ca6 100644 Binary files a/icons/icon16.png and b/icons/icon16.png differ diff --git a/icons/icon32.png b/icons/icon32.png index ba29380e..5f245778 100644 Binary files a/icons/icon32.png and b/icons/icon32.png differ diff --git a/icons/icon48.png b/icons/icon48.png index fcd2e098..acda2012 100644 Binary files a/icons/icon48.png and b/icons/icon48.png differ diff --git a/js/background.js b/js/background.js index 0fce7c16..67c31b1c 100644 --- a/js/background.js +++ b/js/background.js @@ -1,13 +1,4 @@ -chrome.storage.sync.get('savedCourses', function (data) { - if (data.savedCourses && data.savedCourses.length) { - chrome.browserAction.setBadgeBackgroundColor({ - color: '#bf5700' - }); - chrome.browserAction.setBadgeText({ - text: "" + data.savedCourses.length - }); - } -}); +updateBadge(true); /* Handle messages and their commands from content and popup scripts*/ chrome.runtime.onMessage.addListener(function (request, sender, response) { switch (request.command) { @@ -25,6 +16,9 @@ chrome.runtime.onMessage.addListener(function (request, sender, response) { case "checkConflicts": checkConflicts(response); break; + case "updateBadge": + updateBadge(); + break; case "updateStatus": updateStatus(response); break; @@ -90,6 +84,34 @@ chrome.runtime.onInstalled.addListener(function (details) { } }); + +function updateBadge(first) { + chrome.storage.sync.get('savedCourses', function (data) { + if (data.savedCourses) { + let text = ""; + if (data.savedCourses.length > 0) { + text += data.savedCourses.length + } + chrome.browserAction.setBadgeText({ + text: text + }); + let timeout = 0; + if (!first) { + chrome.browserAction.setBadgeBackgroundColor({ + color: '#FF5722' + }); + timeout = 200; + } + setTimeout(function () { + chrome.browserAction.setBadgeBackgroundColor({ + color: '#bf5700' + }); + }, timeout); + + } + }); +} + /* Find all the conflicts in the courses and send them out/ if there is even a conflict*/ function checkConflicts(sendResponse) { chrome.storage.sync.get('savedCourses', function (data) { @@ -172,12 +194,7 @@ function add(request, sender, sendResponse) { savedCourses: courses }); } - chrome.browserAction.setBadgeBackgroundColor({ - color: '#bf5700' - }); - chrome.browserAction.setBadgeText({ - text: "" + courses.length - }); + updateBadge(); sendResponse({ done: "Added: (" + request.course.unique + ") " + request.course.coursename, label: "Remove Course -" @@ -197,18 +214,7 @@ function remove(request, sender, sendResponse) { chrome.storage.sync.set({ savedCourses: courses }); - chrome.browserAction.setBadgeBackgroundColor({ - color: '#bf5700' - }); - if (courses.length > 0) { - chrome.browserAction.setBadgeText({ - text: "" + courses.length - }); - } else { - chrome.browserAction.setBadgeText({ - text: "" - }); - } + updateBadge(); sendResponse({ done: "Removed: (" + request.course.unique + ") " + request.course.coursename, label: "Add Course +" diff --git a/js/calendar.js b/js/calendar.js index fe33680b..7d5d8e03 100644 --- a/js/calendar.js +++ b/js/calendar.js @@ -155,11 +155,8 @@ $(function () { } }); updateCalendar(); - chrome.browserAction.setBadgeBackgroundColor({ - color: '#bf5700' - }); - chrome.browserAction.setBadgeText({ - text: "" + chrome.runtime.sendMessage({ + command: "updateBadge" }); }); diff --git a/js/popup.js b/js/popup.js index c3241c04..9af99048 100644 --- a/js/popup.js +++ b/js/popup.js @@ -306,11 +306,8 @@ $("#importOrig").change(function (e) { chrome.storage.sync.set({ savedCourses: impCourses }); - chrome.browserAction.setBadgeBackgroundColor({ - color: '#bf5700' - }); - chrome.browserAction.setBadgeText({ - text: "" + impCourses.length + chrome.runtime.sendMessage({ + command: "updateBadge" }); chrome.tabs.query({}, function (tabs) { for (var i = 0; i < tabs.length; i++) { @@ -423,11 +420,8 @@ function clear() { }); } }); - chrome.browserAction.setBadgeBackgroundColor({ - color: '#bf5700' - }); - chrome.browserAction.setBadgeText({ - text: "" + chrome.runtime.sendMessage({ + command: "updateBadge" }); $("#courseList").empty() console.log("cleared");