mirror of
https://github.com/SinTan1729/chhoto-url
synced 2024-12-26 23:58:35 -06:00
Automatically add https if no protocol specified for longurl
This commit is contained in:
parent
99073bfd6c
commit
2c8076e2e1
2 changed files with 21 additions and 5 deletions
|
@ -67,7 +67,8 @@
|
|||
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">
|
||||
<label for="shortUrl">Short URL (optional)</label>
|
||||
|
|
|
@ -66,10 +66,25 @@ const TR = (row, site) => {
|
|||
|
||||
const copyShortUrl = async (link) => {
|
||||
const site = await getSiteUrl();
|
||||
try {
|
||||
navigator.clipboard.writeText(`${site}/${link}`);
|
||||
addAlertBox(`Short URL ${link} copied to clipboard!`, "green");
|
||||
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 a new issue