diff options
| author | mrmr1993 | 2014-07-28 16:41:15 +0100 |
|---|---|---|
| committer | mrmr1993 | 2014-11-02 06:25:40 +0000 |
| commit | 474bcb7552dd538978e546f02b2bff1d7204aa34 (patch) | |
| tree | dcadd33b50bc182476e223f870d84a70cf5fb91a /pages/content_script_loader.coffee | |
| parent | 002f48e9e7b821debeb96920050705c9a6ce09b9 (diff) | |
| download | vimium-474bcb7552dd538978e546f02b2bff1d7204aa34.tar.bz2 | |
Automatically load content scripts into the options and blank pages
Load all appropriate content scripts by traversing the list in the
manifest. This removes the need to list them manually.
Diffstat (limited to 'pages/content_script_loader.coffee')
| -rw-r--r-- | pages/content_script_loader.coffee | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/pages/content_script_loader.coffee b/pages/content_script_loader.coffee new file mode 100644 index 00000000..5058bb7b --- /dev/null +++ b/pages/content_script_loader.coffee @@ -0,0 +1,28 @@ +injectContentScripts = -> + manifest = chrome.runtime.getManifest() + content_scripts = manifest.content_scripts + + insertLocation = document.head.firstChild + + for scriptInfo in content_scripts + continue if scriptInfo.matches.indexOf("<all_urls>") == -1 + + if scriptInfo.js + for script in scriptInfo.js + scriptElement = document.createElement "script" + scriptElement.type = "text/javascript" + scriptElement.async = false # Don't load out of order! + scriptElement.src = chrome.runtime.getURL script + + insertLocation.parentElement.insertBefore scriptElement, insertLocation + + if scriptInfo.css + for style in scriptInfo.css + styleElement = document.createElement "link" + styleElement.rel = "stylesheet" + styleElement.type = "text/css" + styleElement.href = chrome.runtime.getURL style + + insertLocation.parentElement.insertBefore styleElement, insertLocation + +injectContentScripts() |
