From 6f7eafc29606a23944ae7b804ac5d39c000cbc10 Mon Sep 17 00:00:00 2001 From: Ryan Breen Date: Fri, 13 Jan 2023 22:39:55 -0500 Subject: [PATCH] alpine in popup. some logic is closer now, with visible changes --- Shared (Extension)/Resources/manifest.json | 6 ++- Shared (Extension)/Resources/popup.css | 15 +++++++- Shared (Extension)/Resources/popup.html | 28 ++++++++------ Shared (Extension)/Resources/popup.js | 43 +++++++++++++--------- package-lock.json | 22 +++++++++++ package.json | 1 + 6 files changed, 83 insertions(+), 32 deletions(-) diff --git a/Shared (Extension)/Resources/manifest.json b/Shared (Extension)/Resources/manifest.json index 23c9511..22986f7 100644 --- a/Shared (Extension)/Resources/manifest.json +++ b/Shared (Extension)/Resources/manifest.json @@ -43,5 +43,9 @@ "resources": ["nostr.build.js", "popup.build.js"], "matches": [""] } - ] + ], + + "content_security_policy": { + "extension_pages": "script-src 'self' 'unsafe-eval'" + } } diff --git a/Shared (Extension)/Resources/popup.css b/Shared (Extension)/Resources/popup.css index d3b2fd5..538b90f 100644 --- a/Shared (Extension)/Resources/popup.css +++ b/Shared (Extension)/Resources/popup.css @@ -9,6 +9,17 @@ body { font-family: system-ui; } -@media (prefers-color-scheme: dark) { - /* Dark Mode styles go here. */ +.profiles label { + width: 80px; + display: inline-block; } + +.profiles { + margin-bottom: 15px; +} + +.key { + margin-bottom: 15px; +} + +/* @media (prefers-color-scheme: dark) {} */ diff --git a/Shared (Extension)/Resources/popup.html b/Shared (Extension)/Resources/popup.html index baa83d0..e1665f9 100644 --- a/Shared (Extension)/Resources/popup.html +++ b/Shared (Extension)/Resources/popup.html @@ -3,20 +3,26 @@ + - -
+ +
- + -
+
+ +
- - - - - + +
+ +
+ + +
diff --git a/Shared (Extension)/Resources/popup.js b/Shared (Extension)/Resources/popup.js index 1bbd85a..fdd242b 100644 --- a/Shared (Extension)/Resources/popup.js +++ b/Shared (Extension)/Resources/popup.js @@ -1,23 +1,30 @@ -async function savePrivateKey(event) { - event.preventDefault(); - let privKey = document.getElementById('priv-key'); - browser.storage.local.set({ "priv-key": privKey.value }); - console.log('setting private key'); - await browser.runtime.sendMessage({greeting: 'hello'}); -} +import Alpine from "alpinejs"; +window.Alpine = Alpine; -async function getPrivateKey() { - let key = await browser.storage.local.get("priv-key"); - return key["priv-key"]; -} +Alpine.data('popup', () => ({ + privKey: '', + profiles: [], + profile: '', + visibleKey: false, -async function setPrivKeyInput() { - let privKey = await getPrivateKey(); + async init() { + await this.getProfiles(); + await this.getPrivKeyForProfile(); + }, - if (privKey) { - document.getElementById("priv-key").value = privKey; + saveKey() { + console.log(`Saving key ${this.privKey}`); + }, + + async getProfiles() { + this.profiles = ['Default', 'Extra']; + this.profile = 'Default'; + }, + + async getPrivKeyForProfile() { + this.privKey = this.profile; } -} +})); -document.getElementById("priv-key-form").addEventListener("submit", savePrivateKey); -setPrivKeyInput(); + +Alpine.start(); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 574587b..fc8bf7e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "1.0.0", "license": "ISC", "dependencies": { + "alpinejs": "^3.10.5", "esbuild": "^0.16.17", "nostr-tools": "^1.1.1" } @@ -423,6 +424,27 @@ } ] }, + "node_modules/@vue/reactivity": { + "version": "3.1.5", + "resolved": "https://registry.npmjs.org/@vue/reactivity/-/reactivity-3.1.5.tgz", + "integrity": "sha512-1tdfLmNjWG6t/CsPldh+foumYFo3cpyCHgBYQ34ylaMsJ+SNHQ1kApMIa8jN+i593zQuaw3AdWH0nJTARzCFhg==", + "dependencies": { + "@vue/shared": "3.1.5" + } + }, + "node_modules/@vue/shared": { + "version": "3.1.5", + "resolved": "https://registry.npmjs.org/@vue/shared/-/shared-3.1.5.tgz", + "integrity": "sha512-oJ4F3TnvpXaQwZJNF3ZK+kLPHKarDmJjJ6jyzVNDKH9md1dptjC7lWR//jrGuLdek/U6iltWxqAnYOu8gCiOvA==" + }, + "node_modules/alpinejs": { + "version": "3.10.5", + "resolved": "https://registry.npmjs.org/alpinejs/-/alpinejs-3.10.5.tgz", + "integrity": "sha512-qlvnal44Gof2XVfm/lef8fYpXKxR9fjdSki7aFB/9THyFvbsRKZ6lM5SjxXpIs7B0faJt7bgpK2K25gzrraXJw==", + "dependencies": { + "@vue/reactivity": "~3.1.1" + } + }, "node_modules/esbuild": { "version": "0.16.17", "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.16.17.tgz", diff --git a/package.json b/package.json index d94176d..ed8e41a 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "author": "", "license": "ISC", "dependencies": { + "alpinejs": "^3.10.5", "esbuild": "^0.16.17", "nostr-tools": "^1.1.1" }