Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/extension/src/contentscript.js
const extension = require('extensionizer'); | |||||
// Insert flag into window object to denote CashTab is available and active as a browser extension | // Insert flag into window object to denote CashTab is available and active as a browser extension | ||||
// Could use a div or other approach for now, but emulate MetaMask this way so it is extensible to other items | // Could use a div or other approach for now, but emulate MetaMask this way so it is extensible to other items | ||||
// Try window object approach | // Try window object approach | ||||
var cashTabInject = document.createElement('script'); | var cashTabInject = document.createElement('script'); | ||||
cashTabInject.innerHTML = `window.bitcoinAbc = 'cashtab'`; | cashTabInject.innerHTML = `window.bitcoinAbc = 'cashtab'`; | ||||
document.head.appendChild(cashTabInject); | document.head.appendChild(cashTabInject); | ||||
// Process page messages | // Process page messages | ||||
// Chrome extensions communicate with web pages through the DOM | // Chrome extensions communicate with web pages through the DOM | ||||
// Page sends a message to itself, chrome extension intercepts it | // Page sends a message to itself, chrome extension intercepts it | ||||
var port = chrome.runtime.connect({ name: 'cashtabPort' }); | var port = extension.runtime.connect({ name: 'cashtabPort' }); | ||||
//console.log(`port: ${JSON.stringify(port)}`); | //console.log(`port: ${JSON.stringify(port)}`); | ||||
//console.log(port); | //console.log(port); | ||||
window.addEventListener( | window.addEventListener( | ||||
'message', | 'message', | ||||
function (event) { | function (event) { | ||||
if (typeof event.data.text !== 'undefined') { | if (typeof event.data.text !== 'undefined') { | ||||
console.log('Message received:'); | console.log('Message received:'); | ||||
Show All 14 Lines |