-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
31 lines (28 loc) · 987 Bytes
/
background.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* global chrome: false, Settings: false, Utilities: false */
/**
* Possible parameters for request:
* action: "beacon" for a cross-origin beacon HTTP request,
* "get-selectors" for getting selectors from the
* server
* url : required, but not validated
* data : data to send in a POST request
*
* The callback function is called upon completion of the request */
chrome.runtime.onMessage.addListener(function(request, sender, callback) {
'use strict';
if (request.action === 'beacon') {
var jsonData = JSON.stringify(request.data);
var sendBeacon = sendBeacon in navigator ? navigator.sendBeacon :
Utilities.sendBeacon;
var success = sendBeacon(request.url, jsonData);
callback(success);
return true;
}
if (request.action === 'get-selectors') {
$.getJSON(
Settings.Selectors + request.engine,
function(data) { callback(data); }
);
return true;
}
});