From 2c8076e2e1a3516922f41c8b3c2257a1d6fdbb72 Mon Sep 17 00:00:00 2001 From: SinTan1729 Date: Fri, 11 Nov 2022 18:52:22 -0600 Subject: [PATCH] Automatically add https if no protocol specified for longurl --- src/main/resources/public/index.html | 5 +++-- src/main/resources/public/js/main.js | 21 ++++++++++++++++++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/main/resources/public/index.html b/src/main/resources/public/index.html index 379c6d8..e6bcd4e 100644 --- a/src/main/resources/public/index.html +++ b/src/main/resources/public/index.html @@ -67,9 +67,10 @@ Shorten
- +
-
+
diff --git a/src/main/resources/public/js/main.js b/src/main/resources/public/js/main.js index 91a27e0..ae1333e 100644 --- a/src/main/resources/public/js/main.js +++ b/src/main/resources/public/js/main.js @@ -66,10 +66,25 @@ const TR = (row, site) => { const copyShortUrl = async (link) => { const site = await getSiteUrl(); - navigator.clipboard.writeText(`${site}/${link}`); - addAlertBox(`Short URL ${link} copied to clipboard!`, "green"); + try { + navigator.clipboard.writeText(`${site}/${link}`); + addAlertBox(`Short URL ${link} was copied to clipboard!`, "green"); + } catch (e) { + console.log(e); + addAlertBox("Could not copy short URL to clipboard, please do it manually.", "red"); + } + }; +const addProtocol = (input) => { + var url = input.value.trim(); + if (url != "" && !~url.indexOf(":/")) { + url = "https://" + url; + } + input.value = url; + return input +} + const A = (s) => `${s}`; const A_INT = (s, t) => `${t}/${s}`; @@ -114,7 +129,7 @@ const submitForm = () => { }) .then(res => { if (!res.ok) { - addAlertBox("Short URL not valid or already in use!", "red"); + addAlertBox("Short URL is not valid or it's already in use!", "red"); return "error"; } else {