blob: a6a1d1df779704f6f4c272b63422f64582842143 (
plain)
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
|
pragma Singleton
import qs.config
import qs.utils
import Quickshell
Singleton {
id: root
function get(url: string, callback: var): void {
const xhr = new XMLHttpRequest();
const cleanup = () => {
xhr.abort();
xhr.onreadystatechange = null;
xhr.onerror = null;
};
xhr.open("GET", url, true);
xhr.onreadystatechange = () => {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200)
callback(xhr.responseText);
else
console.warn(`[REQUESTS] GET request to ${url} failed with status ${xhr.status}`);
cleanup();
}
};
xhr.onerror = () => {
console.warn(`[REQUESTS] GET request to ${url} failed`);
cleanup();
};
xhr.send();
}
}
|