-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
78 lines (73 loc) · 2.23 KB
/
Copy pathscript.js
File metadata and controls
78 lines (73 loc) · 2.23 KB
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
function dodajEl(alb, images)
{
let div = $("<div class='row mt-4 justify-content-center'>");
if(images)
{
let divS = $("<div class='col-sm-12 col-md-6 col-lg-4 col-xl-3 mb-1'>");
let loading = $('<div>').addClass('loader');
let image = $('<img/>', {src: images.images[0].thumbnails['small']});
image.on('load', () => {loading.remove();});
divS.append(image).append(loading);
div.append(divS);
}
else
{
div.append("<br>");
}
let divB = $("<div class='col-sm-12 col-md-2'>");
divB.append($('<input>').attr(
{ type: 'button',
class: 'btn btn-primary btn-sm',
value: alb.title + ", " + alb['artist-credit'][0].name + ", " + alb['track-count'] + " tracks"
}).click(function(){
window.location.href = "sorter.html?id=" + alb.id;
})
);
div.append(divB);
$("#slike").prepend(div);
$("#loadingTxt").remove();
}
$("#confirm").click(() => {
let q = "";
let stAlb = 8;
if($("#album").val()){
q = `release:${$("#album").val()}`;
}
if($("#artist").val())
{
if(q){
q += " AND ";
stAlb = 5;
}
q += `artist:${$("#artist").val()}`;
}
$("#slike").empty();
$("#slike").append("<div id='loadingTxt' class='row justify-content-center'><p>Loading...</p></div>");
let obj = {
query: q,
limit: stAlb,
fmt: "json"
}
let urlLink = "https://musicbrainz.org/ws/2/release/?" + $.param( obj );
$.get(urlLink, (data) => {
if(data.count == 0)
$("#loadingTxt").text("No results");
for(let alb of data.releases)
{
$.get("https://coverartarchive.org/release/" + alb.id, (images, err) => {
dodajEl(alb, images);
}).fail(function(){dodajEl(alb, false)});
}
})
})
function pressEnter(event) {
// Number 13 is the "Enter" key on the keyboard
if (event.keyCode === 13) {
// Cancel the default action, if needed
event.preventDefault();
// Trigger the button element with a click
document.getElementById("confirm").click();
}
}
$("#album").keyup(pressEnter);
$("#artist").keyup(pressEnter);