Skip to content

Instantly share code, notes, and snippets.

@panzi
Last active August 29, 2015 14:05
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 panzi/e6b8e79bd3a393e59fe5 to your computer and use it in GitHub Desktop.
Save panzi/e6b8e79bd3a393e59fe5 to your computer and use it in GitHub Desktop.
Bookmarklet to find bigger version of an image on tumblr.

Copy this link and create bookmark with this as it's URL in your bookmark toolbar:

javascript:(function(){"use strict";function t(t){function l(e){var t=new XMLHttpRequest;t.onload=function(){if(this.status>=200&&this.status<400){a.push(e)}};t.onloadend=c;t.open("HEAD",r+e+s,true);t.send();++f}function c(){--f;if(f===0){if(a.length>0){a.sort(function(e,t){return e-t});var e=r+a[a.length-1]+s;location.href=e}else{alert("No bigger image found.")}}}var n=/^(.*_)(\d+)(\.[a-z]+)$/i.exec(t);if(!n){alert("Not a tumblr image URL.");return}var r=n[1];var i=Number(n[2]);var s=n[3];var o=null;for(var u=0;u<e.length;++u){if(e[u]>i){o=u;break}}if(o===null){alert("There is no bigger known size.");return}var a=[];var f=0;for(var u=o;u<e.length;++u){l(e[u])}}var e=[75,100,250,400,500,1280];t(location.href)})()

Then when you view a tumblr image and suspect that there is a bigger version of it click this bookmarklet.

(function () {
"use strict";
var Sizes = [75, 100, 250, 400, 500, 1280];
findBigger(location.href);
function findBigger (url) {
var m = /^(.*_)(\d+)(\.[a-z]+)$/i.exec(url);
if (!m) {
alert("Not a tumblr image URL.");
return;
}
var prefix = m[1];
var size = Number(m[2]);
var suffix = m[3];
var index = null;
for (var i = 0; i < Sizes.length; ++ i) {
if (Sizes[i] > size) {
index = i;
break;
}
}
if (index === null) {
alert("There is no bigger known size.");
return;
}
var supported = [];
var pending = 0;
for (var i = index; i < Sizes.length; ++ i) {
testSize(Sizes[i]);
}
function testSize (size) {
var xhr = new XMLHttpRequest();
xhr.onload = function () {
if (this.status >= 200 && this.status < 400) {
console.log("supported size:",size);
supported.push(size);
}
};
xhr.onloadend = loadend;
xhr.open('HEAD',prefix + size + suffix,true);
xhr.send();
++ pending;
}
function loadend () {
-- pending;
if (pending === 0) {
if (supported.length > 0) {
supported.sort(function (lhs, rhs) { return lhs - rhs; });
var newUrl = prefix + supported[supported.length - 1] + suffix;
console.log("found bigger:",newUrl);
location.href = newUrl;
}
else {
alert("No bigger image found.");
}
}
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment