Real-time Download Link Finder with Copy Button

Finds and displays all download links, and allows copying them to clipboard

  1. // ==UserScript==
  2. // @name Real-time Download Link Finder with Copy Button
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.4
  5. // @description Finds and displays all download links, and allows copying them to clipboard
  6. // @author motoe
  7. // @match https://making-new-thing-testing-pushing-huginface-yl-dl-1.hf.space/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Create a small floating window to show the download links
  16. let windowDiv = document.createElement("div");
  17. windowDiv.style.position = "fixed";
  18. windowDiv.style.bottom = "10px";
  19. windowDiv.style.right = "10px";
  20. windowDiv.style.backgroundColor = "rgba(0, 0, 0, 0.8)";
  21. windowDiv.style.color = "white";
  22. windowDiv.style.padding = "10px";
  23. windowDiv.style.zIndex = "1000";
  24. windowDiv.style.maxHeight = "200px";
  25. windowDiv.style.overflowY = "scroll";
  26. windowDiv.style.fontSize = "12px";
  27. windowDiv.style.borderRadius = "5px";
  28. windowDiv.style.width = "300px";
  29. windowDiv.style.boxShadow = "0 4px 8px rgba(0, 0, 0, 0.2)";
  30. document.body.appendChild(windowDiv);
  31.  
  32. // Create a copy button and append it to the window
  33. let copyButton = document.createElement("button");
  34. copyButton.textContent = "Copy URLs to Clipboard";
  35. copyButton.style.display = "block";
  36. copyButton.style.marginTop = "10px";
  37. copyButton.style.padding = "5px";
  38. copyButton.style.backgroundColor = "#28a745";
  39. copyButton.style.color = "white";
  40. copyButton.style.border = "none";
  41. copyButton.style.borderRadius = "4px";
  42. copyButton.style.cursor = "pointer";
  43. windowDiv.appendChild(copyButton);
  44.  
  45. let linksArray = []; // To store all the found URLs
  46.  
  47. // Function to check the page for download links in <a> elements with the 'download' attribute
  48. function scanForDownloadLinks() {
  49. let downloadLinks = document.querySelectorAll('a[download]');
  50. downloadLinks.forEach(link => {
  51. let href = link.getAttribute('href');
  52. if (href && !link.dataset.found) {
  53. link.dataset.found = "true";
  54. let fullUrl = new URL(href, window.location.origin).href;
  55. linksArray.push(fullUrl);
  56. let linkElement = document.createElement("div");
  57. linkElement.style.wordWrap = "break-word";
  58. linkElement.textContent = fullUrl;
  59. windowDiv.appendChild(linkElement);
  60. }
  61. });
  62. }
  63.  
  64. // Function to copy all URLs to clipboard
  65. copyButton.addEventListener("click", async () => {
  66. if (linksArray.length > 0) {
  67. try {
  68. await navigator.clipboard.writeText(linksArray.join('\n'));
  69. alert('URLs copied to clipboard!');
  70. } catch (err) {
  71. alert('Failed to copy URLs: ' + err);
  72. }
  73. } else {
  74. alert('No URLs found to copy!');
  75. }
  76. });
  77.  
  78. // Continuously scan for new download links every second
  79. setInterval(scanForDownloadLinks, 1000);
  80.  
  81. })();