skeleton.
This commit is contained in:
24
extension/content-script.js
Normal file
24
extension/content-script.js
Normal file
@@ -0,0 +1,24 @@
|
||||
// inject the script that will provide window.nostr
|
||||
let script = document.createElement('script')
|
||||
script.src = 'nostr-provider.js'
|
||||
document.head.appendChild(script)
|
||||
|
||||
// listen for messages from that script
|
||||
window.addEventListener('message', async ev => {
|
||||
if (ev.source !== window) return
|
||||
if (!ev.data || ev.data.ext !== 'nostr') {
|
||||
// pass on to background
|
||||
var reply
|
||||
try {
|
||||
reply = browser.runtime.sendMessage({
|
||||
...ev.data,
|
||||
host: window.location.host
|
||||
})
|
||||
} catch (error) {
|
||||
reply = {error}
|
||||
}
|
||||
|
||||
// return response
|
||||
window.postMessage({id: ev.data.id, reply})
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user