diff --git a/assets/scripts.js b/assets/scripts.js index cd22804..6e71e22 100644 --- a/assets/scripts.js +++ b/assets/scripts.js @@ -658,6 +658,32 @@ async function computeWKDLocalPart(message) { return encodeZBase32(new Uint8Array(hash)); } +async function generateProfileURL(data) { + if (data.input == "") { + return "Waiting for input..."; + } + switch (data.source) { + case "wkd": + return `https://keyoxide.org/${data.input}`; + break; + case "hkp": + if (/.*@.*\..*/.test(data.input)) { + return `https://keyoxide.org/hkp/${data.input}`; + } else { + return `https://keyoxide.org/${data.input}`; + } + break; + case "keybase": + const re = /https\:\/\/keybase.io\/(.*)\/pgp_keys\.asc\?fingerprint\=(.*)/; + if (!re.test(data.input)) { + return "Incorrect Keybase public key URL."; + } + const match = data.input.match(re); + return `https://keyoxide.org/keybase/${match[1]}/${match[2]}`; + break; + } +} + // General purpose let elFormVerify = document.body.querySelector("#form-verify"), elFormEncrypt = document.body.querySelector("#form-encrypt"), @@ -666,7 +692,8 @@ let elFormVerify = document.body.querySelector("#form-verify"), elProfileMode = document.body.querySelector("#profileMode"), elModeSelect = document.body.querySelector("#modeSelect"), elUtilWKD = document.body.querySelector("#form-util-wkd"), - elUtilQR = document.body.querySelector("#form-util-qr"); + elUtilQR = document.body.querySelector("#form-util-qr"), + elUtilProfileURL = document.body.querySelector("#form-util-profile-url"); if (elModeSelect) { elModeSelect.onchange = function (evt) { @@ -870,3 +897,36 @@ if (elUtilQR) { elInput.dispatchEvent(new Event("input")); } + +if (elUtilProfileURL) { + elUtilProfileURL.onsubmit = function (evt) { + evt.preventDefault(); + } + + const elInput = document.body.querySelector("#input"), + elSource = document.body.querySelector("#source"), + elOutput = document.body.querySelector("#output"); + + let data = { + input: elInput.value, + source: elSource.value + }; + + elInput.addEventListener("input", async function(evt) { + data = { + input: elInput.value, + source: elSource.value + }; + elOutput.innerText = await generateProfileURL(data); + }); + + elSource.addEventListener("input", async function(evt) { + data = { + input: elInput.value, + source: elSource.value + }; + elOutput.innerText = await generateProfileURL(data); + }); + + elInput.dispatchEvent(new Event("input")); +} diff --git a/assets/styles.css b/assets/styles.css index eafa3cd..ab40a53 100644 --- a/assets/styles.css +++ b/assets/styles.css @@ -103,6 +103,9 @@ input[type="submit"][disabled="true"] { pointer-events: none; opacity: 0.3; } +select { + margin: 0 0 16px 0; +} .green { color: green; } @@ -113,9 +116,6 @@ input[type="submit"][disabled="true"] { display: inline-block; margin: 0 0 8px; } -.modesContainer { - margin-top: 16px; -} .modes { display: none; } diff --git a/views/index.php b/views/index.php index 9d5cfa1..b2de7aa 100644 --- a/views/index.php +++ b/views/index.php @@ -10,6 +10,7 @@
+ Profile URL wkd QR
diff --git a/views/util/profile-url.php b/views/util/profile-url.php new file mode 100644 index 0000000..70c3e62 --- /dev/null +++ b/views/util/profile-url.php @@ -0,0 +1,23 @@ +layout('template.base', ['title' => $title]) ?> + +