Created
April 21, 2009 10:14
-
-
Save satyr/99062 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// ==UserScript== | |
// @name GImageHacks | |
// @namespace http://d.hatena.ne.jp/murky-satyr | |
// @description Direct links to the image/page + AutoPagerize support | |
// @include http://*.google.tld/images?* | |
// ==/UserScript== | |
directLinkify([document]); | |
microFormatize(document); | |
setTimeout(function(){ | |
AutoPagerize.addDocumentFilter(microFormatize); | |
AutoPagerize.addFilter(directLinkify); | |
}); | |
function directLinkify(nodes){ | |
nodes.forEach(function(node){ | |
Array.slice(node.getElementsByTagName('a')).forEach(function(a){ | |
var [, img, ref] = /\bimgurl=([^&]+)&imgrefurl=([^&]+)/(a.href) || 0; | |
if(!img) return; | |
a.parentNode.appendChild(document.createElement('div')).innerHTML = | |
<tt><a href={img}>img</a><a href={ref}>ref</a></tt>; | |
}); | |
}); | |
} | |
function microFormatize(doc){ | |
with(doc.querySelector('#nav .cur + td a')){ | |
rel = 'next'; | |
href = href.replace(/\bgbv=\d&?/, '') +'&gbv=1'; | |
} | |
Array.forEach(doc.getElementsByTagName('table'), function(tbl){ | |
if(Array.some(tbl.getElementsByTagName('a'), /\/imgres/)) | |
tbl.className += ' autopagerize_page_element'; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment