making it work.
This commit is contained in:
22
build.js
22
build.js
@@ -5,22 +5,16 @@ const alias = require('esbuild-plugin-alias')
|
|||||||
|
|
||||||
esbuild.build({
|
esbuild.build({
|
||||||
bundle: true,
|
bundle: true,
|
||||||
entryPoints: ['./extension/options.js'],
|
entryPoints: {
|
||||||
outfile: './extension/options.build.js',
|
'options.build': './extension/options.js',
|
||||||
|
'content-script.build': './extension/content-script.js',
|
||||||
|
'background.build': './extension/background.js'
|
||||||
|
},
|
||||||
|
outdir: './extension',
|
||||||
plugins: [
|
plugins: [
|
||||||
alias({
|
alias({
|
||||||
stream: require.resolve('readable-stream')
|
stream: require.resolve('readable-stream')
|
||||||
})
|
})
|
||||||
]
|
],
|
||||||
})
|
sourcemap: 'inline'
|
||||||
|
|
||||||
esbuild.build({
|
|
||||||
bundle: true,
|
|
||||||
entryPoints: ['./extension/background.js'],
|
|
||||||
outfile: './extension/background.build.js',
|
|
||||||
plugins: [
|
|
||||||
alias({
|
|
||||||
stream: require.resolve('readable-stream')
|
|
||||||
})
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
|
import browser from 'webextension-polyfill'
|
||||||
|
|
||||||
// inject the script that will provide window.nostr
|
// inject the script that will provide window.nostr
|
||||||
let script = document.createElement('script')
|
let script = document.createElement('script')
|
||||||
script.src = 'nostr-provider.js'
|
script.setAttribute('async', 'false')
|
||||||
|
script.setAttribute('type', 'text/javascript')
|
||||||
|
script.setAttribute('src', browser.runtime.getURL('nostr-provider.js'))
|
||||||
document.head.appendChild(script)
|
document.head.appendChild(script)
|
||||||
|
|
||||||
// listen for messages from that script
|
// listen for messages from that script
|
||||||
|
|||||||
@@ -13,12 +13,13 @@
|
|||||||
"content_scripts": [{
|
"content_scripts": [{
|
||||||
"matches": ["<all_urls>"],
|
"matches": ["<all_urls>"],
|
||||||
"js": [
|
"js": [
|
||||||
"content-script.js"
|
"content-script.build.js"
|
||||||
]
|
]
|
||||||
}],
|
}],
|
||||||
"permissions": [
|
"permissions": [
|
||||||
"activeTab",
|
"activeTab",
|
||||||
"storage"
|
"storage"
|
||||||
],
|
],
|
||||||
|
"web_accessible_resources": ["nostr-provider.js"],
|
||||||
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self';"
|
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self';"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ window.nostr = {
|
|||||||
window.addEventListener('message', message => {
|
window.addEventListener('message', message => {
|
||||||
if (
|
if (
|
||||||
!message.data ||
|
!message.data ||
|
||||||
|
!message.data.response ||
|
||||||
message.data.ext !== 'nos2x' ||
|
message.data.ext !== 'nos2x' ||
|
||||||
!window.nostr._requests[message.data.id]
|
!window.nostr._requests[message.data.id]
|
||||||
)
|
)
|
||||||
|
|||||||
1041
extension/options.build.js.js
Normal file
1041
extension/options.build.js.js
Normal file
File diff suppressed because it is too large
Load Diff
@@ -3,9 +3,14 @@
|
|||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<title>nos2x</title>
|
<title>nos2x</title>
|
||||||
|
|
||||||
|
<h1>nos2x</h1>
|
||||||
|
<p>nostr signer extension</p>
|
||||||
|
|
||||||
<label>
|
<label>
|
||||||
Private Key:
|
private key:
|
||||||
<input id="privateKeyInput" />
|
<input id="privateKeyInput" />
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
|
<div id="message"></div>
|
||||||
|
|
||||||
<script src="options.build.js"></script>
|
<script src="options.build.js"></script>
|
||||||
|
|||||||
@@ -2,14 +2,26 @@
|
|||||||
|
|
||||||
import browser from 'webextension-polyfill'
|
import browser from 'webextension-polyfill'
|
||||||
|
|
||||||
document.getElementById('privateKeyInput').addEventListener('input', ev => {
|
document
|
||||||
browser.storage.local
|
.getElementById('privateKeyInput')
|
||||||
.set({private_key: document.getElementById('privateKeyInput').value})
|
.addEventListener('input', async ev => {
|
||||||
.then(() => {
|
try {
|
||||||
console.log('success')
|
await browser.storage.local.set({
|
||||||
})
|
private_key: document.getElementById('privateKeyInput').value
|
||||||
})
|
})
|
||||||
|
showMessage('saved!')
|
||||||
|
} catch (err) {
|
||||||
|
showMessage(`error! ${err}`)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
browser.storage.local.get('private_key').then(results => {
|
browser.storage.local.get('private_key').then(results => {
|
||||||
document.getElementById('privateKeyInput').value = results.private_key
|
document.getElementById('privateKeyInput').value = results.private_key
|
||||||
})
|
})
|
||||||
|
|
||||||
|
function showMessage(str) {
|
||||||
|
document.getElementById('message').innerHTML = str
|
||||||
|
setTimeout(() => {
|
||||||
|
document.getElementById('message').innerHTML = ''
|
||||||
|
}, 5000)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user