aboutsummaryrefslogtreecommitdiffstats
path: root/pages/content_script_loader.coffee
blob: 5058bb7b2c5d7c48cda80ea1f990858d90a75160 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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()