Skip to content

Instantly share code, notes, and snippets.

@SheaBelsky
Last active April 8, 2018 23:43
Show Gist options
  • Save SheaBelsky/96e1272116afc81b3c6d691ec1aecb0b to your computer and use it in GitHub Desktop.
Save SheaBelsky/96e1272116afc81b3c6d691ec1aecb0b to your computer and use it in GitHub Desktop.
Full Imgur page from file page

Redirect to full Imgur page from file page

It's happened to you. You're browsing cute cat pictures on Imgur, and someone adds one as a comment. You love it! You want to favorite it, and maybe upvote it! But opening the image in a new page just takes you to the file page. On Imgur's mobile clients, opening an image in the comments section lets you favorite it, but you can't do that on desktop.

Until now.

Installation

  1. Go to the "Code" section, and copy the line of code under "The Script"
  2. Make a new bookmark
  3. Where it asks for the URL, enter the line of code you copied
  4. Give it whatever name you want, I have mine as "Imgur Full Page" but it's up to you!
  5. Go to any Imgur file page (like this one!)
  6. Click the link in your address bar
  7. Admire Pusheen

Compatibility

All Internet browsers (desktop/mobile) should be able to use this without any issues.

Code

The Script:

javascript:void%20function()%7B%20window.location=%22https://imgur.com/%22+window.location.href.split(%22imgur.com/%22)%5B1%5D.split(%22.%22)%5B0%5D;%20%7D()

Expanded:

void function(){
    window.location=`https://imgur.com/${window.location.href.split("imgur.com/")[1].split(".")[0]}`;
}()

Expanded More:

void function(){
    const currentPage = window.location.href;
    const currentFileName = currentPage.split("imgur.com/")[1];
    const imgurID = currentFileName.split(".")[0];
    window.location = `https://imgur.com/${imgurID}`;
}()

What does it do?

  1. Grabs the full address of the current page (what's in the address bar)
  2. Splits everything before imgur.com/ into one element of an array, and everything that follows into another element of the same array.
  3. In the same string as above, we grab everything before the period (the file extension, regardless of what it is). This is now the unique ID of the image on Imgur.
  4. Redirect the user to the full page of the image, based on the ID from 3.

Example

  1. "https://i.imgur.com/BVJ4E9t.gif"
  2. ["https://i.imgur.com/", "BVJ4E9t.gif"] we only care about BVJ4E9t.gif
  3. ["BVJ4E9t", ".gif"]
  4. window.location = "https://imgur.com/BVJ4E9t"
  5. User is redirected to https://imgur.com/BVJ4E9t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment