Skip to content

caioreix/json-modal-extension

Repository files navigation

JSON Modal Extension

Chrome extension that displays JSON on web pages with a CodeMirror editor.

What it does

When you access a page displaying raw JSON (like an API endpoint), the extension automatically detects it and shows a floating button. Clicking it opens a modal with formatted JSON and syntax highlighting. Also works by selecting any JSON on a page - a "{}" icon appears and you click to open the editor.

Installation

  1. Clone the project
  2. Run pnpm install
  3. Run pnpm run build
  4. In Chrome, go to chrome://extensions/
  5. Enable "Developer mode"
  6. Click "Load unpacked" and select the dist folder

Development

pnpm start          # development server
pnpm run watch      # build with watch mode
pnpm run build      # production build

Structure

src/
├── popup/                    # Extension popup UI
│   ├── index.js             # Popup entry point
│   ├── App.js               # Main popup component
│   └── components/
│       └── Settings.js      # Settings component
├── content/                  # Content script (runs on web pages)
│   ├── index.js             # Content script entry point
│   ├── components/          # React components
│   │   ├── CodeEditor.js   # CodeMirror editor
│   │   ├── JsonModal.js    # Modal component
│   │   └── Tooltip.js      # Selection tooltip
│   ├── services/            # Business logic
│   │   ├── jsonDetector.js # JSON detection
│   │   ├── settingsManager.js # Settings management
│   │   └── themeManager.js # Theme management
│   └── utils/               # Content-specific utilities
│       ├── selectionHandler.js # Text selection handling
│       └── clipboard.js    # Clipboard operations
├── shared/                   # Shared code
│   ├── constants/           # Global constants
│   │   ├── themes.js       # Theme constants
│   │   └── storage.js      # Storage constants
│   ├── utils/               # Shared utilities
│   │   ├── storage.js      # Chrome storage operations
│   │   └── json.js         # JSON utilities
│   └── styles/
│       └── tailwind.css    # Global styles
├── config/                   # Configuration
│   └── codemirror.js       # CodeMirror config
└── icons/
    └── createIcons.js      # Icon generation

The build generates separate bundles to optimize loading:

  • Popup bundle: Settings UI with code splitting for vendors
  • Content bundle: Everything needed for the content script (no splitting to ensure it works in all contexts)
  • CodeMirror stays in its own chunk (~240KB)
  • Vendors (React) in another chunk (~199KB)
  • Main scripts are lightweight (~9KB each)

For detailed architecture documentation, see ARCHITECTURE.md.

Features

  • Automatic JSON page detection
  • Editor with syntax highlighting
  • Light/dark/system themes
  • Copy to clipboard
  • Auto formatting
  • Responsive modal with scroll

Stack

  • React 18
  • CodeMirror 6
  • Webpack 5
  • Tailwind CSS
  • Chrome Extension Manifest V3

🎯 Extension Installation

  1. Run NODE_ENV=production pnpm run build
  2. Open chrome://extensions/
  3. Enable "Developer mode"
  4. Click "Load unpacked"
  5. Select the dist/ folder
  6. ✅ Extension installed and working!

📈 Final Results

  • Performance: 99% reduction in bundle sizes
  • 🐛 Bugs: All identified bugs have been fixed
  • 🧹 Cleanup: Optimized code without unnecessary dependencies
  • 🎨 UI/UX: Modernized and responsive interface
  • 🚀 Build: Robust and optimized build system
  • 🔍 Auto-Detection: Automatically detects and displays JSON on pages

🎯 How to Use

1. Text Selection

  • Select any valid JSON on a web page
  • A floating button will appear automatically
  • Click to open the JSON in a formatted modal

2. JSON Auto-Detection

  • When accessing a page displaying raw JSON (like API endpoints)
  • A floating button will appear in the bottom right corner
  • Click to view the JSON formatted
  • Configure in settings to enable/disable

3. Settings

  • Click the extension icon to open settings
  • Choose between themes: Light, Dark, or System
  • Enable/Disable the extension
  • Turn on/off JSON auto-detection
  • See a live preview of your settings

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors