A Chrome extension for converting between epoch timestamps and human-readable dates. Built with TypeScript for type safety and maintainability.
- Convert Epoch to Date: Select any epoch timestamp on a webpage and convert it to a human-readable date format
- Copy Current Epoch Time: Instantly copy the current epoch time (
Date.now()) to your clipboard - Custom Date to Epoch: Input a custom date and time with GMT offset to get the corresponding epoch timestamp
- Configurable Shortcuts: Customize keyboard shortcuts for all actions via the options page
- Context Menu Integration: Right-click context menu for quick access to all features
epoch_converter.chrome/
├── src/
│ ├── content/ # Content script modules
│ │ ├── content.ts # Main content script orchestrator
│ │ ├── keyboard.ts # Keyboard shortcut handling
│ │ ├── modal.ts # Modal creation and management
│ │ ├── notifications.ts # Notification system
│ │ ├── utils.ts # Utility functions
│ │ └── injectStyles.ts # CSS injection
│ ├── background/ # Background service worker
│ │ └── background.ts
│ ├── options/ # Options page
│ │ ├── options.ts
│ │ └── options.html
│ ├── shared/ # Shared code
│ │ ├── types.ts # TypeScript type definitions
│ │ ├── constants.ts # Constants and configuration
│ │ └── config.ts # Config management
│ └── styles/ # CSS files
│ ├── modal.css
│ ├── notifications.css
│ └── options.css
├── dist/ # Compiled output (generated)
├── types/ # TypeScript type definitions
│ └── chrome.d.ts
├── images/ # Extension icons
├── manifest.json # Chrome extension manifest
├── tsconfig.json # TypeScript configuration
└── package.json # Dependencies and scripts
- Node.js (v14 or higher)
- npm or yarn
- Google Chrome browser
git clone https://github.com/yarin-mag/epoch-time-converter.git
cd epoch-time-converternpm installnpm run buildThis will:
- Compile TypeScript files from
src/todist/ - Bundle all modules into single files (required for Chrome extensions)
- Copy HTML and CSS assets to
dist/
- Open Chrome and navigate to
chrome://extensions/ - Enable "Developer mode" in the top right corner
- Click "Load unpacked"
- Select the
epoch_converter.chromedirectory (the root directory containingmanifest.json)
For development with automatic recompilation:
npm run watchThis will watch for file changes and automatically recompile TypeScript files.
npm run build- Compile TypeScript and copy assetsnpm run watch- Watch mode for developmentnpm run clean- Remove thedist/directorynpm run copy-assets- Copy HTML and CSS files to dist
The codebase follows these principles:
- Function length limit: All functions are kept under 50 lines (except edge cases)
- Modular design: Code is organized into logical modules
- Type safety: Full TypeScript coverage with strict mode
- No inline styles: All styles are in separate CSS files
- Clean code: Minimal comments, self-documenting code
- Select an epoch timestamp on any webpage
- Press
Ctrl + Shift + S(orCmd + Shift + Son Mac) - A popup will display the converted date and time
Alternative: Right-click on selected text and choose "Convert from epoch"
- Press
Ctrl + Shift + O(orCmd + Shift + Oon Mac) - The current epoch time is copied to your clipboard
- A notification confirms the action
Alternative: Right-click anywhere and choose "Give me Date.now to clipboard"
- Press
Ctrl + Shift + M(orCmd + Shift + Mon Mac) or right-click and select "Open Date to Epoch Converter" - A modal will appear with date/time inputs
- Enter the date, time, and GMT offset
- Click "Convert" to copy the epoch time to your clipboard
- Navigate to
chrome://extensions/ - Find "Epoch Time Converter" and click "Details"
- Click "Extension options"
- Customize the keyboard shortcuts:
- Choose the key (single character)
- Toggle Meta (Cmd/Ctrl) and Shift modifiers
- Click "Save"
The content script (src/content/content.ts) orchestrates all page-level functionality:
- Keyboard shortcut handling
- Modal display
- Notifications
- Message handling from background script
The background script (src/background/background.ts) handles:
- Context menu creation
- Message routing between context menu and content scripts
The options page (src/options/) provides:
- UI for configuring keyboard shortcuts
- Config persistence using Chrome storage API
- types.ts: TypeScript interfaces and types
- constants.ts: Magic numbers, CSS classes, default config
- config.ts: Configuration loading and saving utilities
The build process automatically bundles all modules into single files. This is required because Chrome extensions with Manifest V3 don't support ES modules in content scripts.
The bundling process:
- TypeScript compiles to ES2020 modules
- A custom bundler (
scripts/bundle-content.js) inlines all imports - All modules are combined into single files for content scripts, background, and options
The bundled files are:
dist/content/content.js- All content script modules bundleddist/background/background.js- Background service worker bundleddist/options/options.js- Options page script bundled
If you see Cannot find name 'chrome' errors:
- Make sure you've run
npm installto install@types/chrome - The local type definitions in
types/chrome.d.tsshould work as a fallback
If you see Cannot use import statement outside a module errors:
- Make sure you've run
npm run build(not justtsc) - The build process includes a bundling step that removes ES module syntax
- Check that
scripts/bundle-content.jsran successfully
- Make sure you've run
npm run buildto generate thedist/folder - Check the browser console for errors
- Verify
manifest.jsonpaths point todist/files - Make sure the bundling step completed successfully (check for "Bundling complete!" message)
- Check if shortcuts conflict with other extensions
- Verify the shortcuts are saved in the options page
- Reload the extension after changing shortcuts
Contributions are welcome! Please follow these guidelines:
- Keep functions under 50 lines
- Use TypeScript with strict mode
- Extract styles to CSS files (no inline styles)
- Add type definitions for new code
- Test your changes before submitting
This project is open source and available for use.
For questions or suggestions, contact Yarin.
Note: This extension has been refactored from JavaScript to TypeScript with improved code organization, type safety, and maintainability.