Skip to content

Instantly share code, notes, and snippets.

@satyr
Created April 21, 2009 10:14
Show Gist options
  • Save satyr/99062 to your computer and use it in GitHub Desktop.
Save satyr/99062 to your computer and use it in GitHub Desktop.
// ==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