basic functionality, untested.

This commit is contained in:
fiatjaf
2022-01-10 14:11:49 -03:00
parent 853a2b304b
commit 88a2dd806d
11 changed files with 156 additions and 23 deletions

View File

@@ -6,19 +6,20 @@ 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') {
if (!ev.data || ev.data.ext !== 'nos2x') {
// pass on to background
var reply
var response
try {
reply = browser.runtime.sendMessage({
...ev.data,
response = browser.runtime.sendMessage({
type: ev.data.type,
params: ev.data.params,
host: window.location.host
})
} catch (error) {
reply = {error}
response = {error}
}
// return response
window.postMessage({id: ev.data.id, reply})
window.postMessage({id: ev.data.id, ext: 'nos2x', response})
}
})