Show absolute time next to relative time on Reddit posts and comments
// ==UserScript== // @name reddit tweaks // @namespace RedditTweaks // @version 1.0.0 // @description Show absolute time next to relative time on Reddit posts and comments // @author [email protected] // @match https://www.reddit.com/* // @grant none // @license MIT // ==/UserScript== (function () { 'use strict'; function updateTimestamps() { const times = document.querySelectorAll("time"); times.forEach((timeEl) => { // Avoid duplicating the absolute time if (timeEl.dataset.absoluteShown) return; const absoluteTime = timeEl.getAttribute("datetime"); if (absoluteTime) { // Format the absolute time const date = new Date(absoluteTime); //const formatted = date.toLocaleString(); // Local user format let formatted = new Date(date.getTime() - (new Date().getTimezoneOffset() * 60000)).toISOString().slice(0,16).replace('T', ' '); if(formatted.slice(0,4) === new Date().toLocaleDateString().slice(-4)){ formatted = formatted.slice(5); } // Append absolute time in parentheses timeEl.textContent += ` (${formatted})`; timeEl.dataset.absoluteShown = "true"; } }); } // Initial call updateTimestamps(); // Observe dynamically loaded content (React-based site) const observer = new MutationObserver(updateTimestamps); observer.observe(document.body, { childList: true, subtree: true }); })();