1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-03 06:34:27 +01:00
metamask-extension/app/scripts/contentscript.js

22 lines
763 B
JavaScript
Raw Normal View History

2015-12-19 07:05:16 +01:00
const LocalMessageDuplexStream = require('./lib/local-message-stream.js')
const PortStream = require('./lib/port-stream.js')
2015-08-02 01:33:31 +02:00
// inject in-page script
2015-08-01 03:38:02 +02:00
var scriptTag = document.createElement('script')
scriptTag.src = chrome.extension.getURL('scripts/inpage.js')
scriptTag.onload = function() { this.parentNode.removeChild(this) }
2015-08-02 01:33:31 +02:00
var container = document.head || document.documentElement
container.appendChild(scriptTag)
2015-12-19 07:05:16 +01:00
// setup communication to page and plugin
var pageStream = new LocalMessageDuplexStream({
name: 'contentscript',
target: 'inpage',
})
2016-01-15 11:03:42 +01:00
var pluginPort = chrome.runtime.connect({name: 'contentscript'})
2015-12-19 07:05:16 +01:00
var pluginStream = new PortStream(pluginPort)
2015-12-19 07:05:16 +01:00
// forward communication across
pageStream.pipe(pluginStream)
pluginStream.pipe(pageStream)