-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
219 lines (183 loc) · 6.37 KB
/
index.html
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<!doctype html>
<html lang="en-US">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>Lost.fm</title>
</head>
<body>
<input type="text" id="search">
<button id="search-btn" onclick="searchResults()"> Search</button>
<hr/>
<button class="options" id="numbers" style="border: 2px solid; border-color: red;" onclick="redGreen(this)">Show numbering</button>
<button class="options" id="listeners" style="border: 2px solid; border-color: red;" onclick="redGreen(this)">Show listeners</button>
<input type="text" id="min-listeners" title="Min listeners" placeholder="Min listeners"> -
<input type="text" id="max-listeners" title="Max listeners" placeholder="Max listeners">
<hr/>
<input type="text" id="api" title="Paste your api key if there are problems with mine" placeholder="Paste your api key if there are problems with mine">
<a href="https://www.last.fm/api/account/create" style="color: #bbbbbb; text-decoration: underline; margin: -10px; font-size: 90%;">Get your api key</a>
<script>
function redGreen(btn) {
if (btn.style.borderColor == "red") {
btn.style.borderColor = "green"
}
else {
btn.style.borderColor = "red"
}
}
let SearchInProgress = false;
async function searchResults() {
if (SearchInProgress) {
return;
}
SearchInProgress = true;
const prevSearching = document.querySelectorAll('#searching');
prevSearching.forEach(elem => {
elem.remove();
});
const prevResults = document.querySelectorAll('.track');
prevResults.forEach(track => {
track.remove();
});
const prevFound = document.querySelectorAll('#found');
prevFound.forEach(elem => {
elem.remove();
});
const prevFileLink = document.querySelectorAll('#filelink');
prevFileLink.forEach(elem => {
elem.remove();
});
let str = "";
const searching = document.createElement('div');
searching.id = 'searching';
searching.textContent = "Searching...";
document.body.appendChild(searching);
let search = document.querySelector('#search').value;
if (search == "") {
search = " ";
}
let apiKey = 'b232418f74787beb124e0ddda1a80fcb';
const newApiKey = document.querySelector('#api').value;
if (newApiKey != "") {
apiKey = newApiKey
}
let apiUrl = `https://ws.audioscrobbler.com/2.0/?method=track.search&track=${search}&api_key=${apiKey}&limit=10000&format=json`;
let response = await fetch(apiUrl);
let data = await response.json();
if (data.message != null) {
searching.remove();
alert(data.message);
}
let array1 = data.results.trackmatches.track;
searching.remove();
const found = document.createElement('div');
found.id = 'found';
document.body.appendChild(found);
const a = document.querySelector('#numbers');
const b = document.querySelector('#listeners');
const maxListeners = document.querySelector('#max-listeners').value;
const minListeners = document.querySelector('#min-listeners').value;
let i = 0;
array1.forEach((track) => {
if ((maxListeners != "") && (parseInt(track.listeners, 10) > parseInt(maxListeners, 10))) {
return;
}
if ((minListeners != "") && (parseInt(track.listeners, 10) < parseInt(minListeners, 10))) {
return;
}
const div = document.createElement('div');
if (a.style.borderColor == "green") {
div.textContent = (i+1)+')'
}
const link = document.createElement('a');
link.href = track.url;
link.target="_blank";
link.rel="noopener noreferrer"
str += `${track.artist} - ${track.name}\n`;
link.textContent = track.artist + ' - ' + track.name;
div.appendChild(link);
if (b.style.borderColor == "green") {
div.innerHTML += `${track.listeners} listeners`
}
div.classList.add("track");
document.body.appendChild(div);
i++;
});
found.textContent = `Found ${data.results["opensearch:totalResults"]} results (${i} are shown). Note that it's impossible to get more than 10000`;
const file = new Blob([str], { type: 'text/plain' });
const fileLink = document.createElement("a");
const searchBtn = document.querySelector("#search-btn");
fileLink.textContent = "Download results as .txt";
fileLink.id = "filelink";
fileLink.style["font-size"] = "90%";
fileLink.href = URL.createObjectURL(file);
fileLink.download = "songs.txt";
searchBtn.after(fileLink);
SearchInProgress = false;
}
</script>
<style>
body {
background-color: #15202b;
color: white;
font-family: Arial, sans-serif;
text-wrap: wrap;
}
a {
color: white;
margin: 10px;
text-decoration: none;
}
#api {
width: 310px;
}
#max-listeners,
#min-listeners {
width: 80px;
}
hr {
width: 100%;
border: 1px solid #37474f;
}
.options {
margin-right: -5px;
}
#search-btn {
margin-left: -3px;
}
input[type="text"],
button {
margin-right: 12px;
margin-left: 12px;
margin-top: 7px;
margin-bottom: 5px;
padding: 6px;
border: none;
background-color: #37474f;
color: white;
border-radius: 3px;
}
button:hover {
background-color: #5588a3;
cursor: pointer;
}
button:active {
transform: translateY(1px);
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
background-color: #3d6074
}
div {
color: #bbbbbb;
margin: 12px;
font-size: 90%;
}
::placeholder {
color: #bbbbbb;
opacity: 1;
}
::-ms-input-placeholder {
color: #bbbbbb;
}
</style>
</body>
</html>