Created
July 21, 2024 14:18
-
-
Save a1678991/040f684674c2ed2cad05b118fc1a7d19 to your computer and use it in GitHub Desktop.
This file contains 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 Booth.pm Download All | |
// @namespace http://tampermonkey.net/ | |
// @author a1678991 | |
// @version 1.0 | |
// @description Add a "Download All" button to purchased items on Booth.pm | |
// @match https://accounts.booth.pm/library* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
function addDownloadAllButton() { | |
const itemContainers = document.querySelectorAll('.mb-16.bg-white'); | |
itemContainers.forEach((container, index) => { | |
const downloadLinks = container.querySelectorAll('a[href^="https://booth.pm/downloadables/"]'); | |
if (downloadLinks.length >= 1) { | |
const downloadAllBtnDiv = document.createElement('div'); | |
downloadAllBtnDiv.style.flexGrow = '1'; | |
downloadAllBtnDiv.style.flexBasis = '0'; | |
downloadAllBtnDiv.style.minWidth = '100px'; | |
downloadAllBtnDiv.style.display = 'flex'; | |
downloadAllBtnDiv.style.justifyContent = 'flex-end'; | |
const downloadAllBtn = document.createElement('button'); | |
downloadAllBtn.textContent = 'Download ' + downloadLinks.length + (downloadLinks.length > 1 ? ' items' : ' item'); | |
downloadAllBtn.style.color = '#1b7f8c'; | |
downloadAllBtn.style.width = '100px'; | |
downloadAllBtn.addEventListener('click', () => downloadAll(downloadLinks)); | |
const appendTarget = container.querySelector('.gap-8.border-b.pb-16'); | |
appendTarget.appendChild(downloadAllBtnDiv); | |
downloadAllBtnDiv.appendChild(downloadAllBtn); | |
} | |
}); | |
} | |
function downloadAll(links) { | |
const waitMs = 5000; | |
const jitterMs = 300; | |
links.forEach((link, index) => { | |
setTimeout(() => { | |
link.dispatchEvent(new MouseEvent('click', { | |
view: window, | |
bubbles: true, | |
cancelable: false | |
})); | |
}, waitMs * index + Math.floor((Math.random() * jitterMs) - jitterMs/2)) | |
}); | |
} | |
addDownloadAllButton(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment