aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormrmr19932014-07-28 16:41:15 +0100
committermrmr19932014-11-02 06:25:40 +0000
commit474bcb7552dd538978e546f02b2bff1d7204aa34 (patch)
treedcadd33b50bc182476e223f870d84a70cf5fb91a
parent002f48e9e7b821debeb96920050705c9a6ce09b9 (diff)
downloadvimium-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.
-rw-r--r--pages/blank.html13
-rw-r--r--pages/content_script_loader.coffee28
-rw-r--r--pages/options.html11
3 files changed, 31 insertions, 21 deletions
diff --git a/pages/blank.html b/pages/blank.html
index 1f8bb1d0..aa9e762a 100644
--- a/pages/blank.html
+++ b/pages/blank.html
@@ -1,16 +1,7 @@
<html>
<head>
- <script src="../lib/utils.js"></script>
- <script src="../lib/keyboard_utils.js"></script>
- <script src="../lib/dom_utils.js"></script>
- <script src="../lib/handler_stack.js"></script>
- <script src="../lib/clipboard.js"></script>
- <script src="../content_scripts/link_hints.js"></script>
- <script src="../content_scripts/vomnibar.js"></script>
- <script src="../content_scripts/scroller.js"></script>
- <script src="../content_scripts/vimium_frontend.js"></script>
-
- <link rel="stylesheet" type="text/css" href="../content_scripts/vimium.css" />
+ <title>New Tab Page</title>
+ <script src="content_script_loader.js"></script>
</head>
<body>
</body>
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()
diff --git a/pages/options.html b/pages/options.html
index 93033a3f..c3d3a4d0 100644
--- a/pages/options.html
+++ b/pages/options.html
@@ -1,15 +1,7 @@
<html>
<head>
<title>Vimium Options</title>
- <script src="../lib/utils.js"></script>
- <script src="../lib/keyboard_utils.js"></script>
- <script src="../lib/dom_utils.js"></script>
- <script src="../lib/handler_stack.js"></script>
- <script src="../lib/clipboard.js"></script>
- <script src="../content_scripts/link_hints.js"></script>
- <script src="../content_scripts/vomnibar.js"></script>
- <script src="../content_scripts/scroller.js"></script>
- <script src="../content_scripts/vimium_frontend.js"></script>
+ <script src="content_script_loader.js"></script>
<style type="text/css" media="screen">
body {
font: 14px "DejaVu Sans", "Arial", sans-serif;
@@ -199,7 +191,6 @@
margin-right: 0px;
}
</style>
- <link rel="stylesheet" type="text/css" href="../content_scripts/vimium.css" />
<script type="text/javascript" src="options.js"></script>