]> git.ardis.lu - alu.bz/commitdiff
Make the URL in the success message clickable
authorArdis Lu <ardisglu@gmail.com>
Sat, 20 May 2023 04:44:14 +0000 (21:44 -0700)
committerArdis Lu <ardisglu@gmail.com>
Sat, 20 May 2023 04:44:14 +0000 (21:44 -0700)
functions/api.js
script.js

index ee0bd031ae22e1e0fd6155178da7d0021afa5601..087dd5a5d86697f612e5819ffeaa5edcc1940bd7 100644 (file)
@@ -80,5 +80,5 @@ export async function onRequestPost({ request, env }) {
   }
 
   await env.links.put(shortUrl, fullUrl);
-  return new Response(`Successfully created short URL: https://alu.bz/${shortUrl}`, { headers: { 'Content-Type': 'text/plain; charset=UTF-8' } });
+  return new Response(shortUrl, { headers: { 'Content-Type': 'text/plain; charset=UTF-8' } });
 }
index db316cd534aee79a055856b6660bf24d8a459284..a307d234628a171a7a371b860b1876dbe1f7c5e2 100644 (file)
--- a/script.js
+++ b/script.js
@@ -102,11 +102,13 @@ async function handleSubmit(event) {
 
   if (response.ok) {
     statusOutput.classList.add('success');
+    const generatedUrl = await response.text();
+    statusOutput.innerHTML = `Successfully created short URL: <a href="${location.origin}/${generatedUrl}">${location.origin}/${generatedUrl}</a>`;
   }
   else {
     statusOutput.classList.add('failure');
+    statusOutput.textContent = await response.text();
   }
-  statusOutput.textContent = await response.text();
 }
 
 if (window.ethereum !== undefined) {
This page took 0.035189 seconds and 4 git commands to generate.