/* Developed by Hero Expert
- Telegram channel: @HeroExpert_ir
- Author: Amirreza Ebrahimi
- Telegram Author: @a_m_b_r
*/
const token="503bf5006708dc769617c571f07206858ef8c018",button=document.querySelector(".shortenURL"),input=document.querySelector("#input-field"),longUrl=document.querySelector("#input-url"),shortUrl=document.querySelector("#new-url"),urlDetail=document.querySelector("#new-url a"),resultDiv=document.querySelector("#output-div"),errorDiv=document.querySelector("#error-div"),errorMessage=document.querySelector("#error-text"),clearButton=document.querySelector("#clear-btn"),copyButton=document.querySelector("#copy-btn"),handleError=e=>{if(console.log(e),e.ok)return e;errorMessage.textContent="",hideResult()},shorten=e=>{fetch("https://api-ssl.bitly.com/v4/shorten",{method:"POST",headers:{Authorization:"Bearer 503bf5006708dc769617c571f07206858ef8c018","Content-Type":"application/json"},body:JSON.stringify({long_url:e,domain:"bit.ly"})}).then(handleError).then(e=>e.json()).then(e=>{shortUrl.innerHTML=e.link,showResult()}).catch(e=>{console.log(e)})},clearFields=()=>{input.value="",urlDetail.innerHTML="",hideResult()};clearButton.addEventListener("click",e=>{e.preventDefault(),clearFields(),window.location.href="./"}),copyButton.addEventListener("click",e=>{e.preventDefault(),navigator.clipboard.writeText(urlDetail.innerHTML),urlDetail.innerHTML&&Swal.fire({title:"Your Short Url Has Been Copied!",icon:"success",toast:!0,position:"top-start",showConfirmButton:!1,timer:3500,timerProgressBar:!0,didOpen(e){e.onmouseenter=Swal.stopTimer,e.onmouseleave=Swal.resumeTimer}})});const showResult=()=>{shortUrl.style.display="flex"},hideResult=()=>{shortUrl.style.display="none"};
|