js: Automatically transform .time-until widgets into .time-ago ones

This commit is contained in:
Johannes Meyer 2023-06-21 14:21:51 +02:00
parent f74041e00a
commit 10d3fb64f9
1 changed files with 12 additions and 4 deletions

View File

@ -490,8 +490,8 @@
++minute; ++minute;
second = 0; second = 0;
} }
el.innerHTML = el.innerHTML.substr(0, partialTime.index) + minute.toString() + 'm ' el.innerHTML = el.innerHTML.substring(0, partialTime.index) + minute.toString() + 'm '
+ second.toString() + 's' + el.innerHTML.substr(partialTime.index + partialTime[0].length); + second.toString() + 's' + el.innerHTML.substring(partialTime.index + partialTime[0].length);
} }
}); });
@ -524,9 +524,17 @@
} else { } else {
--second; --second;
} }
if (minute === 0 && second === 0 && el.dataset.agoLabel) {
el.innerText = el.dataset.agoLabel;
el.classList.remove('time-until');
el.classList.add('time-ago');
return;
}
} }
el.innerHTML = el.innerHTML.substr(0, partialTime.index) + invert + minute.toString() + 'm ' el.innerHTML = el.innerHTML.substring(0, partialTime.index) + invert + minute.toString() + 'm '
+ second.toString() + 's' + el.innerHTML.substr(partialTime.index + partialTime[0].length); + second.toString() + 's' + el.innerHTML.substring(partialTime.index + partialTime[0].length);
} }
}); });
}, },