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);
|
|
@ -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_security_policy": "script-src 'self' https://*.googleapis.com; object-src 'self'",
|
||||||
|
|
||||||
"content_scripts": [{
|
"content_scripts": [{
|
||||||
|
//"all_frames": true,
|
||||||
|
"matches": ["<all_urls>"],
|
||||||
|
"js": ["lib/api.js"]
|
||||||
|
}, {
|
||||||
"all_frames": true,
|
"all_frames": true,
|
||||||
"matches": ["<all_urls>"],
|
"matches": ["<all_urls>"],
|
||||||
"js": ["lib/script.js"]
|
"js": ["lib/run.js"]
|
||||||
}],
|
}],
|
||||||
|
|
||||||
"browser_action": {
|
"browser_action": {
|
||||||
|
|
Reference in a new issue