-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhumblebundle-download.user.js
61 lines (48 loc) · 1.27 KB
/
humblebundle-download.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// ==UserScript==
// @name Humblebundle Downloader
// @namespace https://github.com/denniskupec
// @version 1
// @author Dennis Kupec <[email protected]>
// @match https://www.humblebundle.com/downloads*
// @grant GM_download
// @connect *.humble.com
// @nocompat Chrome
// @noframes
// ==/UserScript==
var elements;
/* page loads everything async */
var int = setInterval(()=>{
elements = document.querySelectorAll('.js-all-downloads-holder a.a');
if (elements.length > 0) {
clearInterval(int);
elements = Array.from(elements);
console.log(`Downloading ${elements.length} items`);
download(elements.pop());
}
}, 250);
function download(url) {
if (!elements.length) {
return;
}
console.info(`Downloading: ${url}`);
GM_download({
url: url.getAttribute('data-web'),
name: getFilename(url),
onload: () => {
console.info(`Completed: ${getFilename(url)}`);
setTimeout(download, 1000, elements.pop());
},
onerror: (err) => {
console.error(`Download error: ${err.details}`);
if (err.error == 'not_succeeded') {
elements.push(url);
setTimeout(download, 1000, elements.pop());
}
}
});
}
function getFilename(url) {
let a = document.createElement('a');
a.href = url.getAttribute('data-web');
return a.pathname.replace('/', '');
}