Interface and basic functionality.

Just learning how to make a basic extension. Creating an interface and setting up some basic plumbing.
This commit is contained in:
Ryan Breen
2023-01-11 22:54:50 -05:00
parent 12ccc005c9
commit 210e61c35b
7 changed files with 61 additions and 13 deletions

View File

@@ -1,7 +1,3 @@
browser.runtime.sendMessage({ greeting: "hello" }).then((response) => {
console.log("Received response: ", response);
});
browser.runtime.onMessage.addListener((request, sender, sendResponse) => {
console.log("Received request: ", request);
});
let script = document.createElement('script');
script.setAttribute('src', browser.runtime.getURL('nostr.js'));
document.body.appendChild(script);

View File

@@ -20,7 +20,7 @@
"content_scripts": [{
"js": [ "content.js" ],
"matches": [ "*://example.com/*" ]
"matches": [ "<all_urls>" ]
}],
"action": {
@@ -35,5 +35,12 @@
}
},
"permissions": [ ]
"permissions": [ "storage" ],
"web_accessible_resources": [
{
"resources": ["nostr.js"],
"matches": ["<all_urls>"]
}
]
}

View File

@@ -0,0 +1,14 @@
console.log("hello from nostr module");
window.nostr = {
async getPublicKey() {
console.log("getting public key!");
return "285d4ca25cbe209832aa15a4b94353b877a2fe6c3b94dee1a4c8bc36770304db";
},
async signEvent(event) {
console.log("Signing event");
console.log(event);
return "signed event";
}
}

View File

@@ -3,7 +3,7 @@
}
body {
width: 100px;
width: 500px;
padding: 10px;
font-family: system-ui;

View File

@@ -3,9 +3,14 @@
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="popup.css">
<script type="module" src="popup.js"></script>
</head>
<body>
<strong>Hello World!</strong>
<form id="priv-key-form">
<label for="priv-key">Private Key</label>
<input type="password" id="priv-key" name="priv-key" />
<button type="submit">Save</button>
</form>
<script src="popup.js"></script>
</body>
</html>

View File

@@ -1 +1,21 @@
console.log("Hello World!", browser);
async function savePrivateKey(event) {
event.preventDefault();
let privKey = document.getElementById('priv-key');
browser.storage.local.set({ "priv-key": privKey.value });
}
async function getPrivateKey() {
let key = await browser.storage.local.get("priv-key");
return key["priv-key"];
}
async function setPrivKeyInput() {
let privKey = await getPrivateKey();
if (privKey) {
document.getElementById("priv-key").value = privKey;
}
}
document.getElementById("priv-key-form").addEventListener("submit", savePrivateKey);
setPrivKeyInput();