├── README.md ├── index.html ├── package.json ├── url-lengthener-node.d.ts ├── url-lengthener-node.js ├── url-lengthener.js └── url-lengthener.min.js /README.md: -------------------------------------------------------------------------------- 1 | # URL Lengthener 2 | 3 | [![](https://data.jsdelivr.com/v1/package/npm/url-lengthener/badge?.png)](https://www.jsdelivr.com/package/npm/url-lengthener) 4 | [![](https://img.shields.io/bundlephobia/min/url-lengthener?style=flat-square&.png)](https://www.jsdelivr.com/package/npm/url-lengthener) 5 | [![](https://img.shields.io/npm/dm/url-lengthener?style=flat-square&.png)](https://www.jsdelivr.com/package/npm/url-lengthener) 6 | 7 | Are you tired of your URLs being just too darn short? Worry no further, as [aaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.com](https://aaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.com/) has got your back. No need to be anxious about people thinking the size of your URL is too small, as it will guaranteed be the largest one around. So what are you waiting for? Give it a go! 8 | 9 | Your date will be impressed with the sheer size of your URLs, and forget having to take time spelling them out to your coworkers; just yell at the top of your lungs. Want to automate it? Check out the docs for more info. 10 | 11 | Disclaimer: Since there is a maximum letter count to a URL, there is a slight chance your resulting URL will be too long to use. No worries, try running it through a site like [bit.ly](https://bitly.com/) and then paste that one over here. Every resulting URL ends up having a minimum number of characters, so your URL will still be plenty long! 12 | 13 | Links: 14 | - Made with ❤️ by [Piero™](https://piemadd.com/) 15 | - [Website source code on Replit](https://replit.com/@piemadd/url-lengthener) 16 | - [Project source code on Github](https://github.com/pieromqwerty/url-lengthener) 17 | - [Package on NPM](https://www.npmjs.com/package/url-lengthener). 18 | 19 | # URL Lengthener - Docs 20 | 21 | Using the URL lengthener is super easy and free. How? Everything is encoded into the URL served. This is how you do it: 22 | 23 | ### Get the script: 24 | 25 | The script is located at [`/url-lengthener.js`](/url-lengthener.js) of this site, or you can use the mirror from JSDelivr, located at [https://cdn.jsdelivr.net/npm/url-lengthener@latest/url-lengthener.min.js](https://cdn.jsdelivr.net/npm/url-lengthener@latest/url-lengthener.min.js). If you would like to link it directly into your website, place either of the two lines in the `` section of your site, with the JSDeliver file being quicker (though not by much) to fetch and the one from this site being more updated: 26 | 27 | ```html 28 | 29 | ``` 30 | ```html 31 | 32 | ``` 33 | If you prefer the unminified version of the code, remove the `.min` from whichever link you are using. 34 | 35 | ### Use the script (web): 36 | 37 | Using the script is quite simple, as it is less than 115 lines in length. Encoding a URL takes two steps, converting from a URL to base16 and then base16 to the string of "A"s. While you could call these functions (`str2hex()` and `hex2a()` respectively), the easiest way to get a URL encoded is to use the `lengthen(url)` function, where _url_ is the URL which you would like to lengthen. The function then returns a lengthened URL, which will redirect to its final destination when visited. 38 | 39 | ### Use the script (Node): 40 | 41 | 1. Install the npm package (`url-lengthener`) 42 | 2. Require the library: 43 | ```js 44 | const urlLengthener = require("url-lengthener") 45 | ``` 46 | 3. Use the `lenghten()` function to run the code: 47 | ```js 48 | let lengthened_url = urlLengthener.lengthen("https://piemadd.com/"); 49 | console.log(lengthened_url); 50 | ``` 51 | To have the returned URL use a PATH instead instead of a URL variable, use `lengthenAsPath()` instead. This increases reliability on sites like Twitter and allows for the lengthened URL to be visited in browsers with Javascript disabled. The solution is drop-in with the example above, instead resulting in something like this: 52 | ```js 53 | let lengthened_url = urlLengthener.lengthenAsPath("https://piemadd.com/"); 54 | console.log(lengthened_url); 55 | ``` 56 | 57 | ### API 58 | 59 | It's simple, ok? You send a `GET` request here: 60 | ``` 61 | https://api.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.com/a?url=[YOUR_URL_HERE] 62 | ``` 63 | 64 | `[YOUR_URL_HERE]` is where you put the URL you want to lengthen. A plaintext response with the lengthened URL is returned unless the URL is invalid, which instead `INVALID_URL` is returned. -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "url-lengthener", 3 | "version": "2.1.1", 4 | "description": "Are your URLs too short? Use url-lengthener to s t r e t c h them out!", 5 | "main": "url-lengthener-node.js", 6 | "types": "url-lengthener-node.d.ts", 7 | "scripts": { 8 | "test": "node url-lengthener.js" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "git+https://github.com/piemadd/url-lengthener.git" 13 | }, 14 | "keywords": [ 15 | "url-shortener", 16 | "url-lenghtener", 17 | "url", 18 | "web-utilities", 19 | "utilities", 20 | "productivity", 21 | "cross-platform" 22 | ], 23 | "author": "Piero™", 24 | "license": "ISC", 25 | "bugs": { 26 | "url": "https://github.com/piemadd/url-lengthener/issues" 27 | }, 28 | "homepage": "https://github.com/piemadd/url-lengthener#readme", 29 | "dependencies": {} 30 | } 31 | -------------------------------------------------------------------------------- /url-lengthener-node.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Convert a hex string to an alphanumeric string 3 | * @param hexx The hex string to convert 4 | */ 5 | export declare const hex2str: (hexx: string) => string; 6 | 7 | /** 8 | * Convert an alphanumeric string to a hex string 9 | * @param str The string to convert 10 | */ 11 | export declare const str2hex: (str: string) => string; 12 | 13 | /** 14 | * Replace real hex values with diffrent 'a' letters 15 | * @param str The hex string to convert 16 | */ 17 | export declare const hex2a: (str: string) => string; 18 | 19 | /** 20 | * Replace diffrent 'a' letters with it's real hex values 21 | * @param str The string to convert 22 | */ 23 | export declare const a2hex: (str: string) => string; 24 | 25 | /** 26 | * Funtion to validate a URL 27 | * @param url The url to validate 28 | */ 29 | export declare const validURL: (url: string) => boolean; 30 | 31 | /** 32 | * Lengthen a URL 33 | * @param url The orignal URL 34 | */ 35 | export declare const lengthen: (url: string) => string; 36 | 37 | /** 38 | * Lengthen a URL but with greater reliability at the cost of speed 39 | * @param url The orignal URL 40 | */ 41 | export declare const lengthenAsPath: (url: string) => string; -------------------------------------------------------------------------------- /url-lengthener-node.js: -------------------------------------------------------------------------------- 1 | //var exports = {"__esModule": true}; 2 | 3 | const hex2str = (hexx) => { 4 | var hex = hexx.toString();//force conversion 5 | var str = ''; 6 | for (var i = 0; (i < hex.length && hex.substr(i, 2) !== '00'); i += 2) 7 | str += String.fromCharCode(parseInt(hex.substr(i, 2), 16)); 8 | return str; 9 | } 10 | 11 | const str2hex = (str) => { 12 | var arr = []; 13 | for (var i = 0, l = str.length; i < l; i ++) { 14 | var hex = Number(str.charCodeAt(i)).toString(16); 15 | arr.push(hex); 16 | } 17 | return arr.join(''); 18 | } 19 | 20 | const hex2a = (str) => { 21 | let arr_hex = str.split(''); 22 | let reformattedArray = arr_hex.map(char => { 23 | const replacements = { 24 | '0': 'a', 25 | '1': 'à', 26 | '2': 'á', 27 | '3': 'â', 28 | '4': 'ã', 29 | '5': 'ä', 30 | '6': 'å', 31 | '7': 'æ', 32 | '8': 'A', 33 | '9': 'À', 34 | 'a': 'Á', 35 | 'b': 'Â', 36 | 'c': 'Ã', 37 | 'd': 'Ä', 38 | 'e': 'Å', 39 | 'f': 'Æ' 40 | }; 41 | return replacements[char]; 42 | }) 43 | 44 | return reformattedArray.join(''); 45 | } 46 | 47 | const a2hex = (str) => { 48 | let arr_hex = str.split(''); 49 | let reformattedArray = arr_hex.map(char => { 50 | const replacements = { 51 | 'a': '0', 52 | 'à': '1', 53 | 'á': '2', 54 | 'â': '3', 55 | 'ã': '4', 56 | 'ä': '5', 57 | 'å': '6', 58 | 'æ': '7', 59 | 'A': '8', 60 | 'À': '9', 61 | 'Á': 'a', 62 | 'Â': 'b', 63 | 'Ã': 'c', 64 | 'Ä': 'd', 65 | 'Å': 'e', 66 | 'Æ': 'f' 67 | 68 | }; 69 | return replacements[char]; 70 | }) 71 | 72 | return reformattedArray.join(''); 73 | } 74 | 75 | const validURL = (url) => { 76 | try { 77 | new URL(url); 78 | } catch (e) { 79 | console.error(e); 80 | return false; 81 | } 82 | return true; 83 | }; 84 | 85 | const lengthen = (url) => { 86 | if (validURL(url)) { 87 | new_url = hex2a(str2hex(url)); 88 | while (new_url.length < 200) { 89 | new_url = "áaaÂ" + new_url; 90 | } 91 | return "https://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.com/a?" + new_url; 92 | } else { 93 | throw new Error("The URL passed is not valid."); 94 | } 95 | } 96 | 97 | const lengthenAsPath = (url) => { 98 | if (validURL(url)) { 99 | new_url = hex2a(str2hex(url)); 100 | while (new_url.length < 200) { 101 | new_url = "áaaÂ" + new_url; 102 | } 103 | return "https://api.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.com/" + new_url; 104 | } else { 105 | throw new Error("The URL passed is not valid."); 106 | } 107 | } 108 | 109 | exports.hex2str = hex2str; 110 | exports.str2hex = str2hex; 111 | exports.hex2a = hex2a; 112 | exports.a2hex = a2hex; 113 | exports.validURL = validURL; 114 | exports.lengthen = lengthen; 115 | exports.lengthenAsPath = lengthenAsPath; -------------------------------------------------------------------------------- /url-lengthener.js: -------------------------------------------------------------------------------- 1 | const hex2str = ((hexx) => { 2 | let hex = hexx.toString();//force conversion 3 | let str = ''; 4 | for (let i = 0; (i < hex.length && hex.substr(i, 2) !== '00'); i += 2) 5 | str += String.fromCharCode(parseInt(hex.substr(i, 2), 16)); 6 | return str; 7 | }) 8 | 9 | const str2hex = ((str) => { 10 | let arr = []; 11 | for (let i = 0, l = str.length; i < l; i ++) { 12 | let hex = Number(str.charCodeAt(i)).toString(16); 13 | arr.push(hex); 14 | } 15 | return arr.join(''); 16 | }) 17 | 18 | const hex2a = ((str) => { 19 | let arr_hex = str.split(''); 20 | let reformattedArray = arr_hex.map(char => { 21 | const replacements = { 22 | '0': 'a', 23 | '1': 'à', 24 | '2': 'á', 25 | '3': 'â', 26 | '4': 'ã', 27 | '5': 'ä', 28 | '6': 'å', 29 | '7': 'æ', 30 | '8': 'A', 31 | '9': 'À', 32 | 'a': 'Á', 33 | 'b': 'Â', 34 | 'c': 'Ã', 35 | 'd': 'Ä', 36 | 'e': 'Å', 37 | 'f': 'Æ' 38 | }; 39 | return replacements[char]; 40 | }) 41 | 42 | return reformattedArray.join(''); 43 | }) 44 | 45 | const a2hex = ((str) => { 46 | let arr_hex = str.split(''); 47 | let reformattedArray = arr_hex.map(char => { 48 | const replacements = { 49 | 'a': '0', 50 | 'à': '1', 51 | 'á': '2', 52 | 'â': '3', 53 | 'ã': '4', 54 | 'ä': '5', 55 | 'å': '6', 56 | 'æ': '7', 57 | 'A': '8', 58 | 'À': '9', 59 | 'Á': 'a', 60 | 'Â': 'b', 61 | 'Ã': 'c', 62 | 'Ä': 'd', 63 | 'Å': 'e', 64 | 'Æ': 'f' 65 | 66 | }; 67 | return replacements[char]; 68 | }) 69 | 70 | return reformattedArray.join(''); 71 | }) 72 | 73 | const validURL = ((url) => { 74 | console.log(url) 75 | try { 76 | console.log(new URL(url)); 77 | } catch (e) { 78 | return false; 79 | } 80 | console.log(true) 81 | return true; 82 | }) 83 | 84 | const encodeURL = (() => { 85 | let input_url = document.getElementById("input").value; 86 | 87 | let originalURL = "https://" + input_url.replace('https://', '').replace('http://', '') 88 | 89 | if (validURL(originalURL) || document.getElementById("override").checked) { 90 | new_url = lengthen(originalURL); 91 | document.getElementById("output").value = new_url; 92 | } else { 93 | document.getElementById("output").value = "URL is not valid, please try again."; 94 | } 95 | }) 96 | 97 | const getRandom = ((list) => { 98 | return list[Math.floor((Math.random()*list.length))]; 99 | }) 100 | 101 | const lengthen = ((url, minLength = 200) => { 102 | const letters = ['a', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'A', 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ'] 103 | 104 | let baseURL = "https://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.com/"; 105 | 106 | let filler = 'a'; 107 | 108 | if (validURL("https://" + url.replace('https://', '').replace('http://', ''))) { 109 | new_url = hex2a(str2hex(url)); 110 | 111 | while (new_url.length + filler.length < minLength) { 112 | filler = filler + getRandom(letters); 113 | } 114 | return baseURL + filler + "?" + new_url; 115 | } else { 116 | throw new Error("The URL passed is not valid."); 117 | } 118 | }) 119 | 120 | const copyURL = (() => { 121 | let copyText = document.getElementById("output"); 122 | copyText.select(); 123 | copyText.setSelectionRange(0, 99999); /* For mobile devices */ 124 | document.execCommand("copy"); 125 | }) -------------------------------------------------------------------------------- /url-lengthener.min.js: -------------------------------------------------------------------------------- 1 | const hex2str=e=>{let a=e.toString(),t="";for(let e=0;e{let a=[];for(let t=0,n=e.length;t{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{let e=document.getElementById("output");e.select(),e.setSelectionRange(0,99999),document.execCommand("copy")}; --------------------------------------------------------------------------------