-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathurl-lengthener.min.js
1 lines (1 loc) · 1.61 KB
/
url-lengthener.min.js
1
const hex2str=e=>{let a=e.toString(),t="";for(let e=0;e<a.length&&"00"!==a.substr(e,2);e+=2)t+=String.fromCharCode(parseInt(a.substr(e,2),16));return t},str2hex=e=>{let a=[];for(let t=0,n=e.length;t<n;t++){let n=Number(e.charCodeAt(t)).toString(16);a.push(n)}return a.join("")},hex2a=e=>{return e.split("").map(e=>{return{0:"a",1:"à",2:"á",3:"â",4:"ã",5:"ä",6:"å",7:"æ",8:"A",9:"À",a:"Á",b:"Â",c:"Ã",d:"Ä",e:"Å",f:"Æ"}[e]}).join("")},a2hex=e=>{return e.split("").map(e=>{return{a:"0","à":"1","á":"2","â":"3","ã":"4","ä":"5","å":"6","æ":"7",A:"8","À":"9","Á":"a","Â":"b","Ã":"c","Ä":"d","Å":"e","Æ":"f"}[e]}).join("")},validURL=e=>{console.log(e);try{console.log(new URL(e))}catch(e){return!1}return console.log(!0),!0},encodeURL=()=>{let e="https://"+document.getElementById("input").value.replace("https://","").replace("http://","");validURL(e)||document.getElementById("override").checked?(new_url=lengthen(e),document.getElementById("output").value=new_url):document.getElementById("output").value="URL is not valid, please try again."},getRandom=e=>e[Math.floor(Math.random()*e.length)],lengthen=(e,a=200)=>{const t=["a","à","á","â","ã","ä","å","æ","A","À","Á","Â","Ã","Ä","Å","Æ"];let n="a";if(validURL("https://"+e.replace("https://","").replace("http://",""))){for(new_url=hex2a(str2hex(e));new_url.length+n.length<a;)n+=getRandom(t);return"https://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.com/"+n+"?"+new_url}throw new Error("The URL passed is not valid.")},copyURL=()=>{let e=document.getElementById("output");e.select(),e.setSelectionRange(0,99999),document.execCommand("copy")};