Skip to content

Instantly share code, notes, and snippets.

@glyphobet
Created July 26, 2011 01:02
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 glyphobet/1105680 to your computer and use it in GitHub Desktop.
Save glyphobet/1105680 to your computer and use it in GitHub Desktop.
Firefox bookmarklet to get the current page's short URL, if one is defined. If no short URL is defined, gives you the option of getting one from TinyURL instead.
(function(){
var promptURL=function (url){
window.prompt("Copy short URL to clipboard:",url);
};
var links=document.getElementsByTagName('link');
for(var i=0;i<links.length;i++){
var tag=links[i];
if(tag.getAttribute('rel')=='shorturl' || tag.getAttribute('rel')=='shortlink' || tag.getAttribute('id')=='shorturl' || tag.getAttribute('id')=='shortlink'){
promptURL(tag.getAttribute('href'));
return;
}
}
if(document.getElementById('shortenurl')){/*Shapeways support*/
promptURL(document.getElementById('shortenurl').children[0].value);
return;
}
if(window.confirm("No short URL for this page found. Create one at TinyURL?")){
document.location='http://tinyurl.com/create.php?url='+encodeURIComponent(location.href);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment