1
0
Fork 0
mirror of https://github.com/SinTan1729/chhoto-url synced 2024-12-26 07:38:36 -06:00

Automatically add https if no protocol specified for longurl

This commit is contained in:
Sayantan Santra 2022-11-11 18:52:22 -06:00
parent 99073bfd6c
commit 2c8076e2e1
2 changed files with 21 additions and 5 deletions

View file

@ -67,9 +67,10 @@
Shorten</legend>
<div class="pure-control-group">
<label for="longUrl">Long URL</label>
<input type="url" name="longUrl" id="longUrl" placeholder="Please enter a valid URL" required />
<input type="url" name="longUrl" id="longUrl" placeholder="Please enter a valid URL"
onblur="addProtocol(this)" required />
</div>
<div class="pure-control-group">
<div class=" pure-control-group">
<label for="shortUrl">Short URL (optional)</label>
<input type="text" name="shortUrl" id="shortUrl" placeholder="Only a-z, 0-9, - and _ are allowed"
pattern="[A-Za-z0-9_-]+" />

View file

@ -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) => `<a href='${s}'>${s}</a>`;
const A_INT = (s, t) => `<a href="javascript:copyShortUrl('${s}');">${t}/${s}</a>`;
@ -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 {