1
0
Fork 0

Splited run and api part of content_script (for iframes access)

This commit is contained in:
Dan Hromada 2014-05-14 08:36:59 +02:00
parent 4e0147fac5
commit 304bae0d62
3 changed files with 31 additions and 27 deletions

24
lib/api.js Normal file
View file

@ -0,0 +1,24 @@
(function(chrome) {
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
switch(request.method) {
case 'setData':
localStorage['customjs'] = JSON.stringify(request.customjs);
case 'getData':
var customjs = JSON.parse(localStorage['customjs'] || 'false');
sendResponse({customjs: customjs, host: location.host, protocol: location.protocol});
break;
case 'removeData':
delete localStorage['customjs'];
break;
case 'goTo':
window.location = request.link;
break;
default:
sendResponse({src: '', config: {}});
}
if( request.reload ) {
window.location.reload();
}
});
})(chrome);

View file

@ -52,28 +52,4 @@
}
}
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
switch(request.method) {
case 'setData':
localStorage['customjs'] = JSON.stringify(request.customjs);
case 'getData':
var customjs = JSON.parse(localStorage['customjs'] || 'false');
sendResponse({customjs: customjs, host: location.host, protocol: location.protocol});
break;
case 'removeData':
delete localStorage['customjs'];
break;
case 'goTo':
window.location = request.link;
break;
default:
sendResponse({src: '', config: {}});
}
if( request.reload ) {
window.location.reload();
}
});
})();

View file

@ -16,9 +16,13 @@
"content_security_policy": "script-src 'self' https://*.googleapis.com; object-src 'self'",
"content_scripts": [{
//"all_frames": true,
"matches": ["<all_urls>"],
"js": ["lib/api.js"]
}, {
"all_frames": true,
"matches": ["<all_urls>"],
"js": ["lib/script.js"]
"js": ["lib/run.js"]
}],
"browser_action": {