mirror of
https://github.com/minoplhy/chhoto-url.git
synced 2024-12-22 19:57:57 +00:00
Automatically add https if no protocol specified for longurl
This commit is contained in:
parent
99073bfd6c
commit
2c8076e2e1
@ -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_-]+" />
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user