Google Image Search - Show Image Dimensions

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

当前为 2020-04-22 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @namespace https://openuserjs.org/users/Taddiboy
  3. // @name Google Image Search - Show Image Dimensions
  4. // @name:de Google Bildersuche - Bildabmessungen anzeigen
  5. // @name:fr Google Image Search - Afficher les dimensions de l'image
  6. // @name:es Búsqueda de imágenes de Google - Mostrar las dimensiones de la imagen
  7. // @name:it Ricerca immagini su Google - Mostra le dimensioni delle immagini
  8. // @name:pl Wyszukiwanie obrazów Google - Pokaż wymiary obrazu
  9. // @name:ru Поиск изображений Google - Показать размеры изображений
  10. // @description Displays image dimensions (eg. "1920 × 1080") for each thumbnail on the Google Image Search results page.
  11. // @description:de Zeigt die Bildabmessungen (z. B. "1920 × 1080") für jedes Vorschaubild auf der Ergebnisseite der Google-Bildsuche an.
  12. // @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.
  13. // @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.
  14. // @description:it Visualizza le dimensioni dell'immagine (ad es. "1920 × 1080") per ogni miniatura nella pagina dei risultati della ricerca immagini di Google.
  15. // @description:pl Wyświetla wymiary obrazu (np. "1920 × 1080") dla każdej miniaturki na stronie wyników wyszukiwania obrazów Google.
  16. // @description:ru Отображает размеры изображения (например, "1920 × 1080") для каждой миниатюры на странице результатов поиска изображений Google.
  17. // @copyright 2020, Taddiboy (https://openuserjs.org/users/Taddiboy)
  18. // @license MIT
  19. // @author Taddiboy
  20. // @version 1.1.0
  21. // @icon https://i.imgur.com/7OeXVaf.png
  22. // @include https://*.google.tld/*tbm=isch*
  23. // @grant GM_addStyle
  24. // ==/UserScript==
  25.  
  26. (function () {
  27. 'use strict';
  28.  
  29. // Add Google's own CSS used for image dimensions
  30. GM_addStyle(`
  31. .img-dims {
  32. background-color: rgba(0,0,0,.5);
  33. border-radius: 2px 0 0 0;
  34. bottom: 0;
  35. box-shadow: 0 0 1px 0 rgba(0,0,0,.16);
  36. box-sizing: border-box;
  37. color: #f1f3f4;
  38. font-family: Roboto-Medium,Roboto,arial,sans-serif;
  39. font-size: 10px;
  40. right: 0;
  41. line-height: 12px;
  42. overflow: hidden;
  43. padding: 4px;
  44. position: absolute;
  45. white-space: nowrap;
  46. }
  47. `);
  48.  
  49. function showDims() {
  50. // Find all thumbnails & exclude the "already handled" class we set below
  51. const images = document.querySelectorAll('[data-ow]:not(.img-dims-added)');
  52.  
  53. // Loop through all thumbnails
  54. for (let i = 0; i < images.length; i++) {
  55. const image = images[i];
  56.  
  57. // Get original width from 'data-ow' attribute
  58. const width = image.getAttribute('data-ow');
  59.  
  60. // Get original height from 'data-oh' attribute
  61. const height = image.getAttribute('data-oh');
  62.  
  63. // Create DIV and insert text
  64. const dimensionsDiv = document.createElement("div");
  65. const dimensionsContent = document.createTextNode(width + " × " + height);
  66. dimensionsDiv.appendChild(dimensionsContent);
  67.  
  68. // Assign CSS class
  69. dimensionsDiv.classList.add("img-dims");
  70.  
  71. // Append everything to thumbnail
  72. image.firstChild.appendChild(dimensionsDiv);
  73.  
  74. // Add "already handled" type of class to the thumbnail
  75. image.classList.add("img-dims-added");
  76. }
  77. }
  78.  
  79. // Run script once on document ready
  80. showDims();
  81.  
  82. // Initialize new MutationObserver
  83. const mutationObserver = new MutationObserver(showDims);
  84.  
  85. // Let MutationObserver target the grid containing all thumbnails
  86. const targetNode = document.querySelector('div[data-id="GRID_STATE0"]');
  87.  
  88. // Run MutationObserver
  89. mutationObserver.observe(targetNode, {childList: true,subtree: true});
  90. })();

QingJ © 2025

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