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/lib/api.js

29 lines
883 B
JavaScript

(function(chrome) {
chrome.extension.onRequest.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);
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();
}
});
})(chrome);