-
Notifications
You must be signed in to change notification settings - Fork 1
/
Musescore to jDownloader.user.js
95 lines (85 loc) · 2.38 KB
/
Musescore to jDownloader.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// ==UserScript==
// @name Musescore to jDownloader
// @version 1
// @grant GM.xmlHttpRequest
// @include https://musescore.com/user/*/scores/*
// ==/UserScript==
// URL of local jDownloader process
var JDOWNLOADER="http://127.0.0.1:9666/flashgot";
var SOURCE="MuseScore 2 jDownloader";
window.setTimeout(initialize, 10);
var imgs= [];
var imgdivs;
var imgcount;
function initialize() {
console.log("Initializing");
var oneimg=document.querySelector('img[src*="/score_"][src*="?no-cache"]');
if (oneimg===null) {
window.setTimeout(initialize, 1000);
return;
}
console.log("First image found");
imgdivs= []
.slice
.call(oneimg.parentNode.parentNode.children);
imgcount= imgdivs.length;
imgs[imgcount-1]= undefined;
console.log("Images required: ", imgcount);
get_img_urls();
}
function get_img_urls() {
console.log(imgcount, imgs);
imgdivs.forEach(
function(elt, i) {
if ( imgs[i] !== undefined ) return;
var img= elt.querySelector('img');
if (img === null ) return;
imgs[i]= img.src;
--imgcount;
}
);
if (imgcount > 0) {
window.setTimeout(get_img_urls, 1000);
return;
}
imgurls= imgs.join("\n");
var title=document.querySelector('meta[property="og:title"]').getAttribute('content');
var composer=document.querySelector('meta[property="musescore:composer"]').getAttribute('content');
var author=document.querySelector('meta[property="musescore:author"]').getAttribute('content');
toJDownloader({
"urls" : imgurls,
"package": title + " - " + composer + " - " + author,
});
}
function toJDownloader (info) {
// Prepare the data to be send to jDownloader
var data= {
"source" : SOURCE,
"passwords" : "",
"package" : info.package,
"urls" : info.urls,
"submit" : "submit"
};
console.debug(JDOWNLOADER, objEncodeURIComponent(data));
GM.xmlHttpRequest({
method: "POST",
url: JDOWNLOADER,
data: objEncodeURIComponent(data),
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
onload: function(response) {
if ( response.status === 200 ) {
//document.querySelector('body').textContent="DONE!";
}
},
});
}
function objEncodeURIComponent(obj) {
var str = [];
for (var p in obj)
if (obj.hasOwnProperty(p)) {
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
}
return str.join("&");
}