Last active
December 30, 2015 09:45
-
-
Save harishvc/eac4094c2d395d9863d7 to your computer and use it in GitHub Desktop.
mapit - background.js (events are added or removed)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//background.js | |
chrome.runtime.onInstalled.addListener( | |
function () { | |
chrome.alarms.create("gcgmalarm",{when: Date.now() + 10*1000,periodInMinutes: 2}); | |
}); | |
function alarmcount(callback) { | |
var count; | |
chrome.alarms.getAll(function(alarms) { callback(alarms.length) }); | |
} | |
function myDate() { | |
var now = new Date(); | |
var now2 = now.getMonth()+1 + "/" + now.getDate() + "/" + now.getFullYear() + " " + now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds(); | |
return now2; | |
} | |
chrome.alarms.onAlarm.addListener(function (){ AreYouAround();}); | |
function AreYouAround() { | |
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { | |
chrome.tabs.sendMessage(tabs[0].id, {action: "checking", now:myDate()}, function(response) {}); | |
alarmcount(function(count) { | |
var numAlarms = count; | |
var msg = "alarm count=" + numAlarms; | |
chrome.tabs.sendMessage(tabs[0].id, {action: "console",consolelog:msg}, function(response) {}); | |
}); | |
}); | |
}; | |
//content.js | |
//Is the extension working? polling from backend | |
if (msg.action == 'checking') { | |
var t1 = document.getElementsByClassName('lv-location'); | |
var t2 = document.getElementsByClassName('calendar-clicksaver-maplink'); | |
if (DEBUG === true) { console.log(msg.now, ": checking....");} | |
if (t1.length != t2.length){ | |
if (DEBUG === true) { console.log("links missing ... updating DOM");} | |
Start(); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment