21 lines
886 B
JavaScript
21 lines
886 B
JavaScript
function load() {
|
|
let intervalID = window.setInterval(get_active_torrents, 20000);
|
|
}
|
|
|
|
function get_active_torrents() {
|
|
let httpRequest;
|
|
httpRequest = new XMLHttpRequest();
|
|
httpRequest.onreadystatechange = function() {
|
|
if (httpRequest.readyState !== XMLHttpRequest.DONE) { return; }
|
|
if (httpRequest.status !== 200) { return; }
|
|
torrents = JSON.parse(httpRequest.responseText);
|
|
let html_str = '';
|
|
for (let i = 0; i < torrents.length; i++) {
|
|
html_str += '<tr><td class="name">' + torrents[i].name + '</td><td class="state">' + torrents[i].state + '</td><td class="downrate">' + torrents[i].downrate_str + '</td><td class="uprate">' + torrents[i].uprate_str + '</td><td class="tracker">' + torrents[i].tracker + "</td>";
|
|
}
|
|
document.getElementById('torrents').children[1].innerHTML = html_str;
|
|
};
|
|
httpRequest.open('GET', get_torrents_uri, true);
|
|
httpRequest.send();
|
|
}
|