Last active
January 17, 2024 22:36
-
-
Save tyhallcsu/89d6c672f93e94cbd651354b587306b4 to your computer and use it in GitHub Desktop.
This is a userscript that extracts image URLs from a Dropbox page and copies them to the clipboard when a button is clicked. The script creates a button on the page that, when clicked, scrolls to the bottom of the page, waits for new images to load, and extracts the image URLs. The script then joins the URLs into a string separated by newlines a…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Bulk Export Dropbox Image URLs (2024) | |
// @version 3.1.1 | |
// @description Extracts image URLs from a Dropbox page and copies them to the clipboard when a button is clicked. | |
// @author sharmanhall | |
// @supportURL https://github.com/tyhallcsu/dropbox-image-url-extractor/issues/new | |
// @namespace https://github.com/tyhallcsu/dropbox-image-url-extractor | |
// @homepageURL https://github.com/tyhallcsu/dropbox-image-url-extractor | |
// @license MIT | |
// @connect greasyfork.org | |
// @connect sleazyfork.org | |
// @connect github.com | |
// @connect openuserjs.org | |
// @match https://www.dropbox.com/* | |
// @grant GM_setClipboard | |
// @grant GM_log | |
// @compatible chrome | |
// @compatible firefox | |
// @compatible edge | |
// @compatible opera | |
// @compatible safari | |
// @run-at document-idle | |
// @icon https://cfl.dropboxstatic.com/static/metaserver/static/images/favicon-vfl8lUR9B.ico | |
// ==/UserScript== | |
// NEW CONTRIBUTOR: [pixelsilo](https://www.dropboxforum.com/t5/user/viewprofilepage/user-id/1795103) | |
// SOURCE: https://www.dropboxforum.com/t5/View-download-and-export/Export-Bulk-Dropbox-Image-Folder-URLs/m-p/744340/highlight/true# | |
(function() { | |
'use strict'; | |
const SECONDS_TO_WAIT_FOR_SCROLL = 1; // adjust as needed | |
const DOWNLOAD_URL_REPLACEMENT = '?raw=1'; | |
// DELETED: MODIFIED BELOW || function to get all image link elements | |
//function getImageLinks() { | |
// const imageLinks = document.querySelectorAll('a.dig-Link.sl-link--file[href*="dl=0"]'); | |
// return Array.from(imageLinks).map(link => link.getAttribute('href').replace(/\?dl=0$/, DOWNLOAD_URL_REPLACEMENT)); | |
//} | |
function getImageLinks() { | |
// Update the selector to match the Dropbox page structure | |
const imageLinks = document.querySelectorAll('a.dig-Link._sl-file-name_1iaob_86.dig-Link--primary[href*="dl=0"]'); | |
return Array.from(imageLinks).map(link => link.getAttribute('href').replace(/\?dl=0$/, DOWNLOAD_URL_REPLACEMENT)); | |
} | |
// function to scroll to the bottom of the page and wait for new images to load | |
async function waitForImagesToLoad() { | |
window.scrollTo(0, document.body.scrollHeight); | |
await new Promise(resolve => setTimeout(resolve, SECONDS_TO_WAIT_FOR_SCROLL * 1000)); | |
} | |
// create an array to hold the image URLs | |
let imageUrls = []; | |
// add a button to the page that will copy the image URLs to the clipboard when clicked | |
const copyButton = document.createElement('button'); | |
copyButton.classList.add('dig-Button', 'dig-Button--primary', 'dig-Button--standard', 'copy-urls-button'); | |
copyButton.textContent = 'Copy all URLs'; | |
copyButton.style.position = 'fixed'; | |
copyButton.style.bottom = '20px'; | |
copyButton.style.right = '20px'; | |
copyButton.style.zIndex = '9999'; | |
document.body.appendChild(copyButton); | |
// add a click event listener to the button | |
copyButton.addEventListener('click', async function() { | |
let finished = false; | |
let numUrls = 0; | |
while (!finished) { | |
// scroll to the bottom of the page and wait for new images to load | |
await waitForImagesToLoad(); | |
// get the newly loaded image URLs | |
const newImageUrls = getImageLinks().filter(url => !imageUrls.includes(url)); | |
imageUrls.push(...newImageUrls); | |
// check if all images have been loaded | |
finished = newImageUrls.length === 0; | |
numUrls += newImageUrls.length; | |
} | |
// join the image URLs into a string separated by newlines | |
const imageUrlString = imageUrls.join('\n'); | |
// copy the image URL string to the clipboard | |
GM_setClipboard(imageUrlString, 'text'); | |
// disable the button and change the text to indicate that the URLs have been copied | |
copyButton.disabled = true; | |
copyButton.textContent = `${numUrls} URL(s) copied to clipboard`; | |
// enable the button again after 3 seconds | |
setTimeout(function() { | |
imageUrls = []; | |
copyButton.disabled = false; | |
copyButton.textContent = 'Copy all URLs'; | |
}, 3000); | |
}); | |
})(); |
Author
tyhallcsu
commented
Apr 29, 2023
HI, i used the script but it says 0 URLs copied. Can you pls check? Thanks!
HI, i used the script but it says 0 URLs copied. Can you pls check? Thanks!
show me the URL you are trying?
Also I must note you must be SIGNED OUT and it must be a PUBLIC folder.
Someone modified my script, so here it is:
https://www.dropboxforum.com/t5/View-download-and-export/Export-Bulk-Dropbox-Image-Folder-URLs/m-p/744340/highlight/true#M52605
Update in Jan 2024. Couldn't get this to work. Chat GPT fixed it for me. The function needs updating. Change it to the below.
function getImageLinks() { // Update the selector to match the Dropbox page structure const imageLinks = document.querySelectorAll('a.dig-Link._sl-file-name_1iaob_86.dig-Link--primary[href*="dl=0"]'); return Array.from(imageLinks).map(link => link.getAttribute('href').replace(/\?dl=0$/, DOWNLOAD_URL_REPLACEMENT)); }
Make sure the folder is publically shared and you're logged out (incognito mode didn't work for me)
So here is their fixes implemented:
// ==UserScript==
// @name Bulk Export Dropbox Image URLs (2024)
// @version 3.1.1
// @description Extracts image URLs from a Dropbox page and copies them to the clipboard when a button is clicked.
// @author sharmanhall
// @supportURL https://github.com/tyhallcsu/dropbox-image-url-extractor/issues/new
// @namespace https://github.com/tyhallcsu/dropbox-image-url-extractor
// @homepageURL https://github.com/tyhallcsu/dropbox-image-url-extractor
// @license MIT
// @connect greasyfork.org
// @connect sleazyfork.org
// @connect github.com
// @connect openuserjs.org
// @match https://www.dropbox.com/*
// @grant GM_setClipboard
// @grant GM_log
// @compatible chrome
// @compatible firefox
// @compatible edge
// @compatible opera
// @compatible safari
// @run-at document-idle
// @icon https://cfl.dropboxstatic.com/static/metaserver/static/images/favicon-vfl8lUR9B.ico
// @downloadURL https://update.greasyfork.org/scripts/465164/Bulk%20Export%20Dropbox%20Image%20URLs%20%282024%29.user.js
// @updateURL https://update.greasyfork.org/scripts/465164/Bulk%20Export%20Dropbox%20Image%20URLs%20%282024%29.meta.js
// ==/UserScript==
// NEW CONTRIBUTOR: [pixelsilo](https://www.dropboxforum.com/t5/user/viewprofilepage/user-id/1795103)
// SOURCE: https://www.dropboxforum.com/t5/View-download-and-export/Export-Bulk-Dropbox-Image-Folder-URLs/m-p/744340/highlight/true#
(function() {
'use strict';
const SECONDS_TO_WAIT_FOR_SCROLL = 1; // adjust as needed
const DOWNLOAD_URL_REPLACEMENT = '?raw=1';
// DELETED: MODIFIED BELOW || function to get all image link elements
//function getImageLinks() {
// const imageLinks = document.querySelectorAll('a.dig-Link.sl-link--file[href*="dl=0"]');
// return Array.from(imageLinks).map(link => link.getAttribute('href').replace(/\?dl=0$/, DOWNLOAD_URL_REPLACEMENT));
//}
function getImageLinks() {
// Update the selector to match the Dropbox page structure
const imageLinks = document.querySelectorAll('a.dig-Link._sl-file-name_1iaob_86.dig-Link--primary[href*="dl=0"]');
return Array.from(imageLinks).map(link => link.getAttribute('href').replace(/\?dl=0$/, DOWNLOAD_URL_REPLACEMENT));
}
// function to scroll to the bottom of the page and wait for new images to load
async function waitForImagesToLoad() {
window.scrollTo(0, document.body.scrollHeight);
await new Promise(resolve => setTimeout(resolve, SECONDS_TO_WAIT_FOR_SCROLL * 1000));
}
// create an array to hold the image URLs
let imageUrls = [];
// add a button to the page that will copy the image URLs to the clipboard when clicked
const copyButton = document.createElement('button');
copyButton.classList.add('dig-Button', 'dig-Button--primary', 'dig-Button--standard', 'copy-urls-button');
copyButton.textContent = 'Copy all URLs';
copyButton.style.position = 'fixed';
copyButton.style.bottom = '20px';
copyButton.style.right = '20px';
copyButton.style.zIndex = '9999';
document.body.appendChild(copyButton);
// add a click event listener to the button
copyButton.addEventListener('click', async function() {
let finished = false;
let numUrls = 0;
while (!finished) {
// scroll to the bottom of the page and wait for new images to load
await waitForImagesToLoad();
// get the newly loaded image URLs
const newImageUrls = getImageLinks().filter(url => !imageUrls.includes(url));
imageUrls.push(...newImageUrls);
// check if all images have been loaded
finished = newImageUrls.length === 0;
numUrls += newImageUrls.length;
}
// join the image URLs into a string separated by newlines
const imageUrlString = imageUrls.join('\n');
// copy the image URL string to the clipboard
GM_setClipboard(imageUrlString, 'text');
// disable the button and change the text to indicate that the URLs have been copied
copyButton.disabled = true;
copyButton.textContent = `${numUrls} URL(s) copied to clipboard`;
// enable the button again after 3 seconds
setTimeout(function() {
imageUrls = [];
copyButton.disabled = false;
copyButton.textContent = 'Copy all URLs';
}, 3000);
});
})();
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment