Skip to content

Instantly share code, notes, and snippets.

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 jesterjunk/722d9dcfeacc0414e7315846db3215db to your computer and use it in GitHub Desktop.
Save jesterjunk/722d9dcfeacc0414e7315846db3215db to your computer and use it in GitHub Desktop.
Bookmarklet for Flickr - Redirect staticflickr.com Flickr image to full Flickr image page

Bookmarklet for Flickr

Redirect staticflickr.com Flickr image to full Flickr image page

This bookmarklet is designed to work only on the domain staticflickr.com, if used on any other domain will result in an alert.


Minified Bookmarklet Code‌ ‌ ‌ ‌ ‌raw source file

javascript:(function(){if(window.location.hostname.indexOf('staticflickr.com')!==-1){var flickrImageID=window.location.pathname.match(/\/(\d+)_/)[1];var flickrPageURL="https://www.flickr.com/photo.gne?rb=1&id="+flickrImageID;window.location.href=flickrPageURL;}else{alert("This bookmarklet only works on staticflickr.com");}})();


Pretty Commented Code‌ ‌ ‌ ‌ ‌raw source file

(function() {

    // Check if the current domain is staticflickr.com
    if (window.location.hostname.indexOf('staticflickr.com') !== -1) {

        // Extract ID from the Flickr image URL
        var flickrImageID = window.location.pathname.match(/\/(\d+)_/)[1];

        // Construct the Flickr page redirect URL
        var flickrPageURL = "https://www.flickr.com/photo.gne?rb=1&id=" + flickrImageID;

        // Redirect browser to the constructed URL
        window.location.href = flickrPageURL;
    }
    else {

        // Alert if not on a staticflickr.com domain
        alert("This bookmarklet only works on staticflickr.com");
    }
})();



This is how the redirect works with the ID extracted from the static image:

       https://c1.staticflickr.com/9/8244/8557312903_6b2e58c8ac_o.jpg
                                          ··········
          https://flickr.com/photo.gne?id=8557312903    2 redirects
 https://www.flickr.com/photo.gne?rb=1&id=8557312903    1 redirect     <-- the bookmarklet uses this
                                          ··········
https://www.flickr.com/photos/sphaerolith/8557312903/   the above two redirecting URLs will
                                                        redirect to a URL similar to this one
javascript:(function(){if(window.location.hostname.indexOf('staticflickr.com')!==-1){var flickrImageID=window.location.pathname.match(/\/(\d+)_/)[1];var flickrPageURL="https://www.flickr.com/photo.gne?rb=1&id="+flickrImageID;window.location.href=flickrPageURL;}else{alert("This bookmarklet only works on staticflickr.com");}})();
(function() {
// Check if the current domain is staticflickr.com
if (window.location.hostname.indexOf('staticflickr.com') !== -1) {
// Extract ID from the Flickr image URL
var flickrImageID = window.location.pathname.match(/\/(\d+)_/)[1];
// Construct the Flickr page redirect URL
var flickrPageURL = "https://www.flickr.com/photo.gne?rb=1&id=" + flickrImageID;
// Redirect browser to the constructed URL
window.location.href = flickrPageURL;
}
else {
// Alert if not on a staticflickr.com domain
alert("This bookmarklet only works on staticflickr.com");
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment