All pastes #1085772 Raw Edit

Linked Images Bookmarklet

public javascript v1 · immutable
#1085772 ·published 2008-07-29 00:33 UTC
rendered paste body
#!/bin/bash##// Javascript Bookmarklet#// Opens all images linked from a given page on a new page.#cat $0 | sed 's@^#@@' | sed 's@//.*$@@' | sed 's@^[\t ]*$@@' | sed 's@^!/bin/bash@@' | sed 's@^cat .*@@' | sed '/^$/d' | sed 's@^[\t ]*@@' | tr '\n' ' ' && echo ""#javascript:(function(){##//Identify images#//Return true if an image#function I(u){#	 //Split the URL in two#	 var t=u.split('.');##	 //The extension is stored in e#	 var e=t[t.length-1].toLowerCase();##	 //Return true if e is one of the following extensions#	 return {gif:1,jpg:1,jpeg:1,png:1,mng:1}[e]#}##//HTML ESCAPE#//Replace special characters with HTML escape codes.#function hE(s){#	 return s.replace(/&/g,'&amp;').replace(/>/g,'&gt;').replace(/</g,'&lt;').replace(/"/g,'&quot;');#}##// q = Temporary link holder#// h = Temporary URL holder#// i = Loop iterator#// z = Document output stream#var q,h,i,z=open().document;##//Write the document header#z.write('<p>Images linked to by '+hE(location.href)+':</p><hr>');##//For all links on the page#for(i=0;q=document.links[i];++i){#	//Get the URL of the link#	h=q.href;##	//If it's non-null and ends in the right extension#	if(h&&I(h))#		//Write out the <img> tag#		z.write('<p>'+q.innerHTML+' ('+hE(h)+')<br><img src="'+hE(h)+'">');#}##//Close the output stream#z.close();##})()