Created
June 9, 2011 08:54
-
-
Save killwing/1016372 to your computer and use it in GitHub Desktop.
[flickrshortener] make flickr link short
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script type="text/javascript"> | |
function shorten() { | |
var s = document.getElementById("url").value.match(/^https?:\/\/[^/]*\bflickr\.com\/(photos\/[^/]+\/(\d+))/i); | |
if (s && s.length && s[2]) { | |
var num = s[2]; | |
if (typeof num !== 'number') { | |
num=parseInt(num); | |
} | |
var enc = ''; | |
var alpha = '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ'; | |
var div = num; | |
var mod; | |
while (num >= 58) { | |
div = num/58; | |
mod = num-(58*Math.floor(div)); | |
enc = ''+alpha.substr(mod,1)+enc; | |
num = Math.floor(div); | |
} | |
var ret = (div)?''+alpha.substr(div,1)+enc:enc; | |
document.write("<a href='http://flic.kr/p/"+ret+"'/'>GO TO SEE!</a>"); | |
} else { | |
alert('Invalid Flickr URL!'); | |
} | |
} | |
</script> | |
</head> | |
<body> | |
<input id="url" type="text"> | |
<input type="button" value="shorten it!" onclick="shorten()"> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment