Display not visited events bold on chrome extension

This commit is contained in:
fermin831 2017-11-28 10:36:38 +01:00
parent 5c9822111d
commit 76dfd3cfa0
2 changed files with 49 additions and 15 deletions

View File

@ -1,6 +1,7 @@
var refreshTimer = null; var refreshTimer = null;
var isFetching = null; var isFetching = null;
var storedEvents=new Array(); var storedEvents = new Array();
var notVisited = {};
$(window).load(function() { $(window).load(function() {
initilise(); initilise();
@ -13,6 +14,13 @@ function fetchEvents() {
return storedEvents; return storedEvents;
} }
function fetchNotVisited() {
return notVisited;
}
function removeNotVisited(eventId) {
if (notVisited[eventId] === true) delete notVisited[eventId];
}
function main() { function main() {
@ -55,31 +63,43 @@ function getEvents(reply){
// If there is no events requested, mark all as visited // If there is no events requested, mark all as visited
if (storedEvents.length == 0) { if (storedEvents.length == 0) {
for(var k=0;k<fetchedEvents.length;k++){ notVisited = {};
fetchedEvents[k]['visited'] = true;
}
storedEvents = fetchedEvents; storedEvents = fetchedEvents;
return; return;
} }
// Discriminate the new events // Discriminate the new events
newEvents=fetchNewEvents(fetchedEvents,storedEvents); newEvents=fetchNewEvents(fetchedEvents,storedEvents);
var newNotVisited = {};
var notVisitedCount = 0;
// Display the notifications only if popup is not showing // Check if popup is displayed to make some actions
var views = chrome.extension.getViews({ type: "popup" }); var views = chrome.extension.getViews({ type: "popup" });
if (views.length == 0) { for(var k=0;k<newEvents.length;k++){
for(var k=0;k<newEvents.length;k++){ newNotVisited[newEvents[k]['id']] = true;
localStorage["new_events"]++; if (views.length == 0) {
notVisitedCount++;
displayNotification (newEvents[k]) displayNotification (newEvents[k])
alertsSound(newEvents[k]); alertsSound(newEvents[k]);
} }
} else {
localStorage["new_events"] = 0;
} }
storedEvents = fetchedEvents; // Make that the old events marked as not visited remains with the
// same status
for(var k=0;k<fetchedEvents.length;k++){
if (notVisited[fetchedEvents[k]['id']] === true) {
newNotVisited[fetchedEvents[k]['id']] = true;
notVisitedCount++;
}
}
notVisited = newNotVisited;
// Update the number
localStorage["new_events"] = (views.length == 0) ? notVisitedCount : 0;
updateBadge(); updateBadge();
// Store the requested events
storedEvents = fetchedEvents;
} }
function updateBadge() { function updateBadge() {

View File

@ -69,7 +69,8 @@ function showEvents(){
if(e_refr){ if(e_refr){
wrapper.removeChild(e_refr); wrapper.removeChild(e_refr);
} }
var allEvents=bg.fetchEvents(); var allEvents = bg.fetchEvents();
var notVisitedEvents = bg.fetchNotVisited();
var eve=document.createElement('div'); var eve=document.createElement('div');
eve.id="event_temp"; eve.id="event_temp";
eve.setAttribute("class","b"); eve.setAttribute("class","b");
@ -83,7 +84,7 @@ function showEvents(){
img.width = '9'; img.width = '9';
img.height='9'; img.height='9';
img.className ='pm'; img.className ='pm';
img.id='i_' + i; img.id='i_' + i + '_' + allEvents[i]['id'];
eve_title.appendChild(img); eve_title.appendChild(img);
var a = document.createElement('a'); var a = document.createElement('a');
var temp_style; var temp_style;
@ -118,6 +119,10 @@ function showEvents(){
break; break;
} }
if (notVisitedEvents[allEvents[i]['id']] === true) {
eve_title.style.fontWeight = 600;
}
eve_title.appendChild(a); eve_title.appendChild(a);
eve.appendChild(eve_title); eve.appendChild(eve_title);
var b = document.createElement('br'); var b = document.createElement('br');
@ -152,8 +157,17 @@ function showEvents(){
function showHide() { function showHide() {
var id = $(this).attr('id'); var id = $(this).attr('id');
var num = id.split("_")[1]; // Image id has the form i_<position>_<eventId>
var pid = "p_" + num; var nums = id.split('_');
var pid = "p_" + nums[1];
// Mark as visited if visited
if($(this).parent().css('font-weight') == '600') {
bg.removeNotVisited(nums[2]);
$(this).parent().css('font-weight', '');
}
// Toggle information
if($('#' + pid).css('display') == 'none') { if($('#' + pid).css('display') == 'none') {
$('#' + pid).slideDown("fast"); $('#' + pid).slideDown("fast");
$(this).attr({src: 'images/minus.gif'}); $(this).attr({src: 'images/minus.gif'});