# SearchSyntax Pro (SSP) - Repository Context Report **Generated**: 2025-11-20 08:52:54 (Asia/Shanghai) **Version**: 1.7.2 **Purpose**: Requirements-driven development - Improved Floating Panel Feature --- ## ๐Ÿ“‹ Executive Summary SearchSyntax Pro is a professional Chrome extension for advanced search syntax visualization, supporting 10 search engines with 28+ advanced syntax features. Built with React 18 + TypeScript 5 + Vite 5, following Manifest V3 standards. The codebase demonstrates mature architecture with comprehensive i18n support, storage management, and modular adapter pattern for search engine integration. --- ## ๐ŸŽฏ Project Overview ### Project Type **Chrome Extension (Manifest V3)** - Browser productivity tool for search enhancement ### Core Purpose Transform complex search syntax into user-friendly visual interfaces, making advanced search features accessible to all users without memorizing syntax patterns. ### Key Metrics - **10 Search Engines**: Baidu, Google, Bing, DuckDuckGo, Brave, Yandex, Twitter/X, Reddit, GitHub, Stack Overflow - **28+ Advanced Syntax**: Site search, file types, exact match, date range, user filters, etc. - **2 UI Languages**: Chinese (zh-CN), English (en-US) - **3 Interface Modes**: Popup, Detached Window, Options Page --- ## ๐Ÿ—๏ธ Technical Architecture ### Technology Stack #### Core Framework ```yaml Runtime: TypeScript 5.2.2 (strict mode) UI Framework: React 18.2.0 Build Tool: Vite 5.0.0 CSS Framework: Tailwind CSS 3.3.6 Testing: Jest 29.7.0 + Playwright 1.40.1 ``` #### Chrome Extension Technologies ```yaml Standard: Manifest V3 Background: Service Worker (ES modules) Content Scripts: Injected at document_end Storage: Chrome Storage API (local) Permissions: storage, activeTab, contextMenus Host Permissions: Baidu, Google, Bing domains ``` #### Key Dependencies ```yaml UI Components: - @headlessui/react: 2.2.9 (accessible UI) - @dnd-kit/core: 6.3.1 (drag & drop) - date-fns: 2.30.0 (date manipulation) Development: - @crxjs/vite-plugin: 2.0.0-beta.21 (extension bundling) - @types/chrome: 0.0.258 (Chrome API types) - ESLint + Prettier (code quality) ``` ### Project Structure ``` /Users/lhly/chromeex/ssp/ โ”œโ”€โ”€ src/ # Source code โ”‚ โ”œโ”€โ”€ background/ # Service worker โ”‚ โ”‚ โ””โ”€โ”€ index.ts # Extension lifecycle management โ”‚ โ”œโ”€โ”€ content/ # Content scripts โ”‚ โ”‚ โ”œโ”€โ”€ index.ts # Main content script โ”‚ โ”‚ โ””โ”€โ”€ bing-enhancer/ # Bing-specific enhancements โ”‚ โ”œโ”€โ”€ popup/ # Extension popup UI โ”‚ โ”‚ โ”œโ”€โ”€ index.html โ”‚ โ”‚ โ”œโ”€โ”€ main.tsx โ”‚ โ”‚ โ””โ”€โ”€ App.tsx โ”‚ โ”œโ”€โ”€ detached/ # Standalone window mode โ”‚ โ”‚ โ”œโ”€โ”€ index.html โ”‚ โ”‚ โ”œโ”€โ”€ main.tsx โ”‚ โ”‚ โ””โ”€โ”€ App.tsx (shared with popup) โ”‚ โ”œโ”€โ”€ options/ # Settings page โ”‚ โ”‚ โ”œโ”€โ”€ index.html โ”‚ โ”‚ โ”œโ”€โ”€ main.tsx โ”‚ โ”‚ โ””โ”€โ”€ App.tsx โ”‚ โ”œโ”€โ”€ components/ # React components โ”‚ โ”‚ โ”œโ”€โ”€ SearchForm.tsx # Main search form โ”‚ โ”‚ โ”œโ”€โ”€ EngineSelector.tsx # Engine picker โ”‚ โ”‚ โ”œโ”€โ”€ TagInput.tsx # Multi-value input โ”‚ โ”‚ โ”œโ”€โ”€ QueryPreview.tsx # Generated query display โ”‚ โ”‚ โ”œโ”€โ”€ SearchHistory.tsx # History manager โ”‚ โ”‚ โ”œโ”€โ”€ SuggestionPanel.tsx # Smart suggestions โ”‚ โ”‚ โ””โ”€โ”€ __tests__/ # Component tests โ”‚ โ”œโ”€โ”€ services/ # Business logic โ”‚ โ”‚ โ”œโ”€โ”€ adapters/ # Search engine adapters โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ baidu.ts โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ google.ts โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ bing.ts โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ twitter.ts โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ reddit.ts โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ github.ts โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ stackoverflow.ts โ”‚ โ”‚ โ”œโ”€โ”€ storage.ts # Storage service โ”‚ โ”‚ โ”œโ”€โ”€ engine-preference.ts # Engine settings โ”‚ โ”‚ โ”œโ”€โ”€ suggestion-engine.ts # Smart suggestions โ”‚ โ”‚ โ””โ”€โ”€ template-manager.ts # Search templates โ”‚ โ”œโ”€โ”€ hooks/ # React hooks โ”‚ โ”‚ โ”œโ”€โ”€ useStorage.ts # Storage hook โ”‚ โ”‚ โ””โ”€โ”€ useTheme.tsx # Theme management โ”‚ โ”œโ”€โ”€ i18n/ # Internationalization โ”‚ โ”‚ โ”œโ”€โ”€ index.tsx # i18n provider โ”‚ โ”‚ โ””โ”€โ”€ translations.ts # Translation resources โ”‚ โ”œโ”€โ”€ types/ # TypeScript types โ”‚ โ”‚ โ””โ”€โ”€ index.ts # Core type definitions โ”‚ โ”œโ”€โ”€ utils/ # Utilities โ”‚ โ”‚ โ”œโ”€โ”€ version.ts โ”‚ โ”‚ โ””โ”€โ”€ migration.ts # Storage migration โ”‚ โ”œโ”€โ”€ config/ # Configuration โ”‚ โ”œโ”€โ”€ data/ # Static data โ”‚ โ””โ”€โ”€ styles/ # Global styles โ”œโ”€โ”€ public/ # Static assets โ”‚ โ”œโ”€โ”€ manifest.json # Extension manifest โ”‚ โ””โ”€โ”€ icons/ # Extension icons โ”œโ”€โ”€ tests/ # Test files โ”œโ”€โ”€ scripts/ # Build scripts โ”œโ”€โ”€ .github/workflows/ # CI/CD pipelines โ””โ”€โ”€ dist/ # Build output ``` --- ## ๐Ÿ”ง Code Patterns & Conventions ### TypeScript Patterns #### Type System ```typescript // Strict typing throughout "strict": true "noUnusedLocals": true "noUnusedParameters": true // Path aliases for clean imports "@/*": ["src/*"] "@/components/*": ["src/components/*"] "@/services/*": ["src/services/*"] "@/types/*": ["src/types/*"] "@/utils/*": ["src/utils/*"] "@/hooks/*": ["src/hooks/*"] "@/i18n/*": ["src/i18n/*"] ``` #### Core Type Definitions Located in `/src/types/index.ts`: - `SearchEngine`: Union type for 10 supported engines - `SearchParams`: Comprehensive search parameters interface - `UserSettings`: User preferences with engine order - `SearchHistory`: Historical search records - `UIFeatureType`: UI feature flags for engine capabilities - `SearchEngineAdapter`: Adapter interface for extensibility ### React Component Patterns #### Component Structure ```typescript // Functional components with TypeScript interface ComponentProps { // Explicit prop types searchParams: SearchParams onSearchParamsChange: (params: SearchParams) => void // Optional external state control showAdvanced?: boolean onToggleAdvanced?: (show: boolean) => void } export function Component({ /* props */ }: ComponentProps) { // Hooks first const { t } = useTranslation() const { data: settings } = useStorage('user_settings') // State management const [localState, setLocalState] = useState(initialValue) // Derived values const computed = useMemo(() => /* calculation */, [deps]) // Event handlers const handleAction = () => { /* ... */ } // Render return
...
} ``` #### State Management - **Local State**: `useState` for component-specific state - **Storage State**: Custom `useStorage` hook for Chrome storage - **Props Drilling**: Controlled component pattern for forms - **No Redux/Context**: Lightweight approach for extension scope ### Adapter Pattern for Search Engines ```typescript // Interface-based extensibility export interface SearchEngineAdapter { buildQuery(params: SearchParams): string validateSyntax(syntax: SyntaxType): boolean getSupportedSyntax(): SyntaxType[] getSupportedFeatures(): UIFeatureType[] getBaseUrl(): string getName(): string // Optional methods getLanguageOptions?(): LanguageFieldConfig getFeatureGroups?(): EngineFeatureGroups } // Factory pattern for adapter creation export class SearchAdapterFactory { static getAdapter(engine: SearchEngine): SearchEngineAdapter { // Return appropriate adapter instance } } ``` ### Internationalization (i18n) ```typescript // Translation hook usage const { t } = useTranslation() // Key-based translations t('searchForm.keywordLabel') t('common.searchEngines.google') // Parameterized translations t('contextMenu.searchSelection', undefined, 'ไฝฟ็”จ SearchSyntax Pro ๆœ็ดข "%s"') // Language switching user_settings.language: 'zh-CN' | 'en-US' ``` ### Chrome API Integration ```typescript // Storage access await chrome.storage.local.get('user_settings') await chrome.storage.local.set({ key: value }) // Message passing chrome.runtime.sendMessage({ action: 'open_search', url }) chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {}) // Context menus chrome.contextMenus.create({ id, title, contexts }) chrome.contextMenus.onClicked.addListener(handler) // Commands (shortcuts) chrome.commands.onCommand.addListener((command) => {}) ``` --- ## ๐ŸŽจ UI/UX Patterns ### Design System #### Tailwind CSS Approach ```javascript // Global utility classes className="input" // Standardized input styling className="btn btn-primary" // Button variants // Theme support darkMode: 'class' // Dark mode via class toggle // Custom theme extensions colors: { primary: { 50-900 }, // Blue scale gray: { 50-900 } // Gray scale } ``` #### Component Hierarchy 1. **Layout Components**: Containers, sections, grids 2. **Form Components**: Inputs, selects, buttons 3. **Display Components**: Preview, history, suggestions 4. **Interactive Components**: Collapsible sections, drag-drop lists ### Responsive Design - Popup: Fixed 400px width (Chrome extension standard) - Detached Window: Resizable, state persistence - Options Page: Full-width responsive layout ### Accessibility - Semantic HTML elements - ARIA labels via translations - Keyboard navigation support - `@headlessui/react` for accessible components --- ## ๐Ÿ“ฆ Build & Development Workflow ### Development Commands ```bash # Development mode (hot reload) npm run dev # Production build npm run build # Type checking npm run type-check # Linting & formatting npm run lint npm run lint:fix npm run format # Testing npm run test # Unit tests npm run test:e2e # E2E tests # Packaging npm run package # Build + create ZIP npm run package:only # Create ZIP from existing build ``` ### Build Process ```yaml Entry Points (vite.config.ts): - popup: src/popup/index.html - detached: src/detached/index.html - options: src/options/index.html - background: src/background/index.ts - content: src/content/index.ts Output Structure: dist/ โ”œโ”€โ”€ src/popup/index.html โ”œโ”€โ”€ src/detached/index.html โ”œโ”€โ”€ src/options/index.html โ”œโ”€โ”€ background.js โ”œโ”€โ”€ content.js โ”œโ”€โ”€ popup.js โ”œโ”€โ”€ detached.js โ”œโ”€โ”€ options.js โ”œโ”€โ”€ icons/ โ””โ”€โ”€ manifest.json (copied from public/) Post-Build Scripts: - scripts/post-build.js: Manifest adjustments - scripts/package.js: ZIP creation for store submission ``` ### CI/CD Pipeline ```yaml Workflow: .github/workflows/release.yml Triggers: - Tag push (v*.*.*) โ†’ Full release workflow - Main branch push โ†’ Build + test only - Pull requests โ†’ Quality checks Steps: 1. Build and test 2. Version consistency check 3. Generate ZIP package 4. Create GitHub Release (draft) Artifacts: - ssp-v{version}.zip - Build logs ``` --- ## ๐Ÿ”Œ Integration Points ### Content Script Injection **Current State**: Feature flag controlled ```typescript // src/content/index.ts const FEATURE_FLAGS = { enableFloatingButton: false // Experimental feature disabled } ``` **Injection Targets**: - Baidu: www.baidu.com/* - Google: www.google.com/* - Bing: www.bing.com/* **Capabilities**: - Search query analysis - Syntax highlighting - Quick search text selection - Message communication with background **Important**: Content scripts run at `document_end` in isolated context ### Background Service Worker **Responsibilities**: - Extension lifecycle management - Storage migration on updates - Context menu creation/management - Message routing between components - Periodic data cleanup **Key Features**: - Automatic storage migration on version updates - Dynamic context menu based on user settings - Language-aware menu text - Shortcut command handling ### Chrome Storage Schema ```typescript ChromeStorageData = { search_history: SearchHistory[] user_settings: UserSettings quick_search_text: string quick_search_trigger: number app_cache: { timestamp: number, ... } } ``` **Migration System**: Automatic schema upgrades via `autoMigrateStorage()` --- ## ๐ŸŽฏ Feature Implementation Patterns ### Right-Click Quick Search **Flow**: 1. User selects text โ†’ Right-click โ†’ "Search with SSP" 2. Background stores text + timestamp trigger 3. Popup auto-loads text when opened 4. Search form pre-fills and focuses engine selection **Key Files**: - Background: `src/background/index.ts` (context menu) - Popup: `src/popup/App.tsx` (auto-fill logic) - Storage: Quick search keys in `ChromeStorageData` ### Engine Preference Management **User-Controlled Ordering**: ```typescript EnginePreference = { engine: SearchEngine visible: boolean order: number // Lower = higher priority } ``` **Services**: - `EnginePreferenceService.getVisibleEngines()`: Sorted visible list - Drag-drop UI in options page - Auto-save to storage ### Multi-Language Support **Architecture**: ```typescript // Centralized translations translations.ts: { 'zh-CN': { ... }, 'en-US': { ... } } // Provider pattern // Hook-based access const { t, language } = useTranslation() ``` **Coverage**: All UI text, context menus, error messages --- ## ๐Ÿšจ Constraints & Considerations ### Chrome Extension Limitations 1. **Popup Lifecycle**: - Popup closes when user clicks outside - State must be persisted to storage - No background processes after close 2. **Content Script Isolation**: - Separate JavaScript context from page - Cannot access page's JS variables directly - Must use message passing for communication 3. **Manifest V3 Restrictions**: - Service worker instead of background pages - No persistent background context - Limited executeScript capabilities 4. **Storage Quotas**: - 5MB limit for chrome.storage.local - Automatic cleanup of 30-day-old data - Backup/restore functionality provided ### Performance Considerations 1. **Bundle Size**: Vite code splitting for lazy loading 2. **Storage Access**: Async operations with error handling 3. **Re-renders**: Memoization for expensive computations 4. **Animation**: CSS-based, Tailwind keyframes ### Security 1. **CSP Policy**: `script-src 'self'; object-src 'self'` 2. **Host Permissions**: Limited to search engine domains 3. **No External Scripts**: All code bundled locally 4. **Privacy**: No data transmission to external servers --- ## ๐Ÿ“ Development Best Practices ### Code Standards ```json // ESLint configuration { "extends": [ "eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:react-hooks/recommended" ], "rules": { "max-warnings": 0, "react-hooks/exhaustive-deps": "warn" } } ``` ### Testing Strategy 1. **Unit Tests**: Jest + React Testing Library - Component rendering - User interactions - Business logic validation 2. **E2E Tests**: Playwright - Extension installation - User workflows - Chrome API interactions 3. **Type Safety**: TypeScript strict mode - No implicit any - Exhaustive switch cases - Null safety checks ### Git Workflow ```yaml Branching: - main: Production-ready code - feature/*: New features - fix/*: Bug fixes Commits: - Conventional commits format - feat: New features - fix: Bug fixes - chore: Tooling changes Versioning: - npm version (patch|minor|major) - Auto-sync package.json โ†” manifest.json - Tag-based releases ``` --- ## ๐ŸŽฏ Integration Points for New Features ### Adding Floating Panel Feature **Recommended Approach**: 1. **Content Script Enhancement**: - Leverage existing `src/content/index.ts` - Enable `FEATURE_FLAGS.enableFloatingButton` - Extend `injectSearchFeatures()` function 2. **Component Structure**: ``` src/content/ โ”œโ”€โ”€ index.ts (entry point) โ”œโ”€โ”€ floating-panel/ โ”‚ โ”œโ”€โ”€ FloatingPanel.tsx (React component) โ”‚ โ”œโ”€โ”€ styles.css (scoped styles) โ”‚ โ””โ”€โ”€ hooks/ โ”‚ โ”œโ”€โ”€ usePosition.ts (drag/resize) โ”‚ โ””โ”€โ”€ usePanelState.ts (visibility) ``` 3. **State Management**: - Chrome storage for panel position - Message passing for search actions - Shared types from `@/types` 4. **UI Rendering in Content Script**: ```typescript // Create Shadow DOM for isolation const container = document.createElement('div') const shadow = container.attachShadow({ mode: 'open' }) // Render React component const root = createRoot(shadow) root.render() ``` 5. **Styling Considerations**: - Shadow DOM isolation from page styles - Inline critical CSS or use CSS-in-JS - Avoid conflicts with Tailwind (if used) 6. **Communication Pattern**: ```typescript // Content โ†’ Background chrome.runtime.sendMessage({ action: 'execute_search', params: searchParams }) // Background โ†’ Content chrome.tabs.sendMessage(tabId, { action: 'update_panel_state', visible: true }) ``` --- ## ๐Ÿ“Š Current Feature Status ### Implemented Features (v1.7.2) - โœ… Visual search syntax builder - โœ… 10 search engine support - โœ… Multi-keyword input (sites, file types, exact matches) - โœ… Search history management - โœ… Right-click quick search - โœ… Detached window mode - โœ… Engine preference ordering (drag-drop) - โœ… Full i18n support (Chinese + English) - โœ… Dark mode support - โœ… Keyboard shortcuts (Ctrl/Cmd+Shift+F) - โœ… Storage migration system - โœ… CI/CD automated releases ### Experimental Features (Disabled) - โš ๏ธ Floating button on search pages (`enableFloatingButton: false`) - ๐Ÿ“ Planned: Improved floating panel (current requirement) ### Planned Features (Roadmap) - ๐Ÿ”œ 10 additional universal syntax types - ๐Ÿ”œ Platform-specific syntax (GitHub, Reddit, Stack Overflow) - ๐Ÿ”œ Search templates - ๐Ÿ”œ Advanced query builder - ๐Ÿ”œ Export/import settings --- ## ๐Ÿ”— Key Files for Reference ### Must-Read Files ``` /src/types/index.ts # Core type system /src/content/index.ts # Content script structure /src/background/index.ts # Extension lifecycle /src/components/SearchForm.tsx # Main UI component /src/services/adapters/* # Engine adapter examples /public/manifest.json # Extension configuration /vite.config.ts # Build configuration ``` ### Configuration Files ``` /package.json # Dependencies & scripts /tsconfig.json # TypeScript config /tailwind.config.js # Styling system /.eslintrc.json # Code quality rules /.prettierrc # Code formatting ``` ### Documentation ``` /README.md # Project overview /README.zh-CN.md # Chinese documentation /PRIVACY.md # Privacy policy /docs/* # Additional guides ``` --- ## ๐ŸŽ“ Learning Resources ### Understanding the Codebase 1. **Start with Types**: Read `/src/types/index.ts` for data models 2. **Explore Adapters**: See pattern in `/src/services/adapters/baidu.ts` 3. **Study Components**: Check `/src/components/SearchForm.tsx` for UI patterns 4. **Review Storage**: Understand persistence in `/src/services/storage.ts` ### Chrome Extension APIs - [Manifest V3 Guide](https://developer.chrome.com/docs/extensions/mv3/) - [Content Scripts](https://developer.chrome.com/docs/extensions/mv3/content_scripts/) - [Service Workers](https://developer.chrome.com/docs/extensions/mv3/service_workers/) - [Storage API](https://developer.chrome.com/docs/extensions/reference/storage/) ### React Patterns - Controlled components for forms - Custom hooks for Chrome storage - Context-free state management (lightweight approach) --- ## ๐Ÿš€ Next Steps for Floating Panel Implementation ### Phase 1: Research & Design 1. Review existing content script (`src/content/index.ts`) 2. Analyze disabled floating button implementation 3. Define improved UX requirements 4. Design component architecture ### Phase 2: Core Implementation 1. Create component structure in `src/content/floating-panel/` 2. Implement Shadow DOM rendering 3. Build draggable/resizable panel UI 4. Integrate with existing search system ### Phase 3: Integration & Testing 1. Connect to Chrome storage for state 2. Message passing with background/popup 3. Cross-browser compatibility testing 4. Performance optimization ### Phase 4: Polish & Documentation 1. Accessibility improvements 2. Animation refinements 3. User documentation 4. Code comments and examples --- ## ๐Ÿ“ง Contact & Resources - **Repository**: https://github.com/lhly/search-syntax-pro - **Issues**: https://github.com/lhly/search-syntax-pro/issues - **Author**: ๅ†ท็ซๅ‡‰็ƒŸ - **License**: MIT --- **Document Version**: 1.0 **Last Updated**: 2025-11-20 **For**: Improved Floating Panel Feature Development