Last active
August 29, 2015 14:03
-
-
Save ultimape/f5e76c9c0fa9930a0a52 to your computer and use it in GitHub Desktop.
An update to an old bookmarklet I found. It scours a page for links to images and creates a new page with the (non-thumb) version of those images. Now compatible with webm. Works great for popular image boards.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:(function(){function I(u){var t=u.split('.'),e=t[t.length-1].toLowerCase();return{gif:1,jpg:1,jpeg:1,png:1,mng:1,webm:1,} [e]} function J(f){if((f.indexOf('thumbs')==-1)&&(f.indexOf("t.4cdn")==-1)){return 1;}else{return 0;}} function hE(s){return s.replace(/&/g,'&').replace(/>/g,'>').replace(/</g,'<').replace(/"/g,'"');} function wrap(href){var t=href.split('.'),e=t[t.length-1].toLowerCase(),s='<p>'+q.innerHTML+' ('+hE(h)+') <br/>';if({webm:1}[e]){s+='<video controls="" loop="" src="'+hE(h)+'" style="max-width: 1280px; max-height: 720px;"></video>';} else{s+='<img style="max-height:690" src="'+hE(h)+'">';} s+='<hr/>';return s;} var q,h,i,z=open().document;z.title="images from "+location.href;z.write('<p>Images linked to by '+hE(location.href)+':</p><hr>');for(i=0;q=document.links[i];++i){h=q.href;if(h&&I(h)&&J(q.innerHTML)) z.write(wrap(h));} z.close();})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* this is a nasty hairball of code that is meant to be minified and ran as a bookmarklet. */ | |
javascript : (function () { | |
/* returns true if a url is a valid image */ | |
function isImage(u) { | |
var t = u.split('.'), | |
e = t[t.length - 1].toLowerCase(); | |
return { | |
gif : 1, | |
jpg : 1, | |
jpeg : 1, | |
png : 1, | |
mng : 1, | |
webm : 1, | |
} | |
[e] /* ugly hack*/ | |
} | |
/* returns true if the image does not appear to be a thumbnail | |
Uses a hueristic. */ | |
function isNotThumbnail(f) { | |
if ((f.indexOf('thumbs') == -1) && (f.indexOf("t.4cdn") == -1)) { | |
return 1; | |
} else { | |
return 0; | |
} | |
} | |
/* returns a string that contains fixes for some issues with the href we get from the url */ | |
function humanReadableHref(s) { | |
return s.replace(/&/g, '&').replace(/>/g, '>').replace(/</g, '<').replace(/"/g, '"'); | |
} | |
/* returns a string that is the correct html tag to show the image/webm */ | |
function wrap(href) { | |
var t = href.split('.'), | |
e = t[t.length - 1].toLowerCase(), | |
s = '<p>' + currentLink.innerHTML + ' (' + humanReadableHref(currentLinkHref) + ') <br/>'; | |
if ({ webm : 1}[e]) { /* ugly hack*/ | |
s += '<video controls="" loop="" src="' + humanReadableHref(currentLinkHref) + '" style="max-width: 1280px; max-height: 720px;"></video>'; | |
} else { | |
s += '<img style="max-height:690" src="' + humanReadableHref(currentLinkHref) + '">'; | |
} | |
s += '<hr/>'; | |
return s; | |
} | |
/* main*/ | |
var currentLink, | |
currentLinkHref, | |
i, | |
newDocument = open().document; | |
newDocument.title = "images from " + location.href; | |
newDocument.write('<p>Images linked to by ' + humanReadableHref(location.href) + ':</p><hr>'); | |
/* for each link in the page, | |
inspect it to see if it is an image, | |
and write out the appropriate tag */ | |
for (i = 0; currentLink = document.links[i]; ++i) { | |
currentLinkHref = currentLink.href; | |
if (currentLinkHref && isImage(currentLinkHref) && isNotThumbnail(currentLink.innerHTML)) | |
newDocument.write(wrap(currentLinkHref)); | |
} | |
newDocument.close(); | |
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript : (function () { | |
function I(u) { | |
var t = u.split('.'), | |
e = t[t.length - 1].toLowerCase(); | |
return { | |
gif : 1, | |
jpg : 1, | |
jpeg : 1, | |
png : 1, | |
mng : 1, | |
webm : 1, | |
} | |
[e] | |
} | |
function J(f) { | |
if ((f.indexOf('thumbs') == -1) && (f.indexOf("t.4cdn") == -1)) { | |
return 1; | |
} else { | |
return 0; | |
} | |
} | |
function hE(s) { | |
return s.replace(/&/g, '&').replace(/>/g, '>').replace(/</g, '<').replace(/"/g, '"'); | |
} | |
function wrap(href) { | |
var t = href.split('.'), | |
e = t[t.length - 1].toLowerCase(), | |
s = '<p>' + q.innerHTML + ' (' + hE(h) + ') <br/>'; | |
if ({ | |
webm : 1 | |
} | |
[e]) { | |
s += '<video controls="" loop="" src="' + hE(h) + '" style="max-width: 1280px; max-height: 720px;"></video>'; | |
} else { | |
s += '<img style="max-height:690" src="' + hE(h) + '">'; | |
} | |
s += '<hr/>'; | |
return s; | |
} | |
var q, | |
h, | |
i, | |
z = open().document; | |
z.title = "images from " + location.href; | |
z.write('<p>Images linked to by ' + hE(location.href) + ':</p><hr>'); | |
for (i = 0; q = document.links[i]; ++i) { | |
h = q.href; | |
if (h && I(h) && J(q.innerHTML)) | |
z.write(wrap(h)); | |
} | |
z.close(); | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment