Google Image Search - Show Image Dimensions

Displays image dimensions (eg. "1920 × 1080") for each thumbnail on the Google Image Search results page.

  1. // ==UserScript==
  2. // @name Google Image Search - Show Image Dimensions
  3. // @name:de Google Bildersuche - Bildabmessungen anzeigen
  4. // @name:fr Google Image Search - Afficher les dimensions de l'image
  5. // @name:es Búsqueda de imágenes de Google - Mostrar las dimensiones de la imagen
  6. // @name:it Ricerca immagini su Google - Mostra le dimensioni delle immagini
  7. // @name:pl Wyszukiwanie obrazów Google - Pokaż wymiary obrazu
  8. // @name:ru Поиск изображений Google - Показать размеры изображений
  9. // @description Displays image dimensions (eg. "1920 × 1080") for each thumbnail on the Google Image Search results page.
  10. // @description:de Zeigt die Bildabmessungen (z. B. "1920 × 1080") für jedes Vorschaubild auf der Ergebnisseite der Google-Bildsuche an.
  11. // @description:fr Affiche les dimensions de l'image (par exemple, "1920 × 1080") pour chaque miniature sur la page de résultats de Google Image Search.
  12. // @description:es Muestra las dimensiones de la imagen (p. ej., "1920 × 1080") para cada miniatura de la página de resultados de Google Image Search.
  13. // @description:it Visualizza le dimensioni dell'immagine (ad es. "1920 × 1080") per ogni miniatura nella pagina dei risultati della ricerca immagini di Google.
  14. // @description:pl Wyświetla wymiary obrazu (np. "1920 × 1080") dla każdej miniaturki na stronie wyników wyszukiwania obrazów Google.
  15. // @description:ru Отображает размеры изображения (например, "1920 × 1080") для каждой миниатюры на странице результатов поиска изображений Google.
  16. // @namespace https://github.com/tadwohlrapp
  17. // @author Tad Wohlrapp
  18. // @version 1.4.0
  19. // @license MIT
  20. // @homepageURL https://github.com/tadwohlrapp/google-image-search-show-image-dimensions-userscript
  21. // @supportURL https://github.com/tadwohlrapp/google-image-search-show-image-dimensions-userscript/issues
  22. // @icon https://github.com/tadwohlrapp/google-image-search-show-image-dimensions-userscript/raw/main/icon.png
  23. // @inject-into content
  24. // @include https://*.google.tld/*tbm=isch*
  25. // @include https://*.google.tld/*udm=2*
  26. // @compatible firefox Tested on Firefox v124 with Violentmonkey v2.18.0, Tampermonkey v5.1.0 and Greasemonkey v4.12.0
  27. // @compatible chrome Tested on Chrome v123 with Violentmonkey v2.18.0 and Tampermonkey v5.1.0
  28. // ==/UserScript==
  29.  
  30. (function () {
  31. 'use strict';
  32.  
  33. const isNewUi = (new URL(location.href).searchParams.get('udm') === '2') && !(new URL(location.href).searchParams.get('tbm'));
  34. const DELAY_TIME = 500;
  35.  
  36. // Add Google's own CSS used for image dimensions
  37. addGlobalStyle(`
  38. .img-dims p {
  39. position: absolute;
  40. bottom: 0;
  41. right: 0;
  42. margin: 0;
  43. padding: 4px;
  44. color: #f1f3f4;
  45. background-color: rgba(0,0,0,.6);
  46. border-radius: 2px 0 ${isNewUi ? `12px` : `0`} 0;
  47. font-family: Roboto-Medium,Roboto,Arial,sans-serif;
  48. font-size: 10px;
  49. line-height: 12px;
  50. }
  51. `);
  52.  
  53. function showDims() {
  54.  
  55. // Find all thumbnails & exclude the "already handled" class we set below
  56. const thumbnails = document.querySelectorAll(
  57. isNewUi ? 'div[data-attrid="images universal"]:not(.img-dims)' : '[data-ow]:not(.img-dims):not([data-ismultirow])'
  58. );
  59.  
  60. // Loop through all thumbnails
  61. thumbnails.forEach((thumbnail) => {
  62. try {
  63. if (isNewUi) {
  64.  
  65. // Dispatch a mouseover event for every thumbnail to generate the href attribute
  66. const dimensionsTrigger = thumbnail.querySelector('h3>a:not([href])>div');
  67. if (!dimensionsTrigger) return;
  68. dimensionsTrigger.dispatchEvent(new MouseEvent('mouseover', { bubbles: true }));
  69.  
  70. setTimeout(() => {
  71.  
  72. // Check if link element received its href attribute
  73. const linkElement = dimensionsTrigger.parentElement;
  74. if (linkElement?.href) {
  75.  
  76. // Add CSS class to the thumbnail
  77. thumbnail.classList.add('img-dims');
  78.  
  79. // Extract width and height from url parameters using destructuring
  80. const [, width, height] = /&w=(\d+)&h=(\d+)/.exec(linkElement.href) || [];
  81.  
  82. // Create p tag and insert text
  83. const dimensionsElement = document.createElement('p');
  84. dimensionsElement.textContent = `${width} × ${height}`;
  85.  
  86. // Append everything to thumbnail
  87. linkElement.appendChild(dimensionsElement);
  88. }
  89. }, DELAY_TIME);
  90. } else {
  91.  
  92. // Get original width from 'data-ow' attribute
  93. const width = thumbnail.getAttribute('data-ow');
  94.  
  95. // Get original height from 'data-oh' attribute
  96. const height = thumbnail.getAttribute('data-oh');
  97.  
  98. // Create p tag and insert text
  99. const dimensionsElement = document.createElement('p');
  100. dimensionsElement.textContent = `${width} × ${height}`;
  101.  
  102. // Append everything to thumbnail
  103. thumbnail.children[1].appendChild(dimensionsElement);
  104.  
  105. // Add CSS class to the thumbnail
  106. thumbnail.classList.add('img-dims');
  107. }
  108.  
  109. } catch (error) {
  110. console.error(error);
  111. }
  112. });
  113. }
  114.  
  115. // Run script once on document ready
  116. showDims();
  117.  
  118. // Initialize new MutationObserver
  119. const mutationObserver = new MutationObserver(showDims);
  120.  
  121. // Let MutationObserver target the grid containing all thumbnails
  122. const targetNode = document.querySelector(isNewUi ? 'div#rso' : 'div[data-cid="GRID_STATE0"]');
  123.  
  124. // Run MutationObserver
  125. mutationObserver.observe(targetNode, { childList: true, subtree: true });
  126.  
  127. function addGlobalStyle(css) {
  128. const head = document.querySelector('head');
  129. if (!head) return;
  130. const style = document.createElement('style');
  131. style.textContent = css;
  132. head.appendChild(style);
  133. }
  134. })();

QingJ © 2025

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