Skip to content

Instantly share code, notes, and snippets.

@killwing
Created June 9, 2011 08:54
Show Gist options
  • Save killwing/1016372 to your computer and use it in GitHub Desktop.
Save killwing/1016372 to your computer and use it in GitHub Desktop.
[flickrshortener] make flickr link short
<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