dm

dm / Pexels Downloader

Last active 2 months ago

Like 0

dm revised this gist 2 months ago · 96f906d

2 files changed, 40 insertions

Explanation.md (file created)
@@ -0,0 +1,7 @@
1 + # Pexels Downloader
2 +
3 + 1. Visit any query/page/collection you want downloaded.
4 + 2. Scroll down untill everything is loaded.
5 + 3. Paste the snippet into the developer tools and press return.
6 +
7 + Profit.
snippet.js (file created)
@@ -0,0 +1,33 @@
1 + (async function() {
2 + // Helper function to wait for a given number of milliseconds
3 + function wait(ms) {
4 + return new Promise(resolve => setTimeout(resolve, ms));
5 + }
6 +
7 + // Function to process each article
8 + async function processArticles() {
9 + const articles = document.querySelectorAll('article');
10 +
11 + for (let i = 0; i < articles.length; i++) { // change 0 in case you need to restart the script and need to define a new index. See index in console log
12 + const article = articles[i];
13 + const downloadButton = article.querySelector('a[download][title="Download"]');
14 +
15 + if (downloadButton && !downloadButton.href.includes('/video/')) {
16 + try {
17 + // Emulate button click
18 + downloadButton.click();
19 + console.log(`Clicked download button for video ID: ${downloadButton.href.split('/').pop()} at article index: ${i}`);
20 +
21 + // Wait for
22 + await wait(200);
23 + } catch (error) {
24 + console.error('An error occurred:', error);
25 + break;
26 + }
27 + }
28 + }
29 + }
30 +
31 + // Start processing the articles
32 + processArticles();
33 + })();