forked from joostflick/cga-groovecollector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DownloadAlbum.user.js
59 lines (53 loc) · 2.13 KB
/
DownloadAlbum.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
// ==UserScript==
// @name Bandcamp Download Album
// @namespace https://bandcamp.com
// @match https://bandcamp.com/download*
// @description Downloads the item from the download page. Refreshes if there is an error.
// @author Ryan Bluth, Xerus2000, Joost Flick
// @version 1.1.1
// @grant none
// ==/UserScript==
(function () {
'use strict';
// Set preferred download format here
var format = "MP3 320";
// Whether the download tab should automatically be closed after the download has been started
var closeAfterDownload = true;
var selectedFormat = false;
setTimeout(function () {
var interval = setInterval(function () {
if (!selectedFormat) {
document.getElementsByClassName('item-format button')[0].click();
var spans = document.getElementsByTagName('span');
for (var i = 0; i < spans.length; i++) {
if (spans[i].textContent == format) {
spans[i].parentElement.click();
selectedFormat = true;
break;
}
}
} else {
var errorText = document.getElementsByClassName('error-text')[0];
if (errorText.offsetParent !== null) {
location.reload();
}
try {
var maintenanceLink = document.getElementsByTagName('a')[0];
if (maintenanceLink.href.indexOf("bandcampstatus") > 0) {
location.reload();
}
} catch (e) {
console.log(e);
}
var titleLabel = document.getElementsByClassName('download-title')[0];
if (titleLabel.children[0].href !== undefined && titleLabel.children[0].href.length > 0) {
window.open(titleLabel.children[0].href);
clearTimeout(interval);
if (closeAfterDownload) {
close();
}
}
}
}, 2000);
}, 2000);
})();