PHP Classes

File: resources/assets/js/fa/app.js

Recommend this page to a friend!
  Packages of Amirreza Ebrahimi   URL Shortener Application   resources/assets/js/fa/app.js   Download  
File: resources/assets/js/fa/app.js
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: URL Shortener Application
Application to create and redirect short URLs
Author: By
Last change:
Date: 7 months ago
Size: 1,846 bytes
 

Contents

Class file image Download
/* 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="",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:"???? ????? ??? ?? ?????? ??? ??!",icon:"success",toast:!0,position:"top-end",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"};input&&input.addEventListener("keyup",e=>{input.value.length>=1?input.classList.add("input-left"):input.classList.remove("input-left")});