Greasy Fork 还支持 简体中文。

HF Group Image "OG"

Reduces group images

目前為 2024-10-23 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name HF Group Image "OG"
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Reduces group images
  6. // @author gloom
  7. // @match *://*/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Function to resize group images
  16. function resizeGroupImages() {
  17. // Find all images that have a src containing 'images/groupimages'
  18. const groupImages = document.querySelectorAll('img[src*="images/groupimages"]');
  19.  
  20. groupImages.forEach(img => {
  21. // Get current dimensions from width/height attributes
  22. let currentWidth = parseInt(img.getAttribute('width'));
  23. let currentHeight = parseInt(img.getAttribute('height'));
  24.  
  25. // Sets the new dimensions
  26. if (!isNaN(currentWidth) && !isNaN(currentHeight)) {
  27. const newWidth = currentWidth - 40;
  28. const newHeight = currentHeight - 15;
  29.  
  30. img.setAttribute('width', newWidth);
  31. img.setAttribute('height', newHeight);
  32. // Also set style to ensure it takes effect
  33. img.style.width = newWidth + 'px';
  34. img.style.height = newHeight + 'px';
  35. }
  36. });
  37. }
  38.  
  39. // Runs when page loads
  40. window.addEventListener('load', resizeGroupImages);
  41.  
  42. // Run for dynamically loaded images
  43. const observer = new MutationObserver(resizeGroupImages);
  44. observer.observe(document.body, {
  45. childList: true,
  46. subtree: true
  47. });
  48. })();