sarthak bhardwaj.
0%
Skip to content
← work

epoch converter · side quest · 2023

A Chrome extension for the timestamps I kept pasting into a search bar

Debugging pipelines means reading Unix timestamps all day. I was converting them by hand several times a day, so I built a tiny browser extension: select a timestamp on any page while holding Ctrl, and a tooltip shows the date right where your cursor is.

The irritation

Small tools that remove a daily annoyance are worth more than their line count

Pipeline logs, API responses and database rows are full of epoch timestamps. Every time, the routine was the same: copy the number, open a tab, search “epoch converter”, paste, read, close. A few seconds each, many times a day — exactly the kind of friction that’s worth automating away.

How it evolved

From a web page, to an alert, to a tooltip at the cursor

  1. 1
    A page with an input box. The first draft was a plain HTML page: paste a value, see the date. It worked, but it was still a separate tab.
  2. 2
    Selection instead of typing. Next, it read whatever text was selected on the page — removing the copy-paste step entirely.
  3. 3
    A Chrome extension. Packaged as a content script, so it works on every site without opening anything.
  4. 4
    A tooltip instead of an alert. The first version popped a blocking alert; the current one draws a small tooltip next to the cursor and removes it after three seconds.

How it works

One content script, one event listener

How the epoch converter extension worksAny web pageCtrl + select textContent scriptruns on every URLValidate & convert≥10 digits → UTCTooltipat cursor · 3 s
Everything happens on the page you're reading — nothing is sent anywhere.

The manifest injects a content script into every URL with only the activeTab permission. The script listens for mouseup; if Ctrl is held and the selection is at least ten characters and parses as a number, it converts it and shows the result at the cursor.

content.js (trimmed)
document.addEventListener("mouseup", (event) => {
  if (!event.ctrlKey) return;
  const selection = window.getSelection().toString().trim();
  if (selection.length < 10) return;

  const epoch = parseInt(selection, 10);
  if (isNaN(epoch)) return;

  const utc = new Date(epoch * 1000).toISOString();
  showInfoTooltip(`UTC: ${utc}`, event.pageX, event.pageY);
});

The edge cases

Seconds, milliseconds and time zones — where timestamps actually bite

It also shows UTC only. I wrote a helper for my own time zone but never wired it into the tooltip, and reading logs from another region is exactly when you need both.

Where I'd take it

Small fixes that would make it genuinely shareable

  1. 1
    Detect milliseconds by length (13 digits) and say which unit it assumed.
  2. 2
    Show UTC and local time side by side, with the offset.
  3. 3
    Move to Manifest V3 and add a right-click menu entry, so it doesn’t depend on a key held during selection.

Built with

  • JavaScript
  • Chrome Extensions