Bulk Export Dropbox Image URLs (2024)

Extracts image URLs from a Dropbox page and copies them to the clipboard when a button is clicked.

  1. // ==UserScript==
  2. // @name Bulk Export Dropbox Image URLs (2024)
  3. // @version 3.1.2
  4. // @description Extracts image URLs from a Dropbox page and copies them to the clipboard when a button is clicked.
  5. // @author sharmanhall
  6. // @supportURL https://github.com/tyhallcsu/dropbox-image-url-extractor/issues/new
  7. // @namespace https://github.com/tyhallcsu/dropbox-image-url-extractor
  8. // @homepageURL https://github.com/tyhallcsu/dropbox-image-url-extractor
  9. // @license MIT
  10. // @connect greasyfork.org
  11. // @connect sleazyfork.org
  12. // @connect github.com
  13. // @connect openuserjs.org
  14. // @match https://www.dropbox.com/*
  15. // @match *://*.dropbox.com/*
  16. // @grant GM_setClipboard
  17. // @grant GM_log
  18. // @compatible chrome
  19. // @compatible firefox
  20. // @compatible edge
  21. // @compatible opera
  22. // @compatible safari
  23. // @run-at document-idle
  24. // @icon https://cfl.dropboxstatic.com/static/metaserver/static/images/favicon-vfl8lUR9B.ico
  25. // ==/UserScript==
  26.  
  27. // NEW CONTRIBUTOR: [pixelsilo](https://www.dropboxforum.com/t5/user/viewprofilepage/user-id/1795103)
  28. // SOURCE: https://www.dropboxforum.com/t5/View-download-and-export/Export-Bulk-Dropbox-Image-Folder-URLs/m-p/744340/highlight/true#
  29. // -------------
  30. // This updated script adds a button to the page labeled "Convert Links and Download."
  31. // When the button is clicked, the script scrolls to the bottom of the page to load more links, converts the links to direct download links, and adds a textarea to the page with the list of links.
  32. // The links are also formatted with `wget` so that they can be used in the command line. The button is temporarily disabled after the links are converted and re-enabled after a few seconds.
  33. // Please note that this script is designed to work on Dropbox pages that match the URL pattern specified in the `@match` directive (`*://*.dropbox.com/*`).
  34. // If you encounter any issues, please make sure that the script is running on the appropriate Dropbox page.
  35.  
  36. (function() {
  37. 'use strict';
  38. const SECONDS_TO_WAIT_FOR_SCROLL = 1; // adjust as needed
  39. //const DOWNLOAD_URL_REPLACEMENT = '?dl=1';
  40. const DOWNLOAD_URL_REPLACEMENT = '?raw=1';
  41. // DELETED: MODIFIED BELOW || function to get all image link elements
  42. //function getImageLinks() {
  43. // const imageLinks = document.querySelectorAll('a.dig-Link.sl-link--file[href*="dl=0"]');
  44. // return Array.from(imageLinks).map(link => link.getAttribute('href').replace(/\?dl=0$/, DOWNLOAD_URL_REPLACEMENT));
  45. //}
  46.  
  47. function getImageLinks() {
  48. // Update the selector to match the Dropbox page structure
  49. const imageLinks = document.querySelectorAll('a.dig-Link._sl-file-name_1iaob_86.dig-Link--primary[href*="dl=0"]');
  50. return Array.from(imageLinks).map(link => link.getAttribute('href').replace(/\?dl=0$/, DOWNLOAD_URL_REPLACEMENT));
  51. }
  52. // function to scroll to the bottom of the page and wait for new images to load
  53. async function waitForImagesToLoad() {
  54. window.scrollTo(0, document.body.scrollHeight);
  55. await new Promise(resolve => setTimeout(resolve, SECONDS_TO_WAIT_FOR_SCROLL * 5000));
  56. }
  57. // create an array to hold the image URLs
  58. let imageUrls = [];
  59. // add a button to the page that will copy the image URLs to the clipboard when clicked
  60. const copyButton = document.createElement('button');
  61. copyButton.classList.add('dig-Button', 'dig-Button--primary', 'dig-Button--standard', 'copy-urls-button');
  62. copyButton.textContent = 'Copy all URLs';
  63. copyButton.style.position = 'fixed';
  64. copyButton.style.bottom = '20px';
  65. copyButton.style.right = '20px';
  66. copyButton.style.zIndex = '9999';
  67. document.body.appendChild(copyButton);
  68. // add a click event listener to the button
  69. copyButton.addEventListener('click', async function() {
  70. let finished = false;
  71. let numUrls = 0;
  72. while (!finished) {
  73. // scroll to the bottom of the page and wait for new images to load
  74. await waitForImagesToLoad();
  75. // get the newly loaded image URLs
  76. const newImageUrls = getImageLinks().filter(url => !imageUrls.includes(url));
  77. imageUrls.push(...newImageUrls);
  78. // check if all images have been loaded
  79. finished = newImageUrls.length === 0;
  80. numUrls += newImageUrls.length;
  81. }
  82. // join the image URLs into a string separated by newlines
  83. const imageUrlString = imageUrls.join('\n');
  84. // copy the image URL string to the clipboard
  85. GM_setClipboard(imageUrlString, 'text');
  86. // disable the button and change the text to indicate that the URLs have been copied
  87. copyButton.disabled = true;
  88. copyButton.textContent = `${numUrls} URL(s) copied to clipboard`;
  89. // enable the button again after 3 seconds
  90. setTimeout(function() {
  91. imageUrls = [];
  92. copyButton.disabled = false;
  93. copyButton.textContent = 'Copy all URLs';
  94. }, 3000);
  95. });
  96. })();