Reviews for YYYY-MM-DD Github
YYYY-MM-DD Github by Serdar Sanli
1 review
- Rated 4 out of 5by VoidsShadow, 6 months agoVersion 1.0.0 of this extension is a single script. It could very well be distributed as a cross-browser UserScript in addition to per-browser extensions.
I would like it if I could set a preference for a full date-time format such as ${YYYY}-${MM}-${DD}T${hh}:${mm}:${ss}(+/-)${TZ}.
https://ijmacd.github.io/rfc3339-iso8601/
For those with security concerns...
The script loops through the DOM "relative-time" elements. These elements have a "datetime" attribute with an RFC3339 and ISO-8601 compliant date-time string e.g. 2024-08-05T14:51:54-07:00. The script simply grabs the first ten characters from this string, prepends "at ", and *replaces* the relative-time element the `at ${date}`.
Because pages often load asynchronously, the above loop is executed again in a `for` loop with an incrementally increasing timeout.
I wonder why Serdar Sanli used a loop instead of Event hooks e.g.
```js
if (document.readyState === "loading") {
// Loading hasn't finished yet
document.addEventListener("DOMContentLoaded", doit);
} else {
// `DOMContentLoaded` has already fired
doit();
}
```
However, there's no event for when content is changed by scripts *after* DOMContentLoaded. From what I'm reading on StackOverflow, a [MutationObserver](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver) would handle this scenario.