Splited run and api part of content_script (for iframes access)
This commit is contained in:
parent
4e0147fac5
commit
304bae0d62
3 changed files with 31 additions and 27 deletions
24
lib/api.js
Normal file
24
lib/api.js
Normal 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);
|
|
@ -1,4 +1,4 @@
|
|||
(function() {
|
||||
(function() {
|
||||
function injectScript(src, where) {
|
||||
var elm = document.createElement('script');
|
||||
elm.src = src;
|
||||
|
@ -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();
|
||||
}
|
||||
});
|
||||
|
||||
})();
|
|
@ -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"]
|
||||
"matches": ["<all_urls>"],
|
||||
"js": ["lib/run.js"]
|
||||
}],
|
||||
|
||||
"browser_action": {
|
||||
|
|
Reference in a new issue