Skip to content

Instantly share code, notes, and snippets.

@dvingerh
Last active May 25, 2020 11:59
Show Gist options
  • Save dvingerh/da145c4f4343811f4052b5efb79f4e91 to your computer and use it in GitHub Desktop.
Save dvingerh/da145c4f4343811f4052b5efb79f4e91 to your computer and use it in GitHub Desktop.
Google Images - View Image button
// ==UserScript==
// @name Google Images - View Image button
// @description Brings back the View Image button that Google has removed.
// @namespace Violentmonkey Scripts
// @grant GM_addStyle
// @require http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
// @require https://raw.githubusercontent.com/pie6k/jquery.initialize/master/jquery.initialize.min.js
// @include *google*
//
// ==/UserScript==
// This script was taken from https://github.com/weienlee/viewimages - I've only added some code for extra compatibility
var web_url = window.location.href;
if (web_url.indexOf("imgres?imgurl=") != -1) {
$(document).find("a").each(function() {
if ($(this).parent().parent().find('a.view-image-button').length == 0) {
if ($(this).find('span').length == 2) {
var img_url = $("meta[property='og:image']").attr("content");
$(this).parent().before(`<td class="view-image-td"><a class="view-image-button" href="` + img_url + `"target="_blank"><span>View Image</span></a></td>`);
}
}
});
}
$(document).on('click', '.rg_ic.rg_i', function(event) {
handleClick(event);
});
function handleClick(event) {
const img = event.target;
const container = img.closest('div');
let meta = $(container).find('.notranslate')[0].innerHTML;
meta = JSON.parse(meta);
const url = meta.ou;
insertButton(url);
}
function insertButton(url) {
const section = $('#irc_cc');
const layers = section[0].children;
let layer;
for (let i=0; i<layers.length; i++) {
if (layers[i].style.transform === "translate3d(0px, 0px, 0px)") {
layer = layers[i];
}
}
const table = $(layer).find('table.irc_but_r')[0];
const tr = $(table).find('tr');
$('.view-image-td').remove();
tr.prepend(renderButton(url));
}
function renderButton(url) {
return $(`
<td class="view-image-td">
<a
class="view-image-button"
href="` + url + `"
target="_blank"
>
<span>View Image</span>
</a>
</td>
`);
}
@Korb
Copy link

Korb commented May 25, 2020

Google Images - View Image button 0.0 does not work. Firefox 77.0b9 x64, Microsoft Windows 10.0.18363.836, Tampermonkey 4.10.6112.

@dvingerh
Copy link
Author

Google Images - View Image button 0.0 does not work. Firefox 77.0b9 x64, Microsoft Windows 10.0.18363.836, Tampermonkey 4.10.6112.

This gist is not being maintained

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment