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:
@@ -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);
|
||||
|
||||
@@ -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>"]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
14
Shared (Extension)/Resources/nostr.js
Normal file
14
Shared (Extension)/Resources/nostr.js
Normal 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";
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
}
|
||||
|
||||
body {
|
||||
width: 100px;
|
||||
width: 500px;
|
||||
padding: 10px;
|
||||
|
||||
font-family: system-ui;
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user