Skip to content

Commit

Permalink
Use canonical URL for tinyurl creation (closes #3).
Browse files Browse the repository at this point in the history
  • Loading branch information
Fred Wenzel committed Jul 23, 2010
1 parent a7d9dc1 commit 62e31eb
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/main.js
Expand Up @@ -17,6 +17,10 @@ function findShortUrl(ctx) {
/** Create a short URL from tinyurl.com */
function createShortUrl(ctx) {
let req = new xhr.XMLHttpRequest(),
url, canonical;
// use canonical URL if it exists, current URL otherwise.
canonical = ctx.document.querySelector('link[rel=canonical]');
if (!(canonical && (url = canonical.getAttribute('href'))))
url = ctx.document.URL;
req.open("GET", "http://tinyurl.com/api-create.php?url="
+encodeURIComponent(url), false);
Expand Down

0 comments on commit 62e31eb

Please sign in to comment.