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();

View File

@@ -45,6 +45,8 @@
941B03F9296FA90400CA291E /* popup.css in Resources */ = {isa = PBXBuildFile; fileRef = 941B03A9296FA90400CA291E /* popup.css */; };
941B03FA296FA90400CA291E /* popup.js in Resources */ = {isa = PBXBuildFile; fileRef = 941B03AA296FA90400CA291E /* popup.js */; };
941B03FB296FA90400CA291E /* popup.js in Resources */ = {isa = PBXBuildFile; fileRef = 941B03AA296FA90400CA291E /* popup.js */; };
941B040D296FAD6900CA291E /* nostr.js in Resources */ = {isa = PBXBuildFile; fileRef = 941B040C296FAD6900CA291E /* nostr.js */; };
941B040E296FAD6900CA291E /* nostr.js in Resources */ = {isa = PBXBuildFile; fileRef = 941B040C296FAD6900CA291E /* nostr.js */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@@ -120,6 +122,7 @@
941B03D7296FA90400CA291E /* nostore Extension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = "nostore Extension.appex"; sourceTree = BUILT_PRODUCTS_DIR; };
941B03DC296FA90400CA291E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
941B03DD296FA90400CA291E /* nostore.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = nostore.entitlements; sourceTree = "<group>"; };
941B040C296FAD6900CA291E /* nostr.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; path = nostr.js; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -205,6 +208,7 @@
941B03A5296FA90400CA291E /* manifest.json */,
941B03A6296FA90400CA291E /* background.js */,
941B03A7296FA90400CA291E /* content.js */,
941B040C296FAD6900CA291E /* nostr.js */,
941B03A8296FA90400CA291E /* popup.html */,
941B03A9296FA90400CA291E /* popup.css */,
941B03AA296FA90400CA291E /* popup.js */,
@@ -417,6 +421,7 @@
941B03F2296FA90400CA291E /* background.js in Resources */,
941B03F8296FA90400CA291E /* popup.css in Resources */,
941B03F6296FA90400CA291E /* popup.html in Resources */,
941B040D296FAD6900CA291E /* nostr.js in Resources */,
941B03EE296FA90400CA291E /* images in Resources */,
941B03F0296FA90400CA291E /* manifest.json in Resources */,
941B03EC296FA90400CA291E /* _locales in Resources */,
@@ -432,6 +437,7 @@
941B03F3296FA90400CA291E /* background.js in Resources */,
941B03F9296FA90400CA291E /* popup.css in Resources */,
941B03F7296FA90400CA291E /* popup.html in Resources */,
941B040E296FAD6900CA291E /* nostr.js in Resources */,
941B03EF296FA90400CA291E /* images in Resources */,
941B03F1296FA90400CA291E /* manifest.json in Resources */,
941B03ED296FA90400CA291E /* _locales in Resources */,