2013-02-07 02:43:14 +04:00
|
|
|
self.port.on('log', function log(arguments){
|
|
|
|
if (unsafeWindow && unsafeWindow.console){
|
|
|
|
unsafeWindow.console.log.call(unsafeWindow, arguments);
|
|
|
|
}else{
|
|
|
|
console.log('cannot call browser logging: ' + unsafeWindow);
|
|
|
|
}
|
|
|
|
});
|
2013-01-25 04:35:44 +04:00
|
|
|
|
2013-02-07 02:43:14 +04:00
|
|
|
self.port.on('connection', function(connection){
|
|
|
|
if (unsafeWindow && unsafeWindow.currentVisualization){
|
2013-05-29 21:30:16 +04:00
|
|
|
unsafeWindow.allConnections.push(connection);
|
2013-05-30 21:13:17 +04:00
|
|
|
unsafeWindow.currentVisualization.emit('connection', connection);
|
2013-02-07 02:43:14 +04:00
|
|
|
}else{
|
|
|
|
console.log('cannot call unsafeWindow.currentVisualization: ' + unsafeWindow);
|
|
|
|
}
|
|
|
|
});
|
2013-01-25 04:35:44 +04:00
|
|
|
|
2013-05-31 05:02:30 +04:00
|
|
|
self.port.on('init', function(collusionToken){
|
2013-07-09 06:03:20 +04:00
|
|
|
console.error('content-script::init()');
|
2013-05-31 05:02:30 +04:00
|
|
|
localStorage.collusionToken = collusionToken;
|
|
|
|
|
2013-02-07 02:43:14 +04:00
|
|
|
if (unsafeWindow && unsafeWindow.currentVisualization){
|
2013-06-17 23:38:35 +04:00
|
|
|
unsafeWindow.allConnections = getAllConnections();
|
2013-05-31 03:51:57 +04:00
|
|
|
unsafeWindow.currentVisualization.emit('init', unsafeWindow.allConnections);
|
2013-02-07 02:43:14 +04:00
|
|
|
}else{
|
2013-07-09 06:03:20 +04:00
|
|
|
console.error('cannot call unsafeWindow.currentVisualization: ' + unsafeWindow);
|
2013-02-07 02:43:14 +04:00
|
|
|
}
|
2013-01-25 04:35:44 +04:00
|
|
|
});
|
|
|
|
|
2013-06-14 02:40:22 +04:00
|
|
|
|
2013-06-14 04:49:22 +04:00
|
|
|
self.port.on("passTempConnections", function(connReceived){
|
|
|
|
// connReceived can be an empty array [] or an array of connection arrays [ [], [], [] ]
|
|
|
|
localStorage.tempConnections = JSON.stringify(connReceived);
|
2013-06-04 04:04:21 +04:00
|
|
|
self.port.emit("tempConnectionTransferred", true);
|
2013-05-31 01:10:53 +04:00
|
|
|
|
2013-06-12 01:05:53 +04:00
|
|
|
localStorage.lastSaved = Date.now();
|
2013-06-17 23:38:35 +04:00
|
|
|
|
|
|
|
var nonPrivateConnections = connReceived.filter(function(connection){
|
2013-06-17 22:46:59 +04:00
|
|
|
return (connection[unsafeWindow.FROM_PRIVATE_MODE] == null);
|
2013-06-14 04:49:22 +04:00
|
|
|
});
|
2013-06-18 00:13:08 +04:00
|
|
|
unsafeWindow.saveConnectionsByDate(nonPrivateConnections);
|
2013-06-04 04:04:21 +04:00
|
|
|
localStorage.totalNumConnections = unsafeWindow.allConnections.length;
|
2013-05-29 21:30:16 +04:00
|
|
|
});
|
|
|
|
|
2013-05-31 01:10:53 +04:00
|
|
|
|
2013-06-17 23:38:35 +04:00
|
|
|
function getAllConnections(){
|
|
|
|
var allConnectionsAsArray = [];
|
2013-06-18 00:08:27 +04:00
|
|
|
Object.keys(localStorage).sort().forEach(function(key){
|
|
|
|
if ( key.charAt(0) == "2" ){ // date keys are in the format of yyyy-mm-dd
|
|
|
|
var conns = JSON.parse(localStorage.getItem(key));
|
2013-06-17 23:38:35 +04:00
|
|
|
allConnectionsAsArray = allConnectionsAsArray.concat(conns);
|
2013-06-18 00:08:27 +04:00
|
|
|
}
|
|
|
|
});
|
2013-06-17 23:38:35 +04:00
|
|
|
return allConnectionsAsArray;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-07 02:43:14 +04:00
|
|
|
unsafeWindow.addon = self.port;
|