mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Clean up extension polyfill abstraction
This commit is contained in:
parent
0880721d84
commit
b07bbc14e1
@ -9,14 +9,19 @@ if (shouldInjectWeb3()) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setupInjection(){
|
function setupInjection(){
|
||||||
|
try {
|
||||||
|
|
||||||
// inject in-page script
|
// inject in-page script
|
||||||
var scriptTag = document.createElement('script')
|
var scriptTag = document.createElement('script')
|
||||||
var urlGetter = extension.extension || chrome.extension
|
scriptTag.src = extension.extension.getURL('scripts/inpage.js')
|
||||||
scriptTag.src = urlGetter.getURL('scripts/inpage.js')
|
|
||||||
scriptTag.onload = function () { this.parentNode.removeChild(this) }
|
scriptTag.onload = function () { this.parentNode.removeChild(this) }
|
||||||
var container = document.head || document.documentElement
|
var container = document.head || document.documentElement
|
||||||
// append as first child
|
// append as first child
|
||||||
container.insertBefore(scriptTag, container.children[0])
|
container.insertBefore(scriptTag, container.children[0])
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Metamask injection failed.', e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupStreams(){
|
function setupStreams(){
|
||||||
|
@ -24,14 +24,9 @@ const apis = [
|
|||||||
|
|
||||||
function Extension () {
|
function Extension () {
|
||||||
const _this = this
|
const _this = this
|
||||||
let global = window
|
|
||||||
|
|
||||||
if (window.chrome) {
|
|
||||||
global = window.chrome
|
|
||||||
}
|
|
||||||
|
|
||||||
apis.forEach(function (api) {
|
apis.forEach(function (api) {
|
||||||
_this[api] = global[api]
|
_this[api] = chrome ? chrome[api] : window[api] || browser.extension[api]
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user