Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0
Ce dépôt a été archivé le 2022-05-07. Vous pouvez voir ses fichiers ou le cloner, mais pas ouvrir de ticket ou de demandes d'ajout, ni soumettre de changements.
nyaa-pantsu/public/js/query.js

46 lignes
1,6 Kio
JavaScript
Brut Vue normale Historique

2017-06-04 07:43:41 +02:00
// @source https://github.com/NyaaPantsu/nyaa/tree/dev/public/js
// @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt Expat
var Query = {
2017-07-23 04:50:36 +02:00
Failed: 0,
2017-07-16 06:43:09 +02:00
MaxFail: 10,
2017-07-23 04:50:36 +02:00
Get: function (url, renderer, callback) {
2017-07-16 06:43:09 +02:00
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'json';
2017-07-23 04:50:36 +02:00
xhr.onload = function (e) {
2017-07-16 06:43:09 +02:00
if (this.status == 200) {
Query.Failed = 0;
renderer(this.response);
if (callback != undefined) callback(this.response);
} else {
console.log("Error when refresh")
Query.Failed++;
2017-07-23 04:50:36 +02:00
console.log("Attempt to refresh " + Query.Failed + "...");
2017-07-16 06:43:09 +02:00
if ((Query.MaxFail == -1) || (Query.Failed < Query.MaxFail)) Query.Get(url, renderer, callback);
else console.error("Too many attempts, stopping...")
}
};
xhr.send();
},
2017-07-23 04:50:36 +02:00
Post: function (url, postArgs, callback) {
2017-07-16 06:43:09 +02:00
var xhr = new XMLHttpRequest();
xhr.open('POST', url, true);
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.responseType = 'json';
2017-07-23 04:50:36 +02:00
xhr.onload = function (e) {
2017-07-16 06:43:09 +02:00
if (this.status == 200) {
Query.Failed = 0;
if (callback != undefined) callback(this.response);
} else {
console.log("Error when refresh")
Query.Failed++;
2017-07-23 04:50:36 +02:00
console.log("Attempt to refresh " + Query.Failed + "...");
2017-07-16 06:43:09 +02:00
if ((Query.MaxFail == -1) || (Query.Failed < Query.MaxFail)) Query.Post(url, postArgs, callback);
else console.error("Too many attempts, stopping...")
}
};
xhr.send(postArgs);
}
2017-06-04 07:43:41 +02:00
};
// @license-end