mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
added camera snippet injection to inpage.js
This commit is contained in:
parent
2e50348241
commit
0940ecd57b
@ -5,6 +5,7 @@ const log = require('loglevel')
|
|||||||
const LocalMessageDuplexStream = require('post-message-stream')
|
const LocalMessageDuplexStream = require('post-message-stream')
|
||||||
const setupDappAutoReload = require('./lib/auto-reload.js')
|
const setupDappAutoReload = require('./lib/auto-reload.js')
|
||||||
const MetamaskInpageProvider = require('./lib/inpage-provider.js')
|
const MetamaskInpageProvider = require('./lib/inpage-provider.js')
|
||||||
|
const Instascan = require('instascan')
|
||||||
restoreContextAfterImports()
|
restoreContextAfterImports()
|
||||||
|
|
||||||
log.setDefaultLevel(process.env.METAMASK_DEBUG ? 'debug' : 'warn')
|
log.setDefaultLevel(process.env.METAMASK_DEBUG ? 'debug' : 'warn')
|
||||||
@ -96,3 +97,41 @@ function restoreContextAfterImports () {
|
|||||||
console.warn('MetaMask - global.define could not be overwritten.')
|
console.warn('MetaMask - global.define could not be overwritten.')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function initCameraScanner () {
|
||||||
|
// Append preview div
|
||||||
|
const preview = document.createElement('div')
|
||||||
|
preview.id = 'metamask-preview-wrapper'
|
||||||
|
preview.style = 'position:absolute; top: 20px; left: 20px; z-indez: 99999999999999; width: 300px; height: 300px; overflow: hidden'
|
||||||
|
const previewVideo = document.createElement('video')
|
||||||
|
previewVideo.id = 'metamask-preview-video'
|
||||||
|
previewVideo.style = 'width: 100%; height: 100%; object-fit: none; margin-left: -10%; margin-top: 10%'
|
||||||
|
preview.appendChild(previewVideo)
|
||||||
|
document.body.appendChild(preview)
|
||||||
|
console.log('injected')
|
||||||
|
const scanner = new Instascan.Scanner({
|
||||||
|
video: document.getElementById('metamask-preview-video'),
|
||||||
|
backgroundScan: false,
|
||||||
|
continuous: true,
|
||||||
|
})
|
||||||
|
scanner.addListener('scan', function (content) {
|
||||||
|
alert(content)
|
||||||
|
scanner.stop().then(_ => {
|
||||||
|
document.getElementById('metamask-preview-wrapper').parentElement.removeChild(document.getElementById('metamask-preview-wrapper'))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
Instascan.Camera.getCameras().then(function (cameras) {
|
||||||
|
if (cameras.length > 0) {
|
||||||
|
scanner.start(cameras[1])
|
||||||
|
} else {
|
||||||
|
console.error('No cameras found.')
|
||||||
|
}
|
||||||
|
}).catch(function (e) {
|
||||||
|
console.error(e)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
setTimeout(_ => {
|
||||||
|
console.log('injecting...')
|
||||||
|
initCameraScanner()
|
||||||
|
}, 3000)
|
||||||
|
Loading…
Reference in New Issue
Block a user