Bulk Export Dropbox Image URLs (2024)

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

当前为 2024-01-17 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Bulk Export Dropbox Image URLs (2024)
  3. // @version 3.1.1
  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 gf.qytechs.cn
  11. // @connect sleazyfork.org
  12. // @connect github.com
  13. // @connect openuserjs.org
  14. // @match https://www.dropbox.com/*
  15. // @grant GM_setClipboard
  16. // @grant GM_log
  17. // @compatible chrome
  18. // @compatible firefox
  19. // @compatible edge
  20. // @compatible opera
  21. // @compatible safari
  22. // @run-at document-idle
  23. // @icon https://cfl.dropboxstatic.com/static/metaserver/static/images/favicon-vfl8lUR9B.ico
  24. // ==/UserScript==
  25.  
  26. // NEW CONTRIBUTOR: [pixelsilo](https://www.dropboxforum.com/t5/user/viewprofilepage/user-id/1795103)
  27. // SOURCE: https://www.dropboxforum.com/t5/View-download-and-export/Export-Bulk-Dropbox-Image-Folder-URLs/m-p/744340/highlight/true#
  28.  
  29. (function() {
  30. 'use strict';
  31. const SECONDS_TO_WAIT_FOR_SCROLL = 1; // adjust as needed
  32. const DOWNLOAD_URL_REPLACEMENT = '?raw=1';
  33. // DELETED: MODIFIED BELOW || function to get all image link elements
  34. //function getImageLinks() {
  35. // const imageLinks = document.querySelectorAll('a.dig-Link.sl-link--file[href*="dl=0"]');
  36. // return Array.from(imageLinks).map(link => link.getAttribute('href').replace(/\?dl=0$/, DOWNLOAD_URL_REPLACEMENT));
  37. //}
  38.  
  39. function getImageLinks() {
  40. // Update the selector to match the Dropbox page structure
  41. const imageLinks = document.querySelectorAll('a.dig-Link._sl-file-name_1iaob_86.dig-Link--primary[href*="dl=0"]');
  42. return Array.from(imageLinks).map(link => link.getAttribute('href').replace(/\?dl=0$/, DOWNLOAD_URL_REPLACEMENT));
  43. }
  44. // function to scroll to the bottom of the page and wait for new images to load
  45. async function waitForImagesToLoad() {
  46. window.scrollTo(0, document.body.scrollHeight);
  47. await new Promise(resolve => setTimeout(resolve, SECONDS_TO_WAIT_FOR_SCROLL * 1000));
  48. }
  49. // create an array to hold the image URLs
  50. let imageUrls = [];
  51. // add a button to the page that will copy the image URLs to the clipboard when clicked
  52. const copyButton = document.createElement('button');
  53. copyButton.classList.add('dig-Button', 'dig-Button--primary', 'dig-Button--standard', 'copy-urls-button');
  54. copyButton.textContent = 'Copy all URLs';
  55. copyButton.style.position = 'fixed';
  56. copyButton.style.bottom = '20px';
  57. copyButton.style.right = '20px';
  58. copyButton.style.zIndex = '9999';
  59. document.body.appendChild(copyButton);
  60. // add a click event listener to the button
  61. copyButton.addEventListener('click', async function() {
  62. let finished = false;
  63. let numUrls = 0;
  64. while (!finished) {
  65. // scroll to the bottom of the page and wait for new images to load
  66. await waitForImagesToLoad();
  67. // get the newly loaded image URLs
  68. const newImageUrls = getImageLinks().filter(url => !imageUrls.includes(url));
  69. imageUrls.push(...newImageUrls);
  70. // check if all images have been loaded
  71. finished = newImageUrls.length === 0;
  72. numUrls += newImageUrls.length;
  73. }
  74. // join the image URLs into a string separated by newlines
  75. const imageUrlString = imageUrls.join('\n');
  76. // copy the image URL string to the clipboard
  77. GM_setClipboard(imageUrlString, 'text');
  78. // disable the button and change the text to indicate that the URLs have been copied
  79. copyButton.disabled = true;
  80. copyButton.textContent = `${numUrls} URL(s) copied to clipboard`;
  81. // enable the button again after 3 seconds
  82. setTimeout(function() {
  83. imageUrls = [];
  84. copyButton.disabled = false;
  85. copyButton.textContent = 'Copy all URLs';
  86. }, 3000);
  87. });
  88. })();

QingJ © 2025

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