Greasy Fork

Greasy Fork is available in English.

Google Images direct link fix

Adds a direct button link for the image.

当前为 2019-12-05 提交的版本,查看 最新版本

// ==UserScript==
// @name     Google Images direct link fix
// @description	Adds a direct button link for the image.
// @version  1.4b
// @grant    none
// @include  https://www.google.com/search?q=*
// @require  https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
// @namespace http://greasyfork.icu/users/11231
// ==/UserScript==

var tar, x, progressBar;

$(window).on("load", function() {
Checker();
  
$(window).click(function(e) { 
if ( $(e.target).prop("tagName") == 'IMG' ) {	$("#aTheIMG").remove(); Checker(); } 
});
  
});


async function Checker() { setTimeout(function() {
  if (!progressBar){
if ( $('div:nth-child(2) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(2) > div:nth-child(2)').length )  {
progressBar = $('div:nth-child(2) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(2) > div:nth-child(2)');     
} else if ( $('div.irc_c:nth-child(3) > div:nth-child(1) > div:nth-child(3)').length ) {
progressBar = $('div.irc_c:nth-child(3) > div:nth-child(1) > div:nth-child(3)'); }
}  
  
if ( $(progressBar).css('display') != 'none' ) {
  Checker();
} else {
  theWork();
}
  
}, 500); }
                 

function theWork() {
var xIMG, xPlaceholder, xCurrentClass, xPos;
  if ( $('body').attr('data-has-header') == 'true' ) {  
  	xIMG = $("div:nth-child(2) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(2) > a:nth-child(1) > img:nth-child(1)");
  	xPlaceholder = $(".fwCBrd");
    xCurrentClass = 'dJcyOc';
    xPos = '-139px';
  } else { //Private Mode
    xIMG = $("div.irc_c:nth-child(3) > div:nth-child(1) > div:nth-child(4) > div:nth-child(1) > a:nth-child(1) > div:nth-child(1) > img:nth-child(1)");
    xPlaceholder = $(".hZC4Sd > div:nth-child(1) > div:nth-child(1) > div:nth-child(2)");
    xCurrentClass = 'NDcgDe';
    xPos = '-85px';
  }
  
	if ( !$(xIMG).attr("src").match("^https://encrypted-tbn") ) {
		tar = $(xIMG);
		x = $(tar).attr("src");
    if (x.startsWith("data:imag")) {theWork(); return true;}
	if (!$("#aTheIMG").length) $(xPlaceholder).append('<a class="'+xCurrentClass+'" id="aTheIMG" style="left:'+xPos+'" href="' + x + '" title="Open image in new tab" target="_blank" ><span>View image</span></a>'); else ;
	} else {};
	x = "";
	$('div:nth-child(2) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1)').remove(); //Left-Right Arrows
if ( !$('#aTheIMG').length() ) { theWork(); }  
}

$( '<style>' ).text(' \
#aTheIMG { \
position: relative; \
z-index: 1; \
top: 1px; \
margin-left: -84px; \
text-decoration: none !important; \
} \
#aTheIMG > span {padding-left: 3px;} \
#aTheIMG:hover { \
filter: brightness(1.3); \
} \
div:nth-child(2) > div:nth-child(1) > div:nth-child(1) > div:nth-child(3) > div:nth-child(1) > div:nth-child(1) > a:nth-child(3), .hZC4Sd > div:nth-child(1) > div:nth-child(1) > div:nth-child(2) > a:nth-child(1) { \
margin-right: -0px; \
} \
div:nth-child(2) > div:nth-child(1) > div:nth-child(1) > div:nth-child(3) > div:nth-child(1) > div:nth-child(1) > a:nth-child(1), .hZC4Sd > div:nth-child(1) > div:nth-child(1) > div:nth-child(2) > a:nth-child(1) {pointer-events: none !important;} \
div:nth-child(2) > div:nth-child(1) > div:nth-child(1) > div:nth-child(3) > div:nth-child(1) > div:nth-child(1) > a:nth-child(1) > div:nth-child(1), .hZC4Sd > div:nth-child(1) > div:nth-child(1) > div:nth-child(2) > a:nth-child(1) > div:nth-child(1) {pointer-events: all !important;} \
' ).appendTo( document.head );