Don't track me Google

Restores the 'View Image' button on Google Image search. Beta, report back issues!

Από την 16/02/2018. Δείτε την τελευταία έκδοση.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name           Don't track me Google
// @namespace      David Refoua <www.Refoua.me>
// @author         David Refoua
// @description    Restores the 'View Image' button on Google Image search. Beta, report back issues!
// @include        http://*.google.tld/*isch*
// @include        https://*.google.tld/*isch*
// @grant          unsafeWindow
// @run-at         document-start
// @version        0.1.0-beta
// ==/UserScript==

var resetViewBtn = (function() {
	'use strict';

	var getCousins = function(node, selector) {

		var found = null;

		while ( (parent = node.parentNode) && ( parent != node ) ) {

			node = parent;
			var list = node.querySelectorAll(selector);
      
			if ( list.length > 0 ) {
				found = list;
				break;
			}

		}

		return found;

	};

	var getImageLink = function(node) {

		/*
		var image_nodes = getCousins(node, '.irc_mi');

		for (var i in image_nodes) if ( image_nodes.hasOwnProperty(i) ) {
			var image_item = image_nodes[i];

			var image_source = image_item.getAttribute('src');
			if ( !image_source ) return image_source;
		}
		*/

		var related_nodes = getCousins(node, '.irc_rimask');

		for (var j in related_nodes) if ( related_nodes.hasOwnProperty(j) ) {
			var related_item = related_nodes[j];

			if ( related_item.classList.contains('irc_rist') ) {

				var target_image = related_item.querySelector('.target_image');

				var x, the_source;

				if ( target_image && ( x = target_image.parentNode ) && ( the_source = x.getAttribute('href') ) )
				{
					
					var image_match = the_source.match( /imgurl=([^\&]+)\&/i );

					if ( image_match && image_match.length > 0 ) {

						var image_link = image_match[1];
						while ( decodeURIComponent(image_link) != image_link ) image_link = decodeURIComponent(image_link);

						return image_link;

					}

				}

			}

		}

		return null;
		
	};
  
  
  var bottom_buttons = document.querySelectorAll('.irc_but_r');

	for ( var i = 0; i < bottom_buttons.length; i++ ) {

		var the_table = bottom_buttons[i];
		var img_addr = getImageLink(the_table);
		var visit_button_container = the_table.querySelector('.irc_vpl').parentNode;
		var view_image_button = visit_button_container.querySelector('.irc_view_image');
		
		if ( !view_image_button ) {
			var new_button = document.createElement("a");
			view_image_button = visit_button_container.appendChild(new_button);
			view_image_button.classList.add('irc_view_image');
      // TODO: use the waybackmachine to find what google originally used instead of `.irc_view_image`
		}
		
		view_image_button.style.display = ( img_addr ? '' : 'none' );

		// view_image_button.innerText = 'View Image';
		view_image_button.innerHTML = '<span class="_WKw">View Image</span>';

		view_image_button.setAttribute('href', img_addr);

		view_image_button.setAttribute('target', '_blank');
		view_image_button.setAttribute('tabindex', '0');

	}

});

/*
// TODO: find a valid event and don't use an interval
var eventsList = ['mouseup', 'keyup'];

for (var i in eventsList) if ( eventsList.hasOwnProperty(i) ) {
	document.addEventListener(eventsList[i], function(e){
		if (e.target && e.target.classList && e.target.classList.contains('irc_view_image') == false && e.target.parentNode.classList.contains('irc_view_image') == false )
			resetViewBtn();
	});
}
*/

setInterval(resetViewBtn, 500);