flash badge

This commit is contained in:
Sriram Hariharan
2019-01-15 13:42:21 -06:00
parent 147fef3d07
commit ce709cbec4
7 changed files with 40 additions and 43 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View File

@@ -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 +"

View File

@@ -155,11 +155,8 @@ $(function () {
}
});
updateCalendar();
chrome.browserAction.setBadgeBackgroundColor({
color: '#bf5700'
});
chrome.browserAction.setBadgeText({
text: ""
chrome.runtime.sendMessage({
command: "updateBadge"
});
});

View File

@@ -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");