Greasy Fork 还支持 简体中文。

Google Images direct links

Add direct links to the Google Images search results. LeftClick to open image, CTRL+LeftClick to open source page

目前為 2017-02-15 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Google Images direct links
  3. // @version 1.2
  4. // @namespace Google
  5. // @author Benjamin Philipp <benjamin_philipp [at - please don't spam] gmx.de>
  6. // @description Add direct links to the Google Images search results. LeftClick to open image, CTRL+LeftClick to open source page
  7. // @include /^https?:\/\/(www\.)*google\.[a-z\.]{2,5}\/search.*tbm=isch.*/
  8. // @require http://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js
  9. // @run-at document-body
  10. // ==/UserScript==
  11.  
  12. var maxtries = 10;
  13.  
  14. var idle = true;
  15. var disableUpdate = false;
  16.  
  17. function updatePage()
  18. {
  19. if($("#directLinkStyles").length<=0){
  20. disableUpdate = true;
  21. $("head").append("\
  22. <style id='directLinkStyles'>\
  23. .linkToTarget{\
  24. box-shadow: 3px 5px 10px rgba(0,0,0,0.5); \
  25. position: absolute; \
  26. right:0; top:0; \
  27. opacity: 0.5; \
  28. background-color: rgba(255,255,255,0.3);\
  29. transition: background-color 0.5s, opacity 0.5s \
  30. }\
  31. .linkToTarget:hover{\
  32. opacity: 1; \
  33. background-color: rgba(255,255,255,1);\
  34. }\
  35. .linkToTargetLink, .linkToTarget>span{\
  36. color: rgba(200,200,200, 0.7)!important; \
  37. padding: 3px 10px; \
  38. font-size: 28pt; \
  39. display: block; \
  40. font-weight: bold; \
  41. text-decoration: none;\
  42. transition: color 0.5s, font-size 0.5s, padding 0.5s; \
  43. }\
  44. .linkToTargetLink:hover{\
  45. color: rgba(155,177,233, 1)!important; \
  46. padding:8px 20px; \
  47. font-size: 36pt; \
  48. } \
  49. .linkswait{ \
  50. box-shadow: 0 0 20px #f00; \
  51. border: 2px solid #f00; \
  52. border-radius: 5px; \
  53. </style>");
  54. disableUpdate = false;
  55. }
  56.  
  57. $(".rg_di.rg_bx a.rg_l:not(.linksdone):not([href='#'])").each(function(){
  58. var tp = this;
  59. var tppar = $(this).parent();
  60. var imin = tp.href.indexOf("imgurl=");
  61. if(imin<0)
  62. {
  63. $(tp).attr("resTries", $(tp).attr("resTries")?$(tp).attr("resTries")*1+1:1);
  64. if($(tp).attr("resTries")*1>=maxtries){
  65. console.log("This Link won't come up with a good fragment: " + $(tp).find("img")[0].src);
  66. return true;
  67. }
  68. updater();
  69. return true;
  70. }
  71. var linkconts = tp.href.substr(imin+7);
  72. var piclink = linkconts.substr(0,linkconts.indexOf("&"));
  73. var reflink = linkconts.substr(linkconts.indexOf("imgrefurl=")+10);
  74. reflink = decodeURIComponent(reflink.substr(0, reflink.indexOf("&")));
  75. piclink = decodeURIComponent(piclink);
  76. disableUpdate = true;
  77. var dirlink = $("<a class='linkToTargetLink' href='" + piclink + "' reflink='" + reflink + "' target='_blank'>+</a>");
  78. $(dirlink).click(function(e){
  79. var t = this;
  80. if(e.ctrlKey){
  81. window.open($(t).attr("reflink"));
  82. return false;
  83. }
  84. window.open(t.href);
  85. return false;
  86. });
  87. $(tppar).find(".linkToTarget.temp").remove();
  88. $(this).removeClass("linkswait");
  89. $(tppar).append($("<div/>", {class: 'linkToTarget'}).append(dirlink));
  90. $(this).addClass("linksdone");
  91. successlink = this;
  92. disableUpdate = false;
  93. });
  94. var notready = false;
  95. $(".rg_di.rg_bx a.rg_l[href='#']:not(.linksdone)").each(function(){
  96. notready = true;
  97. if(!$(this).hasClass("linkswait")){
  98. $(this).addClass("linkswait");
  99. $(this).parent().append("<div class='linkToTarget temp'><span>...</span></div>");
  100. }
  101. });
  102. if(notready){
  103. updater();
  104. }
  105. }
  106.  
  107. function updater(t = 1000){
  108. if(idle)
  109. {
  110. idle = false;
  111. updaterequest = false;
  112. updatePage();
  113. idletimer = setTimeout(function(){
  114. idle = true;
  115. if(updaterequest)
  116. updatePage();
  117. }, t);
  118. }
  119. else
  120. {
  121. updaterequest = true;
  122. }
  123. }
  124.  
  125. var bodyObserver = false;
  126. function observeResults(){
  127. // console.log("observing");
  128. resultsObserver = new MutationObserver(updater);
  129. resultsObserver.observe($("#ires #rg")[0], {subtree: true, childList: true});
  130. if(bodyObserver !== false)
  131. bodyObserver.disconnect();
  132. }
  133.  
  134.  
  135. if($("#ires #rg").length>0){
  136. observeResults();
  137. }
  138. else{
  139. bodyObserver = new MutationObserver(function(mutations){
  140. if(disableUpdate || !idle){
  141. return;
  142. }
  143. if($("#ires #rg").length>0)
  144. {
  145. observeResults();
  146. }
  147. });
  148. bodyObserver.observe($("body")[0], {subtree: true, childList: true});
  149. }
  150. updatePage();