Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save harishvc/eac4094c2d395d9863d7 to your computer and use it in GitHub Desktop.
Save harishvc/eac4094c2d395d9863d7 to your computer and use it in GitHub Desktop.
mapit - background.js (events are added or removed)
//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