├── index.html ├── README.md └── main.js /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Simple URL Shortener 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Simple URL Shortener 2 | 3 | ## ⚠️ Doesn't work anymore! 4 | 5 | Source Code of the Code from the article of [Adventure Of Palash](https://palashbauri.in) 6 | 7 | Tools Using : 8 | 9 | - jsonstore.io 10 | - html 11 | - javascript 12 | - jquery 13 | 14 | No Need Of Database ! 15 | 16 | READ THE Original ARTICLE HERE 17 | 18 | [![Blog Post](https://palash.tk/assets/images/build_url_shortener.png)](https://dev.to/bauripalash/building-a-simple-url-shortener-with-just-html-and-javascript-16o4) 19 | 20 | --- 21 | ### Buy Me A Coffee! 22 | Buy Me A Coffee 23 | -------------------------------------------------------------------------------- /main.js: -------------------------------------------------------------------------------- 1 | var endpoint = "https://www.jsonstore.io/8ba4fd855086288421f770482e372ccb5a05d906269a34da5884f39eed0418a1"; 2 | 3 | function geturl(){ 4 | var url = document.getElementById("urlinput").value; 5 | var protocol_ok = url.startsWith("http://") || url.startsWith("https://") || url.startsWith("ftp://"); 6 | if(!protocol_ok){ 7 | newurl = "http://"+url; 8 | return newurl; 9 | }else{ 10 | return url; 11 | } 12 | } 13 | 14 | function getrandom() { 15 | var text = ""; 16 | var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; 17 | 18 | for (var i = 0; i < 5; i++) 19 | text += possible.charAt(Math.floor(Math.random() * possible.length)); 20 | return text; 21 | } 22 | 23 | function genhash(){ 24 | if (window.location.hash == ""){ 25 | window.location.hash = getrandom(); 26 | } 27 | } 28 | 29 | function send_request(url) { 30 | this.url = url; 31 | $.ajax({ 32 | 'url': endpoint + "/" + window.location.hash.substr(1), 33 | 'type': 'POST', 34 | 'data': JSON.stringify(this.url), 35 | 'dataType': 'json', 36 | 'contentType': 'application/json; charset=utf-8' 37 | }) 38 | } 39 | 40 | function shorturl(){ 41 | var longurl = geturl(); 42 | genhash(); 43 | send_request(longurl); 44 | } 45 | 46 | var hashh = window.location.hash.substr(1) 47 | 48 | if (window.location.hash != "") { 49 | $.getJSON(endpoint + "/" + hashh, function (data) { 50 | data = data["result"]; 51 | 52 | if (data != null) { 53 | window.location.href = data; 54 | } 55 | 56 | }); 57 | } 58 | 59 | --------------------------------------------------------------------------------