Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //js/get_var.js
- setTimeout(function() {
- var info = false;
- if (window.mySummaryPrefix) {
- info = {mySummaryPrefix:mySummaryPrefix}
- }
- document.dispatchEvent(new CustomEvent('my_event_connectExtension', {
- detail: info
- }));
- }, 0);
- ...
- "web_accessible_resources": ["js/get_var.js"]
- ...
- //content_script.js
- function askForValue(){
- var scriptTag = document.createElement('script');
- scriptTag.src = chrome.extension.getURL('js/get_var.js');
- (document.head||document.documentElement).appendChild(scriptTag);
- scriptTag.onload = function() {
- scriptTag.parentNode.removeChild(scriptTag);
- };
- }
- document.addEventListener('my_event_connectExtension', function(e) {
- if (e.detail) {
- var info = e.detail && {'info': e.detail} || false;
- console.log(info);
- }
- });
- document.addEventListener('DOMContentLoaded', function() {
- askForValue();
- }
- "content_scripts": [{
- "matches": ["https://*/*"], /* your url matchs */
- "js": ["js/content_script.js"]
- }],
- //from popup.js
- ...
- chrome.tabs.getSelected(null, function(tab) {
- chrome.tabs.sendMessage(tab.id, {
- 'action': 'myExtension:myAction'
- }, function(result){
- var info = result && result.info;
- });
- });
- ...
- chrome.runtime.onMessage.addListener(function(request, sender, callback){
- if (request.action === 'myExtension:myAction') { ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement