Skip to content

Commit

Permalink
update injectScript to return a promise
Browse files Browse the repository at this point in the history
  • Loading branch information
starpit committed Jul 29, 2018
1 parent 0b870a3 commit ff714d3
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions app/content/js/ui.js
Expand Up @@ -1791,16 +1791,24 @@ const ui = (function() {
* Inject a script
*
*/
self.injectScript = url => {
self.injectScript = url => new Promise((resolve, reject) => {
const type = 'script'
const id = `injected-${type}-${url}`

if (!document.getElementById(id)) {
var link = document.createElement('script')
link.id = id
link.src = url

link.async = true
link.addEventListener('load', () => {
debug('injected script', url, id, link)
resolve()
})

document.getElementsByTagName('head')[0].appendChild(link);
}
}
})

/**
* Inject HTML stored in the given local file
Expand Down

0 comments on commit ff714d3

Please sign in to comment.