formatted timestamps

This commit is contained in:
Evert Prants 2021-10-11 22:13:11 +03:00
parent 72502368b2
commit 0f6a5c3a9e
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
2 changed files with 24 additions and 1 deletions

View File

@ -129,6 +129,9 @@ button .tooltip {
.movie-buttons a {
margin-right: 0.5rem;
}
.timestamp .original {
color: gray;
}
@media screen and (max-width: 1200px) {
.inner {
width: 100%;

View File

@ -50,6 +50,14 @@ function findByInfoFile(infoFile) {
return found;
}
const pZ = (n) => n.toString().padStart(2, '0');
function restampDateTime(datetime, includeTime = true) {
const date = new Date(datetime);
const [month, day, year] = [date.getMonth() + 1, date.getDate(), date.getFullYear()];
const [hour, minutes, seconds] = [date.getHours(), date.getMinutes(), date.getSeconds()];
return `${pZ(day)}/${pZ(month)}/${year}${includeTime ? ` ${pZ(hour)}:${pZ(minutes)}:${pZ(seconds)}` : ''}`;
}
function deduplicateJointEpisode(textContent) {
return new Promise((resolve, reject) => {
const lns = textContent.split('\n');
@ -99,7 +107,11 @@ function fillMeta(
if (airedEl || premieredEl) {
const timestamp = original.parentElement.parentElement.querySelector('.timestamp');
if (timestamp) {
timestamp.innerText = (airedEl || premieredEl).textContent;
const original = timestamp.innerText;
const airdate = restampDateTime((airedEl || premieredEl).textContent, false);
const wrapper = `<span class="airdate">${airdate}</span>`;
const originalWrapper = ` <span class="original">(${original})</span>`;
timestamp.innerHTML = wrapper + originalWrapper;
}
}
@ -196,6 +208,12 @@ function createOrImproveMovieMeta(original, thumbnail, nfo) {
}
}
function timestampify() {
Array.from(document.body.querySelectorAll('.timestamp')).forEach((stamp) => {
stamp.innerText = restampDateTime(stamp.innerText);
});
}
// Promise that resolves when all info files that were found have been parsed
function waitUntilInfoComplete() {
return new Promise((resolve, reject) => {
@ -331,10 +349,12 @@ function createToggleCheckbox(field, value, description) {
if ('localStorage' in window) {
const plainMode = window.localStorage.getItem('plainMode');
if (plainMode !== 'true') {
timestampify();
accountForMetadata();
}
createToggleCheckbox('plainMode', plainMode, 'Disable metadata / display plain index listing (less bandwidth required)');
} else {
timestampify();
accountForMetadata();
}