Skip to content

Instantly share code, notes, and snippets.

@Glench
Created December 24, 2014 18:13
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 Glench/53e2c61d8f3e265361db to your computer and use it in GitHub Desktop.
Save Glench/53e2c61d8f3e265361db to your computer and use it in GitHub Desktop.
var baseUrl = 'http://127.0.0.1:5000';
var wikipedify = function(best_guess) {
return 'https://en.wikipedia.org/wiki/Special:Search/'+best_guess;
};
var makeLink = function(href, text, title) {
return '<a href="'+href+'" target="_blank" title="'+title+'">'+text+'</a>';
};
$('img').each(function(i, img) {
var $img = $(img)
$.get(baseUrl+'?image_url='+window.location.href+img.getAttribute('src')).done(function(data) {
data = JSON.parse(data)
var $div = $('<div>').attr('class', 'google-images-label').attr('title', 'best guess from google images').css({
position: 'absolute',
top: $img.offset().top,
left: $img.offset().left,
maxWidth: $img.width(),
fontSize: '12px',
backgroundColor: 'rgba(255,255,255,.6)'
});
$div.on('mouseenter', function() {
$(this).css('background-color', 'white');
}).on('mouseleave', function() {
$(this).css('background-color', 'rgba(255,255,255,.6)');
});
if (data.best_guess) {
$div.append(data.best_guess+' ('+makeLink(wikipedify(data.best_guess), 'wp', 'go to wikipedia page for this term')+' '+makeLink(data.search_url, 'imgs', 'open google images with this image')+')');
} else {
$div.append(makeLink(data.search_url, 'imgs', 'open google images with this image'));
}
$('body').append($div);
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment