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
Ramon Dantas d8e17478f8 Country flags (language) for torrents. (#970)
* Add flags for torrents

Add a new field, .Language, to the Torrent model, and a new package,
torrentLanguages, which maps languages to flags. Added also a flag icon pack
from googlei18n/region-flags, with (mostly) public domain flags from Wikipedia.

* Optimize flags

* Use FlagSprites CSS instead of .png files

* Only use flags for languages we support

* Add test for CSS flags

Ensure that we have all the flags for the languages we support.

* Add AdditionalLanguages field to config

This allows us to support additional languages for new uploaded torrents,
even if we have no translation for it.

* Minor CSS fix

* Add "other" and "multiple" torrent languages

Also removed the TorrentLanguage struct, as it wasn't much useful.

* Fix test

* Add colspan=2 to category when language is empty

Also hide the language column if empty.

* Add lang field to search.

Hopefully it works with Elasticsearch as well, but I haven't tested
(lol Java)

* Add language field to ES index and settings

* Add language column to JS template

* Add keyword type to language ES field

* Remove 'raw' from keyword

* Set "simple" analyzer on language

* Document .Language field on Torrent model
2017-06-12 09:14:26 +10:00

56 lignes
2,1 Kio
JavaScript

// @source https://github.com/NyaaPantsu/nyaa/tree/dev/public/js
// @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt Expat
var Torrents = {
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,
StopRefresh: function() {
clearTimeout(this.timeout)
this.timeout = undefined
this.CanRefresh = false
},
Refresh: function() {
if (this.CanRefresh) {
this.timeout = setTimeout(function() {
var searchArgs = (window.location.search != "") ? window.location.search.substr(1) : ""
searchArgs = (Torrents.LastID > 0) ? "?fromID="+Torrents.LastID+"&"+searchArgs : "?"+searchArgs
Query.Get(Torrents.SearchURL+searchArgs,
Templates.ApplyItemListRenderer({
templateName: "torrents.item", method: "prepend", element: document.getElementById("torrentListResults")
}), function(torrents) {
for (var i =0; i < torrents.length; i++) { if (Torrents.LastID < torrents[i].id) Torrents.LastID = torrents[i].id; }
parseAllDates();
Torrents.Refresh()
});
}, this.Seconds*1000);
}
},
StartRefresh: function() {
this.CanRefresh = true;
this.Refresh()
}
}
document.addEventListener("DOMContentLoaded", function() { // if Torrents.CanRefresh is enabled, refresh is automatically done (no need to start it anually)
if (Torrents.CanRefresh) {
Torrents.StartRefresh()
}
})
function humanFileSize(bytes, si) {
var k = si ? 1000 : 1024;
var i = ~~(Math.log(bytes) / Math.log(k));
return i == 0 ? bytes + " B" : (bytes / Math.pow(k, i)).toFixed(1) + " " + "KMGTPEZY"[i - 1] + (si ? "" : "i") + "B";
}
function flagCode(language) {
split = language.split("-");
if (split.length > 1) {
return split[1];
}
return language;
}
// @license-end