Created
March 11, 2018 15:56
-
-
Save gbaptista/983437d50e5450e75af8d2fbe6fa3112 to your computer and use it in GitHub Desktop.
Luminous contentScripts.register demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var update_content_script_settings = function() { | |
// contentScripts.register not available | |
} | |
if(typeof browser !== 'undefined' && browser.contentScripts) { | |
var registered_content_scripts = []; | |
async function register_content_script(data, i) { | |
registered_content_scripts[i] = await browser.contentScripts.register({ | |
runAt: 'document_start', | |
matches: ['<all_urls>'], | |
allFrames: true, | |
js: [{ | |
code: "var luminous_settings = JSON.parse('" + JSON.stringify(data) + "'); intialize_luminous_injections('content_scripts_register');" | |
}] | |
}); | |
} | |
update_content_script_settings = function(data) { | |
var pending = false; | |
for(i in registered_content_scripts) { | |
if(!registered_content_scripts[i]) { | |
pending = true; | |
} else if(registered_content_scripts[i] != 'unregistered') { | |
registered_content_scripts[i].unregister(); | |
registered_content_scripts[i] = 'unregistered'; | |
} | |
} | |
if(!pending) { | |
registered_content_scripts = []; | |
} | |
registered_content_scripts.push(null); | |
register_content_script(data, registered_content_scripts.length - 1); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var update_cached_settings = function() { | |
chrome.storage.sync.get(null, function(sync_data) { | |
if(sync_data) { | |
settings_defined = true; | |
cached_settings = sync_data; | |
update_content_script_settings(cached_settings['injection_disabled']); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment