1
0
Fork 0
This repository has been archived on 2024-06-28. You can view files and clone it, but cannot push or open issues or pull requests.
matomo-injector/js/api.js
2017-08-25 22:50:13 +02:00

30 lines
867 B
JavaScript

chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
var website = location.protocol + '//' + location.host;
switch (request.method) {
case 'setData':
var syncdata = {};
syncdata[website] = request.customjs;
chrome.storage.sync.set(syncdata);
break;
case 'getData':
chrome.storage.sync.get(website, function(obj) {
var customjs = obj[website] || JSON.parse('false');
sendResponse({customjs: customjs, host: location.host, protocol: location.protocol});
});
break;
case 'removeData':
chrome.storage.sync.remove(website, function() {
});
break;
case 'goTo':
window.location = request.link;
break;
default:
sendResponse({src: '', config: {}});
}
if (request.reload) {
window.location.reload();
}
return true;
});