lightbeam/data/content-script.js

59 строки
2.1 KiB
JavaScript
Исходник Обычный вид История

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-02-07 02:43:14 +04:00
self.port.on('connection', function(connection){
if (unsafeWindow && unsafeWindow.currentVisualization){
unsafeWindow.allConnections.push(connection);
unsafeWindow.currentVisualization.emit('connection', connection);
2013-02-07 02:43:14 +04:00
}else{
console.log('cannot call unsafeWindow.currentVisualization: ' + unsafeWindow);
}
});
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){
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
}
});
self.port.on("passTempConnections", function(connReceived){
// connReceived can be an empty array [] or an array of connection arrays [ [], [], [] ]
localStorage.tempConnections = JSON.stringify(connReceived);
self.port.emit("tempConnectionTransferred", true);
localStorage.lastSaved = Date.now();
var nonPrivateConnections = connReceived.filter(function(connection){
return (connection[unsafeWindow.FROM_PRIVATE_MODE] == null);
});
2013-06-18 00:13:08 +04:00
unsafeWindow.saveConnectionsByDate(nonPrivateConnections);
localStorage.totalNumConnections = unsafeWindow.allConnections.length;
});
function getAllConnections(){
var allConnectionsAsArray = [];
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));
allConnectionsAsArray = allConnectionsAsArray.concat(conns);
}
});
return allConnectionsAsArray;
}
2013-02-07 02:43:14 +04:00
unsafeWindow.addon = self.port;