var refreshTimer = null; var isFetching = null; var storedEvents = new Array(); var notVisited = {}; $(window).on('load', function() { initilise(); // Wait some ms to throw main function var delay = setTimeout(main, 100); resetInterval(); }); function fetchEvents() { return storedEvents; } function fetchNotVisited() { return notVisited; } function removeNotVisited(eventId) { if (notVisited[eventId] === true) delete notVisited[eventId]; } function main() { chrome.runtime.sendMessage({text: "FETCH_EVENTS"}); // Do not fetch if is fetching now if (isFetching) return; isFetching = true; var feedUrl = localStorage["ip_address"]+'/include/api.php?op=get&op2=events&return_type=json&apipass='+localStorage["api_pass"]+'&user='+localStorage["user_name"]+'&pass='+localStorage["pass"]; req = new XMLHttpRequest(); req.onload = handleResponse; req.onerror = handleError; req.open("GET", feedUrl, true); req.withCredentials = true req.send(null); } function handleError() { chrome.runtime.sendMessage({text: "FETCH_EVENTS_URL_ERROR"}); isFetching = false; } function handleResponse() { var doc = req.responseText; if (doc=="auth error") { chrome.runtime.sendMessage({text: "FETCH_EVENTS_URL_ERROR"}); } else { var n = doc.search("404 Not Found"); if (n>0) { chrome.runtime.sendMessage({text: "FETCH_EVENTS_DATA_ERROR"}); } else { getEvents(doc); chrome.runtime.sendMessage({text: "FETCH_EVENTS_SUCCESS"}); } } isFetching = false; } function getEvents(reply){ var fetchedEvents = parseReplyEvents(reply); // If there is no events requested, mark all as visited if (storedEvents.length == 0) { notVisited = {}; storedEvents = fetchedEvents; return; } // Discriminate the new events newEvents=fetchNewEvents(fetchedEvents,storedEvents); var newNotVisited = {}; var notVisitedCount = 0; // Check if popup is displayed to make some actions var views = chrome.extension.getViews({ type: "popup" }); for(var k=0;k