🏠 Home 

Google Image Direct View

A different take on Google direct image viewer


Install this script?
Author's suggested script

You may also like Auto Load Big Image.


Install this script
  1. // ==UserScript==
  2. // @name Google Image Direct View
  3. // @version 3.6
  4. // @namespace Google_Image_Direct_View
  5. // @description A different take on Google direct image viewer
  6. // @author navchandar
  7. // @include https://www.google.tld/*tbm=isch*
  8. // @include https://www.google.tld/search?tbm=isch*
  9. // @include https://www.google.co.*/*tbm=isch*
  10. // @include https://www.google.co.*/search?tbm=isch*
  11. // @match https://lens.google.com/search*
  12. // @include https://lens.google.com/search*
  13. // @run-at document-end
  14. // @license MIT
  15. // @grant none
  16. // @homepage https://navchandar.github.io/
  17. // @homepage https://github.com/navchandar/
  18. // @homepageURL https://navchandar.github.io/
  19. // @contributionURL https://paypal.me/navchandar
  20. // @contributionAmount $5.00
  21. // @copyright 2019+, navchandar (https://openuserjs.org/users/navchandar)
  22. // @supportURL https://openuserjs.org/scripts/navchandar/Google_Image_Direct_View/issues
  23. // @setupURL https://openuserjs.org/install/navchandar/Google_Image_Direct_View.user.js
  24. // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAMAAAD04JH5AAAAYFBMVEUAAAAAzAAAzAAAzAAAywAAzQAAzgAAzAAAzAAAzAAAzgAAzAAAzgAAzAAAywAAywAAzAD///9/5X8/2D+f65/v++8v1S+/8r8f0h/P9c/f+N9f31+v76+P6I9v4m9P20/YL+UMAAAAEHRSTlMAD++/z38v359vH18/r49PSnNavQAAA7hJREFUeNrt2wuSoyAUBVDAH6LGi79oYtL73+XMVGUqncJEHiJOV81ZQHOVx2uDyJykZZ6com9OSV6mLIi0kDHeiGWxbwqeVwIrRJVztguVx7AU54r5VlcgqWq/tz4DWeZtKvhJwIk4eYmQYINk+9wLbCLqbYu+wmbVhtaQw4vcdeHH8CR2agulgDeiPOj2u08Dj+FZzKnjH5kgFdiBSInjH5ZACexEqLDzT68D+vj0BMTxwyeQ2Jmkjh82QYEAilANgN4OeIYgMh6kAOhlUCOYenECBIIRS5NQIaCKGUoEZT6jZQgqM3//BJYEqEBKHSYILjnwBpi3IMEBksOWgLkQCgRl/l+OQNfeu/NF/3U5N9cRRBF7UKAau4s2TQ0xg3Itwat+o7+BInErwWHS7/UD7GVOM3Dt9ScXSgLlsBPQ6RV9C2s5fQ1Met2AJ5t1AM/j6x7WqE8inbYyw1ZJW4T31wudr4+bPX7N+kULSwmpBIaXQW7ja2t6aUkgFIGArfPH1Ta71KFgjMNWa1zi+wLpYIkTanBe63ezw0Io7dvQqJ++sGTs6XOQs8RhCZyxrHnUx9wQlkEFS5f1yxv11N1bUFQsAnkGJvgTrQcwnwHu8CdiWGMushEeWQc405aY/wDGGiDwHKADgYcARh9uQBAgQNssCheg0Yv+B7AOkB0bILNoxUYf8BkgOj6AxArzv7HPANLigcR4Ih09BkjWd0fMca74bmyfOnKAgpX0ddjZpISdknGQq7D3GIDb/zCZjTnwEEAw5vJMdvEWIKL8OO2NZrg9QEL5eX7TT4OnACVpg6LXK2XQkPsAaYvm+feXn82HM7kRRcRNqunDNsjQETvhc5MqBQjN6KnvWjy03eTUilPiRqXZ989/TLT/BeZ++QnWOm1pgoXTI0AK7wluljPwEHtOcGlhI3Z7YXHv/Vw+UDi+sxrP+oO+gSXBnV9ajd3bm/8cnvTSSoFouC1MxHQFhdp4duHrNn2/9Pk6gET6eHU7tA8gE/zfenkd/OWt4AGOEBEPE8UIKGYmhYAU/RC5/wo8cBLiQGc56Sc7awRRs7dOCODEPqiwu+qQI6XmodKjzhRmPPSxavM0ZegE9MPdaYydxGnow/1m/R2ZIOY/5wOH3wkkPJOk8f0/IRWMLBVhl59JRfAkUj/zU69/4GO33/IMm2T59u8tsYGXby65FHAiJGd+KClchlfMH15kIMkKzjwrJazJku2ilhlWZbJmO1KFzD4NXii2P17mSRThRRQleeky7b8AeEEvYPjorH8AAAAASUVORK5CYII=
  25. // ==/UserScript==
  26. // If your device/extension is not running the script on Image search, try adding this above: // @include https://www.google.*
  27. // Check out this link: https://openuserjs.org/scripts/navchandar/Google_Image_Direct_View/issues/Alternative_to_tld_for_matching_domains_(for_non-Tampermonkey_users)_ for more details.
  28. // Updated image xpath locator to work on Google Images and Google Lens
  29. var img_locator = "//c-wiz[@jsname]/parent::div[not(contains(@style, 'display: none'))]//a[(contains(@jsaction, 'focus'))]//img[not(contains(@src, 'gstatic.com/favicon')) and not(contains(@style, 'hidden'))] | //c-wiz[@jsname]/parent::div[not(contains(@style, 'display: none'))]//a//img[contains(@jsaction, 'load') and not(contains(@src, 'gstatic.com/favicon')) and not(contains(@style, 'hidden'))]";
  30. var del_locator = "//c-wiz[@jsname]/parent::div[not(contains(@style, 'display: none'))]//a//img[contains(@style, 'hidden')]"
  31. var lens_locator1 = "//a/div//img[not(contains(@alt, 'tag') or contains(@alt, 'domain'))]";
  32. var lens_locator2 = "//a/div/img";
  33. // Function to get elements by XPath
  34. function get_elements_by_xpath(xpath, parent) {
  35. let r###lts = [];
  36. let query = document.evaluate(xpath, parent || document, null, XPathR###lt.ORDERED_NODE_SNAPSHOT_TYPE, null);
  37. for (let i = 0, length = query.snapshotLength; i < length; ++i) {
  38. r###lts.push(query.snapshotItem(i));
  39. }
  40. return r###lts;
  41. }
  42. // Function to check if a string contains a search term
  43. function has(string, search) {
  44. try {
  45. return string.includes(search);
  46. }
  47. catch (err) {
  48. return false;
  49. }
  50. }
  51. function is_lens() {
  52. return has(window.location.href, "lens.google.");
  53. }
  54. // Function to get the XPath locator for images
  55. function get_img_locator() {
  56. return is_lens() ? (lens_locator1 + " | " + lens_locator2) : img_locator;
  57. }
  58. // Function to get the XPath locator for image links
  59. function get_img_link_locator() {
  60. if (is_lens()) {
  61. return `${lens_locator2}//../../../a[@href] | ${lens_locator1}//../../../../../a[@href]`;
  62. }
  63. else {
  64. let img_xp = `(${img_locator})`;
  65. return `${img_xp}//../../../a[@href] | ${img_xp}//../../a[@href]`;
  66. }
  67. }
  68. // Check if the attribute exists and remove
  69. function remove_attr(elem, attr) {
  70. if (elem.hasAttribute(attr)) {
  71. elem.removeAttribute(attr);
  72. }
  73. }
  74. // Function to update image elements on the page
  75. function update_elements() {
  76. var int = 0;
  77. // remove duplicate hidden image elements
  78. var del_elems = get_elements_by_xpath(del_locator);
  79. if (del_elems) {
  80. console.log(del_elems.length.toString() + " del elems items found");
  81. for (var x = 0; x < del_elems.length; x++) {
  82. try {
  83. del_elems[x].remove();
  84. }
  85. catch (err) {
  86. console.log(err);
  87. }
  88. }
  89. }
  90. let imgXpath = get_img_locator();
  91. let linkXpath = get_img_link_locator()
  92. var Img_items = get_elements_by_xpath(imgXpath);
  93. console.log(Img_items.length.toString() + " Image items found");
  94. if (Img_items.length > 0) {
  95. var Link_items = get_elements_by_xpath(linkXpath);
  96. console.log(Link_items.length.toString() + " link items found");
  97. for (var i = 0; i < Img_items.length; i++) {
  98. try {
  99. if (Link_items && Link_items[i]) {
  100. console.log(Link_items[i].jsaction);
  101. var src = Img_items[i].src;
  102. var uri = Link_items[i].href;
  103. // Add target to open images in new tab
  104. Link_items[i].target = "_blank";
  105. Img_items[i].target = "_blank";
  106. if (uri != src) {
  107. int++;
  108. Link_items[i].title = "Image Loading... Wait...";
  109. if (has(src, "data:image")) {
  110. Link_items[i].href = src;
  111. Link_items[i].download = "Base64_Image.jpg";
  112. Link_items[i].title = "Base64 Image will be downloaded!";
  113. }
  114. else if (is_lens() && has(src, "https://encrypted")) {
  115. Link_items[i].href = src;
  116. Link_items[i].title = "Image URL updated!";
  117. remove_attr(Link_items[i], "jsaction");
  118. remove_attr(Link_items[i], "download");
  119. }
  120. else {
  121. if (!has(src, "https://encrypted")) {
  122. Link_items[i].href = src;
  123. Link_items[i].title = "Image URL updated!";
  124. remove_attr(Link_items[i], "jsaction");
  125. remove_attr(Link_items[i], "download");
  126. }
  127. }
  128. }
  129. else if (!Link_items[i].title || has(Link_items[i].title, "Wait")) {
  130. // Link is already updated. Update the title.
  131. if (has(uri, "data:image")) {
  132. Link_items[i].title = "Base64 Image will be downloaded!";
  133. }
  134. else {
  135. Link_items[i].title = "Image URL updated!";
  136. }
  137. }
  138. }
  139. }
  140. catch (err) {
  141. console.log(err);
  142. }
  143. }
  144. if (int > 0) {
  145. console.log("Updated " + int + " image links.");
  146. }
  147. }
  148. }
  149. // Start the script and update elements every 500 milli seconds
  150. (function () {
  151. 'use strict';
  152. setInterval(function () {
  153. update_elements();
  154. }, 500);
  155. })()