From 474bcb7552dd538978e546f02b2bff1d7204aa34 Mon Sep 17 00:00:00 2001
From: mrmr1993
Date: Mon, 28 Jul 2014 16:41:15 +0100
Subject: 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.
---
pages/blank.html | 13 ++-----------
pages/content_script_loader.coffee | 28 ++++++++++++++++++++++++++++
pages/options.html | 11 +----------
3 files changed, 31 insertions(+), 21 deletions(-)
create mode 100644 pages/content_script_loader.coffee
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 @@
-
-
-
-
-
-
-
-
-
-
-
+ New Tab Page
+
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("") == -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 @@
Vimium Options
-
-
-
-
-
-
-
-
-
+
-
--
cgit v1.2.3