Google Image Direct Link Patch

Make clicking on image bottom panel go directly to the image in a Google Image search result. Use SHIFT+Click to open image in a new tab.

当前为 2018-04-03 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Google Image Direct Link Patch
  3. // @namespace GoogleImageDirectLinkPatch
  4. // @description Make clicking on image bottom panel go directly to the image in a Google Image search result. Use SHIFT+Click to open image in a new tab.
  5. // @version 1.1.4
  6. // @license AGPL v3
  7. // @author jcunews
  8. // @include /^https:\/\/www\.google\.(co\.)?[a-z]{2,3}\/search.*tbm=isch/
  9. // @include /^https:\/\/www\.google\.com(\.[a-z]{2,3})?\/search.*tbm=isch/
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. //*** Settings Start ***
  14. var bottomPanelBackgroundColor = "rgba(51,51,51,0.8)"; //"rgba(51,51,51,0.8)" is the default. Alpha (4th number) is the opacity level.
  15. var bottomPanelFontColor = "#FFF"; //"#FFF" is the default.
  16. var bottomPanelFontSize = "11px"; //"11px" is the default. Can be e.g. "9pt" for size in Points.
  17. var bottomPanelFontWeight = "normal"; //"normal is the default. Can be "bold".
  18. //*** Settings End ***
  19.  
  20. //add bottom panel style override
  21. var ele = document.createElement("STYLE");
  22. ele.innerHTML = ".rg_ilmbg,a.rg_ilmbg:link,a.rg_ilmbg:visited{background-color:" + bottomPanelBackgroundColor + ";color:" + bottomPanelFontColor + ";font-size:" + bottomPanelFontSize + ";font-weight:" + bottomPanelFontWeight + "}";
  23. document.body.appendChild(ele);
  24.  
  25. //add the click handler to the direct image
  26. document.addEventListener("click", function(ev) {
  27. var ele = ev.target, url;
  28. if (!ev.button && (ele.tagName === "A") && ele.classList.contains("rg_ilmbg")) {
  29. if (ev.stopImmediatePropagation) {
  30. ev.stopImmediatePropagation();
  31. }
  32. if (ev.stopPropagation) {
  33. ev.stopPropagation();
  34. }
  35. ev.preventDefault();
  36. if (ev.shiftKey) {
  37. window.open(ele.href);
  38. } else {
  39. window.location.href = ele.href;
  40. }
  41. }
  42. }, true);
  43.  
  44. //add direct image URL to the image bottom panel
  45. document.addEventListener("mouseover", function(ev) {
  46. var panel = ele = ev.target, url, link;
  47. if ((ele.className === "rg_ilmbg") && (panel.tagName !== "A") && ele.parentNode) {
  48. ele = ele.parentNode;
  49. url = ele.search.match(/imgurl=([^&]+)/);
  50. if (url) {
  51. url = decodeURIComponent(url[1]);
  52. link = document.createElement("A");
  53. link.href = url;
  54. link.className = "rg_ilmbg";
  55. link.innerHTML = panel.innerHTML;
  56. panel.parentNode.replaceChild(link, panel);
  57. }
  58. }
  59. }, true);

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址