Skip to content

Instantly share code, notes, and snippets.

@fcalderan
Last active June 4, 2018 07:58
Show Gist options
  • Save fcalderan/24e38f2dc7fe04e14c28a2d37d5f9802 to your computer and use it in GitHub Desktop.
Save fcalderan/24e38f2dc7fe04e14c28a2d37d5f9802 to your computer and use it in GitHub Desktop.
Restore "Show image" in google image results
/* Usage:
* when Google image returns some results, before choosing an image just inject
* this code into the JS console and a new button with a direct link to the image
* will appear inside the overlay.
*/
var config = {
attributes: true,
childList: false,
characterData: false,
subtree: false,
attributeOldValue: true
};
var G_overlay = document.querySelectorAll('#irc_cc > div');
var G_re = /\.*translate3d\((.*)px,(.*)px,(.*)px\)/i;
var cb = function(mutationsList) {
for (m in mutationsList) {
if (mutationsList[m].attributeName === 'style') {
var target = mutationsList[m].target;
if (target.style.visibility === 'visible' &&
G_re.exec(target.style.transform)[1] === '0') {
return getImageUrl(mutationsList[m], target)
break;
}
}
}
};
var getImageUrl = function(m, target) {
//console.log(m, target)
var si = document.getElementById('showimage');
if (si) {
si.parentNode.removeChild(si);
}
setTimeout(function() {
var table = target.querySelector('.irc_but_r tr'),
cell = document.createElement('td'),
link = document.createElement('a'),
img = target.querySelector('.irc_t .irc_mic .irc_mimg img.irc_mi');
cell.id = "showimage";
link.target = "_blank";
link.href = "#";
link.innerHTML = "Show image";
cell.appendChild(link);
table.appendChild(cell);
document.querySelector('#showimage a').href = img.src;
}, 300);
}
var observer = new MutationObserver(cb);
[...G_overlay].map((overlay) => observer.observe(overlay, config));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment