Image Extractor And Download Button

Analyzes webpage inputs and downloads results as a .txt file

  1. // ==UserScript==
  2. // @name Image Extractor And Download Button
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.2
  5. // @license MIT
  6. // @author SijosxStudio
  7. // @url https://greasyfork.org/en/users/1375139-sijosxstudio
  8. // @description Analyzes webpage inputs and downloads results as a .txt file
  9. // @match *://*/*
  10. // @grant none
  11.  
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. // Function to determine if an image is likely an ad or logo
  18. function isRelevantImage(img) {
  19. const src = img.src.toLowerCase();
  20. const excludePatterns = [
  21. 'logo', // common pattern for logos
  22. 'ad', // common pattern for ads
  23. 'banner', // common pattern for banners
  24. 'tracker', // common for tracking pixels
  25. 'pixel', // 1x1 tracking pixels
  26. 'favicon', // favicon
  27. ];
  28.  
  29. // Exclude based on patterns or small sizes
  30. return !excludePatterns.some(pattern => src.includes(pattern)) && img.width > 100 && img.height > 100;
  31. }
  32.  
  33. // Collect relevant image URLs
  34. function collectImageUrls() {
  35. const imageUrls = Array.from(document.images)
  36. .filter(isRelevantImage)
  37. .map(img => img.src);
  38.  
  39. return Array.from(new Set(imageUrls)); // Remove duplicates
  40. }
  41.  
  42. // Prompt download of URLs as a text file
  43. function promptDownloadUrls(urls) {
  44. // Convert URLs to text and encode as a data URL
  45. const urlText = urls.join('\n');
  46. const dataUrl = `data:text plain;charset=utf-8,${encodeURIComponent(urlText)}`;
  47. // Create a link for download prompt
  48. const a = document.createElement('a');
  49. a.href = dataUrl;
  50. a.download = 'image_urls.txt';
  51.  
  52. // Append to document for iOS compatibility
  53. document.body.appendChild(a);
  54. // Simulate click to trigger download
  55. a.click();
  56. // Clean up
  57. document.body.removeChild(a);
  58. }
  59.  
  60. // Button to trigger URL collection and download prompt
  61. function addDownloadButton() {
  62. const button = document.createElement('button');
  63. button.textContent = 'Collect Image URLs';
  64. button.style.position = 'fixed';
  65. button.style.bottom = '10px';
  66. button.style.right = '10px';
  67. button.style.zIndex = 10000;
  68. button.style.padding = '10px 15px';
  69. button.style.backgroundColor = '#4CAF50';
  70. button.style.color = 'white';
  71. button.style.border = 'none';
  72. button.style.cursor = 'pointer';
  73. button.style.fontSize = '14px';
  74.  
  75. // When the button is clicked, collect URLs and prompt download
  76. button.onclick = () => {
  77. const imageUrls = collectImageUrls();
  78. if (imageUrls.length > 0) {
  79. promptDownloadUrls(imageUrls);
  80. } else {
  81. alert('No relevant images found on this page.');
  82. }
  83. };
  84.  
  85. document.body.appendChild(button);
  86. }
  87.  
  88. // Run script when the page fully loads
  89. window.addEventListener('load', addDownloadButton);
  90. })();