Improve WKD URL generator

This commit is contained in:
Yarmo Mackenbach 2020-07-23 11:07:49 +02:00
parent 4018ec1c7b
commit 47b0383341
4 changed files with 29 additions and 8 deletions

View file

@ -1004,14 +1004,30 @@ if (elUtilWKD) {
const elInput = document.body.querySelector("#input"); const elInput = document.body.querySelector("#input");
const elOutput = document.body.querySelector("#output"); const elOutput = document.body.querySelector("#output");
const elOutputDirect = document.body.querySelector("#output_url_direct");
const elOutputAdvanced = document.body.querySelector("#output_url_advanced");
let match;
elInput.addEventListener("input", async function(evt) { elInput.addEventListener("input", async function(evt) {
if (evt.target.value) { if (evt.target.value) {
elOutput.value = await computeWKDLocalPart(evt.target.value); if (/(.*)@(.{1,}\..{1,})/.test(evt.target.value)) {
match = evt.target.value.match(/(.*)@(.*)/);
elOutput.innerText = await computeWKDLocalPart(match[1]);
elOutputDirect.innerText = `https://${match[2]}/.well-known/openpgpkey/hu/${elOutput.innerText}?l=${match[1]}`;
elOutputAdvanced.innerText = `https://openpgpkey.${match[2]}/.well-known/openpgpkey/${match[2]}/hu/${elOutput.innerText}?l=${match[1]}`;
} else { } else {
elOutput.value = ""; elOutput.innerText = await computeWKDLocalPart(evt.target.value);
elOutputDirect.innerText = "Waiting for input";
elOutputAdvanced.innerText = "Waiting for input";
}
} else {
elOutput.innerText = "Waiting for input";
elOutputDirect.innerText = "Waiting for input";
elOutputAdvanced.innerText = "Waiting for input";
} }
}); });
elInput.dispatchEvent(new Event("input"));
} }
if (elUtilQRFP) { if (elUtilQRFP) {

View file

@ -84,7 +84,7 @@ footer a {
background: linear-gradient(0deg, #4da4d2 0%, #82c5ea 100%); background: linear-gradient(0deg, #4da4d2 0%, #82c5ea 100%);
} }
.full-width { .full-width {
width: 100%; width: 100% !important;
} }
h1 { h1 {

View file

@ -18,8 +18,8 @@
<h2>Utilities</h2> <h2>Utilities</h2>
<p> <p>
<a href="/util/profile-url">Profile URL generator</a><br> <a href="/util/profile-url">Profile URL generator</a><br>
<a href="/util/wkd">Web Key Directory</a><br> <a href="/util/wkd">Web Key Directory URL generator</a><br>
<a href="/util/qr">Fingerprint QR</a> <a href="/util/qr">Fingerprint QR generator</a>
</p> </p>
</div> </div>
</div> </div>

View file

@ -1,12 +1,17 @@
<?php $this->layout('template.base', ['title' => $title]) ?> <?php $this->layout('template.base', ['title' => $title]) ?>
<div class="content"> <div class="content">
<h1>WKD Local Part</h1> <h1>Web Key Directory generator</h1>
<form id="form-util-wkd" method="post"> <form id="form-util-wkd" method="post">
<p>This tool computes the part of the URL that corresponds to the username when <a href="https://keyoxide.org/guides/web-key-directory">uploading keys using web key directory</a>.</p> <p>This tool computes the part of the URL that corresponds to the username when <a href="https://keyoxide.org/guides/web-key-directory">uploading keys using web key directory</a>.</p>
<h3>Input</h3> <h3>Input</h3>
<input type="text" name="input" id="input" placeholder="Username"> <input type="text" name="input" id="input" placeholder="WKD username or identifier">
<h3>Output</h3> <h3>Output</h3>
<input type="text" name="output" id="output" placeholder="Waiting for input..." readonly> <h4>Local part</h4>
<code class="full-width"id="output">Waiting for input...</code>
<h4>Direct URL</h4>
<code class="full-width"id="output_url_direct">Waiting for input...</code>
<h4>Advanced URL</h4>
<code class="full-width"id="output_url_advanced">Waiting for input...</code>
</form> </form>
</div> </div>