Skip to content

Instantly share code, notes, and snippets.

@oxguy3
Last active March 13, 2024 05:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oxguy3/9e0f0f224b10d5e364476d7e05019d45 to your computer and use it in GitHub Desktop.
Save oxguy3/9e0f0f224b10d5e364476d7e05019d45 to your computer and use it in GitHub Desktop.
Greasemonkey script to find the biggest version of an image on a variety of sites

Embiggener

This is a work-in-progress Greasemonkey script. If you are looking at a low resolution thumbnail-type image on one of the websites supported by this script, you can click your "Embiggen" bookmarklet, and you'll be redirected to the largest available version of that file. Currently, it works with:

  • YouTube (thumbnails)
  • Flickr
  • Bandcamp (album art, profile pics, etc)
  • Wikimedia Foundation sites (Wikipedia/etc)
  • Twitter

To install the script, you'll need the Tampermonkey extension if you're in Chrome (I believe Firefox natively supports Greasemonkey scripts but idk). Once it's installed, copy-paste the embiggener.js file into a new script and save it. Then, create a bookmark with the following URL: "javascript:runEmbiggener()" (if you're in Chrome, you'll need to create a bookmark of any web page, and then edit the URL to that). Any time you click that bookmark, it'll attempt to find the bigger version of whatever image you're looking at.

// ==UserScript==
// @name Embiggener
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Finds the biggest possible version of any image
// @author Hayden Schiff (oxguy3)
// @match *://*/*
// @grant unsafeWindow
// ==/UserScript==
function runParsers() {
var parsers = [
parseYouTube,
parseFlickr,
parseBandcamp,
parseWikimedia,
parseTwitter
];
var result = null;
parsers.forEach(function(parser) {
if (result !== null) return;
console.log("Testing "+parser.name.substring(5)+"...");
result = parser(window.location);
});
if (result !== null) {
window.location = result;
} else {
alert("Failed to embiggen! :(");
}
}
function parseYouTube(location) {
if (location.hostname == "i.ytimg.com") {
var re = /^\/vi\/([^"&?/ ]{11})\/\w+.jpg$/ig;
var result = re.exec(location.pathname);
if (result !== null) {
var videoId = result[1];
return "https://i.ytimg.com/vi/"+videoId+"/maxresdefault.jpg";
}
}
return null;
}
function parseFlickr(location) {
if (/farm\d\.staticflickr\.com/gi.test(location.hostname)) {
var re = /^\/\d{4}\/(\d{1,11})_[0-9a-f]{10}_\w(?:_d)?.jpg$/ig;
var result = re.exec(location.pathname);
if (result !== null) {
var photoId = result[1];
return "https://flickr.com/photo.gne?id="+photoId;
}
}
return null;
}
function parseBandcamp(location) {
if (/f\d\.bcbits\.com/gi.test(location.hostname)) {
var re = /^\/img\/(a?\d{10})_\d+.jpg$/ig;
var result = re.exec(location.pathname);
if (result !== null) {
var imgId = result[1];
return "https://f1.bcbits.com/img/"+imgId+"_0.jpg";
}
}
return null;
}
function parseWikimedia(location) {
if (location.hostname == "upload.wikimedia.org") {
var re = /^\/(\w+)\/(\w+)(?:\/thumb)?\/[0-9a-f]\/[0-9a-f]{2}\/([^#<>\[\]\|\{\}\/]+)(?:\/(?:page\d+-)?\d+px-[^#<>\[\]\|\{\}\/]+)?$/ig;
var result = re.exec(location.pathname);
if (result !== null) {
var website = result[1];
var language = result[2];
var filename = result[3];
// special case for .wikimedia.org domains
var specialLanguages = [ "commons", "species", "meta" ];
if (website == "wikipedia" && specialLanguages.indexOf(language) != -1) {
website = "wikimedia";
}
return "https://"+language+"."+website+".org/wiki/File:"+filename;
}
}
return null;
}
function parseTwitter(location) {
if (location.hostname == "pbs.twimg.com") {
var re = /^\/media\/([\w\d_]+)\.(\w+)(?:\:\w+)?$/ig;
var result = re.exec(location.pathname);
if (result !== null) {
var imageId = result[1];
var fileExt = result[2];
return "https://pbs.twimg.com/media/"+imageId+"."+fileExt+":large";
}
}
return null;
}
(function() {
'use strict';
unsafeWindow.runEmbiggener = runParsers;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment