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/torrents.js

49 lignes
1,7 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 Torrents = {
2017-07-16 06:43:09 +02:00
CanRefresh: false,
timeout: undefined,
Seconds: 300, // Every five minutes, can be overridden directly in home.html (not here is better)
SearchURL: "/api/search",
Method: "prepend",
LastID: 0,
2017-07-23 04:50:36 +02:00
StopRefresh: function () {
2017-07-16 06:43:09 +02:00
clearTimeout(this.timeout)
this.timeout = undefined
this.CanRefresh = false
},
2017-07-23 04:50:36 +02:00
Refresh: function () {
2017-07-16 06:43:09 +02:00
if (this.CanRefresh) {
2017-07-23 04:50:36 +02:00
this.timeout = setTimeout(function () {
2017-07-16 06:43:09 +02:00
var searchArgs = (window.location.search != "") ? window.location.search.substr(1) : ""
2017-07-23 04:50:36 +02:00
searchArgs = (Torrents.LastID > 0) ? "?fromID=" + Torrents.LastID + "&" + searchArgs : "?" + searchArgs
Query.Get(Torrents.SearchURL + searchArgs,
function (data) {
2017-07-20 22:00:42 +02:00
var torrents = data.torrents
Templates.ApplyItemListRenderer({
2017-07-23 04:50:36 +02:00
templateName: "torrents.item",
method: "prepend",
element: document.getElementById("torrentListResults")
2017-07-20 22:00:42 +02:00
})(torrents)
2017-07-23 04:50:36 +02:00
for (var i = 0; i < torrents.length; i++) {
if (Torrents.LastID < torrents[i].id) Torrents.LastID = torrents[i].id;
}
2017-07-20 22:00:42 +02:00
parseAllDates()
2017-07-16 06:43:09 +02:00
Torrents.Refresh()
});
2017-07-23 04:50:36 +02:00
}, this.Seconds * 1000);
}
},
2017-07-23 04:50:36 +02:00
StartRefresh: function () {
2017-07-20 22:00:42 +02:00
this.CanRefresh = true
this.Refresh()
2017-07-16 06:43:09 +02:00
}
}
2017-07-23 04:50:36 +02:00
document.addEventListener("DOMContentLoaded", function () { // if Torrents.CanRefresh is enabled, refresh is automatically done (no need to start it anually)
if (Torrents.CanRefresh) {
Torrents.StartRefresh()
2017-07-16 06:43:09 +02:00
}
})
2017-07-23 04:50:36 +02:00
// @license-end