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
|
|
|
|
2015-08-02 05:50:29 +02:00
|
|
|
|
|
|
|
// inject in-page script
|
2015-08-01 03:38:02 +02:00
|
|
|
var scriptTag = document.createElement('script')
|
2015-08-02 05:50:29 +02:00
|
|
|
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-08-02 05:50:29 +02:00
|
|
|
|
2015-12-19 07:05:16 +01:00
|
|
|
// forward communication across
|
|
|
|
pageStream.pipe(pluginStream)
|
|
|
|
pluginStream.pipe(pageStream)
|