Skip to content

Instantly share code, notes, and snippets.

@srifqi
Forked from 140bytes/LICENSE.txt
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save srifqi/7de7cc4ed53de7e68136 to your computer and use it in GitHub Desktop.
Save srifqi/7de7cc4ed53de7e68136 to your computer and use it in GitHub Desktop.

Url Parser

This will help user to navigate in it's browser

##Example

a('https://gist.github.com/srifqi/7de7cc4ed53de7e68136')

Will be: [ [gist.github.com,srifqi,7de7cc4ed53de7e68136], [https:///gist.github.com,https:///gist.github.com/srifqi,https:///gist.github.com/srifqi/7de7cc4ed53de7e68136] ]

function a(
t //url to be parsed
){
var y='://',
t=t.split(y), //split using y
s=t[0], //get http or https
u=t[1].split('/'), //get domain and directories (also the file)
d=[],e=[]; //place to save
for(t=0;t<u.length;)
e.push((e[t-1]||s+y)+'/'+u[t]), //e for url
d.push(u[t++]); //d for the text
return[d,e] //return parsed url [text,url]
}
function a(t){var y='://',t=t.split(y),s=t[0],u=t[1].split('/'),d=[],e=[];for(t=0;t<u.length;)e.push((e[t-1]||s+y)+'/'+u[t]),d.push(u[t++]);return[d,e]}
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 srifqi srifqi.github.io
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
{
"name": "UrlParser",
"description": "",
"keywords": [
"url",
"parser"
]
}
<!doctype html>
<html>
<head>
<title>Url Parsing</title>
<meta charset="utf-8" />
</head>
<body>
<div id="d"></div>
<script>
var b = document.body;
var d = document.getElementById('d'); //DEBUG
</script>
<script>
//the library
function a(t){var y='://',t=t.split(y),s=t[0],u=t[1].split('/'),d=[],e=[];for(t=0;t<u.length;)e.push((e[t-1]||s+y)+'/'+u[t]),d.push(u[t++]);return[d,e]}
//url to be parsed
var y=['https://www.google.com/search','https://github.com/srifqi/srifqi.github.io','https://github.com/jed/140bytes/wiki/Byte-saving-techniques'];
//show the result
for(var o=0;o<y.length;o++){
var A=a(y[o]);
d.innerHTML+=y[o]+':<br/>';
for(var p=0;p<A[0].length;p++)d.innerHTML+='&gt;&nbsp;<a href="'+A[1][p]+'">'+A[0][p]+'</a>&nbsp;';
d.innerHTML+='<br/><br/>';
}
</script>
</body>
</html>
@atk
Copy link

atk commented May 16, 2014

Can you please provide a test or at least a description how it's supposed to work?

@srifqi
Copy link
Author

srifqi commented May 20, 2014

Thank's for remind me! I was in a hurry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment