Skip to main content

max / makenotwork

887 B · 26 lines History Blame Raw
1 function exportAll() {
2 var btn = document.getElementById('export-all-btn');
3 var buttons = document.querySelectorAll('.export-card button.secondary');
4 if (buttons.length === 0) return;
5
6 btn.disabled = true;
7 btn.textContent = 'Exporting...';
8 var i = 0;
9
10 function next() {
11 if (i >= buttons.length) {
12 btn.textContent = 'Done';
13 // A temporary label going back to the real one: `Intent::Revert`,
14 // the same duration a copy button flashes for.
15 setTimeout(function() { btn.textContent = 'Export All'; btn.disabled = false; }, window.timing.revertMs());
16 return;
17 }
18 buttons[i].click();
19 i++;
20 // Not a timing intent: this paces one click after another so the
21 // browser is not handed a dozen downloads at once.
22 setTimeout(next, 1500);
23 }
24 next();
25 }
26