forked from sunwoo1524/krll
[feat] enter키로 shorten 가능
This commit is contained in:
parent
ffdd89f9b8
commit
868d28c48f
|
@ -6,7 +6,23 @@ const qr_code = document.getElementById("qr-code");
|
||||||
const error_message = document.getElementById("error");
|
const error_message = document.getElementById("error");
|
||||||
const copy_message = document.getElementById("copied");
|
const copy_message = document.getElementById("copied");
|
||||||
|
|
||||||
to_shorten_btn.addEventListener("click", async () => {
|
to_shorten_btn.addEventListener("click", shorten);
|
||||||
|
addEventListener("keydown", (event) => {if(event.key == "Enter") shorten;});
|
||||||
|
|
||||||
|
short_url.addEventListener("click", event => {
|
||||||
|
// copy the short url to clipboard
|
||||||
|
navigator.clipboard.writeText(event.target.innerText)
|
||||||
|
.then(() => {
|
||||||
|
// show a message
|
||||||
|
copy_message.style.opacity = "1";
|
||||||
|
setTimeout(() => copy_message.style.opacity = "0", 3000);
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
alert("An error has occurred...\n" + error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
const shorten = async () => {
|
||||||
const original_url = url_input.value
|
const original_url = url_input.value
|
||||||
// check if the url input is empty
|
// check if the url input is empty
|
||||||
if (original_url.length === 0) {
|
if (original_url.length === 0) {
|
||||||
|
@ -52,20 +68,7 @@ to_shorten_btn.addEventListener("click", async () => {
|
||||||
// get the qr code of the short url and show it
|
// get the qr code of the short url and show it
|
||||||
qr_code.src = `https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=${result}`;
|
qr_code.src = `https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=${result}`;
|
||||||
qr_code.alt = result;
|
qr_code.alt = result;
|
||||||
});
|
}
|
||||||
|
|
||||||
short_url.addEventListener("click", event => {
|
|
||||||
// copy the short url to clipboard
|
|
||||||
navigator.clipboard.writeText(event.target.innerText)
|
|
||||||
.then(() => {
|
|
||||||
// show a message
|
|
||||||
copy_message.style.opacity = "1";
|
|
||||||
setTimeout(() => copy_message.style.opacity = "0", 3000);
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
alert("An error has occurred...\n" + error);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
const rickroll = {
|
const rickroll = {
|
||||||
check: (url)=>{
|
check: (url)=>{
|
||||||
|
|
Loading…
Reference in a new issue