Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

Improve date formatting (#1693)

* Update main.js

* Update base.jet.html

* Update CHANGELOG.md

* Update en-us.all.json

* Update ja-jp.all.json

* Update main.js
Cette révision appartient à :
MMP0 2017-10-29 00:01:56 +09:00 révisé par kilo
Parent 1f5d07a85c
révision 901c933632
5 fichiers modifiés avec 34 ajouts et 4 suppressions

Voir le fichier

@ -40,6 +40,13 @@ function toggleLayer(elem) {
} }
} }
// String formatter
// "{0}{2}, {1}".format("foo", 123, "bar") == "foobar, 123"
String.prototype.format = function() {
var args = arguments
return this.replace(/\{(\w+)\}/g, function(m, k) { return args[k] })
}
function parseAllDates() { function parseAllDates() {
// Date formatting // Date formatting
var lang = document.getElementsByTagName("html")[0].getAttribute("lang") var lang = document.getElementsByTagName("html")[0].getAttribute("lang")
@ -58,6 +65,7 @@ function parseAllDates() {
var e = list[i] var e = list[i]
e.innerText = new Date(e.title).toLocaleString(lang, ymdOpt) e.innerText = new Date(e.title).toLocaleString(lang, ymdOpt)
e.title = new Date(e.title).toLocaleString(lang) e.title = new Date(e.title).toLocaleString(lang)
e.classList.remove("date-short")
} }
var list = document.getElementsByClassName("date-full") var list = document.getElementsByClassName("date-full")
@ -65,12 +73,13 @@ function parseAllDates() {
var e = list[i] var e = list[i]
var dateDifference = dateDiff(new Date(e.innerText), new Date()) var dateDifference = dateDiff(new Date(e.innerText), new Date())
if(e.className != undefined && e.className.includes("scrape-date")) if(e.classList.contains("scrape-date"))
e.title = ((dateDifference.d * 24) + dateDifference.h) + " hours " + dateDifference.m + " minutes ago" e.title = hmFmt.format((dateDifference.d * 24) + dateDifference.h, dateDifference.m)
else else
e.title = dateDifference.d + " days " + dateDifference.h + " hours ago" e.title = dhFmt.format(dateDifference.d, dateDifference.h)
e.innerText = new Date(e.innerText).toLocaleString(lang) e.innerText = new Date(e.innerText).toLocaleString(lang)
e.classList.remove("date-full")
} }
} }
function dateDiff( str1, str2 ) { function dateDiff( str1, str2 ) {

Voir le fichier

@ -100,7 +100,9 @@
websiteVersion = "{{ Config.Version }}", websiteVersion = "{{ Config.Version }}",
UserID = {{User.ID}}, UserID = {{User.ID}},
domain = "{{getDomainName()}}", domain = "{{getDomainName()}}",
darkTheme = "{{DarkTheme}}"; darkTheme = "{{DarkTheme}}",
hmFmt = "{{ T("hours_minutes_ago") }}",
dhFmt = "{{ T("days_hours_ago") }}";
</script> </script>
<script type="text/javascript" src="/js/query.js?v={{ Config.Version}}{{ Config.Build }}"></script> <script type="text/javascript" src="/js/query.js?v={{ Config.Version}}{{ Config.Build }}"></script>
<script type="text/javascript" charset="utf-8" src="/js/main.js?v={{ Config.Version }}{{ Config.Build }}" async></script> <script type="text/javascript" charset="utf-8" src="/js/main.js?v={{ Config.Version }}{{ Config.Build }}" async></script>

Voir le fichier

@ -60,3 +60,6 @@
* + generating_torrent * + generating_torrent
## 2017/10/09 ## 2017/10/09
* + no_api_token * + no_api_token
## 2017/10/28
* + hours_minutes_ago
* + days_hours_ago

Voir le fichier

@ -2174,5 +2174,13 @@
{ {
"id": "search_from_specific_user", "id": "search_from_specific_user",
"translation": "Search from %s" "translation": "Search from %s"
},
{
"id": "hours_minutes_ago",
"translation": "{0} hours {1} minutes ago"
},
{
"id": "days_hours_ago",
"translation": "{0} days {1} hours ago"
} }
] ]

Voir le fichier

@ -2174,5 +2174,13 @@
{ {
"id": "search_from_specific_user", "id": "search_from_specific_user",
"translation": "%s のアップロードを検索" "translation": "%s のアップロードを検索"
},
{
"id": "hours_minutes_ago",
"translation": "{0} 時間 {1} 分前"
},
{
"id": "days_hours_ago",
"translation": "{0} 日 {1} 時間前"
} }
] ]