refactor(extension): consolidate 5 relativeTime copies into shared util

This commit is contained in:
adlee-was-taken
2026-05-24 18:28:21 -04:00
parent 9da45dd478
commit a587965528
5 changed files with 5 additions and 55 deletions

View File

@@ -2,6 +2,7 @@
import { setState, sendMessage, navigate, escapeHtml } from '../../shared/state';
import type { Device } from '../../shared/types';
import { relativeTime } from '../../shared/relative-time';
interface RevokedEntry {
name: string;
@@ -10,16 +11,6 @@ interface RevokedEntry {
revoked_by: string;
}
function relativeTime(unixSec: number): string {
const now = Math.floor(Date.now() / 1000);
const diff = now - unixSec;
if (diff < 60) return 'just now';
if (diff < 3600) return `${Math.floor(diff / 60)}m ago`;
if (diff < 86400) return `${Math.floor(diff / 3600)}h ago`;
if (diff < 2592000) return `${Math.floor(diff / 86400)}d ago`;
return `${Math.floor(diff / 2592000)}mo ago`;
}
function detectDefaultDeviceName(): string {
const ua = navigator.userAgent ?? '';
const platform = (navigator.platform ?? '').toLowerCase();