From f9abc3afeb1b752099ca27362966c07ec7f1b9ca Mon Sep 17 00:00:00 2001 From: luorome31 <2743057396@qq.com> Date: Sun, 29 Mar 2026 14:27:37 +0800 Subject: [PATCH 1/3] feat: UI optimizations - plugin name, debug toggle, highlight color, dynamic card width - Add plugin name "InlineNote" to popup header - Hide debug overlay unless apiConfig.debug is true - Change Alt highlight border from yellow to light blue - Make note card width dynamic based on selected text rect - Remove chrome_url_overrides.newtab (restore default newtab) - Simplify config.ts - remove unused API config variables --- manifest.json | 7 ++----- src/pages/background/config.ts | 19 +------------------ src/pages/content/index.tsx | 16 ++++++++++++++-- .../content/services/HighlightController.ts | 2 +- src/pages/content/services/NoteCard.ts | 13 +++++++++++-- src/pages/popup/Popup.tsx | 15 ++++++++------- src/pages/popup/popup.css | 9 ++++++++- 7 files changed, 45 insertions(+), 36 deletions(-) diff --git a/manifest.json b/manifest.json index 2226736..38c532d 100755 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 3, - "name": "name in manifest.json", - "description": "description in manifest.json", + "name": "InlineNote", + "description": "An inline AI note-taking extension. Hover, press, and get LLM-powered insights seamlessly embedded into your reading flow.", "options_ui": { "page": "src/pages/options/index.html", "open_in_tab": true @@ -12,9 +12,6 @@ "32": "icon-32.png" } }, - "chrome_url_overrides": { - "newtab": "src/pages/newtab/index.html" - }, "icons": { "128": "icon-128.png" }, diff --git a/src/pages/background/config.ts b/src/pages/background/config.ts index f1e0dd6..c3f0688 100644 --- a/src/pages/background/config.ts +++ b/src/pages/background/config.ts @@ -1,22 +1,5 @@ // src/pages/background/config.ts -export interface APIConfig { - baseURL: string; - apiKey: string; - model: string; - maxTokens: number; - temperature: number; - systemPrompt: string; - debug?: boolean; -} - -export const apiConfig: APIConfig = { - // ⚠️ TODO: T012 将迁移到 chrome.storage.local - baseURL: 'https://api.deepseek.com', - apiKey: 'YOUR_API_KEY_HERE', // 替换为你的 API Key - model: 'deepseek-chat', - maxTokens: 1000, - temperature: 0.7, - systemPrompt: '你是一个专业的助手,请简洁地解释用户提供的内容。', +export const apiConfig = { debug: false, }; diff --git a/src/pages/content/index.tsx b/src/pages/content/index.tsx index f0a2e41..3cbc904 100644 --- a/src/pages/content/index.tsx +++ b/src/pages/content/index.tsx @@ -9,6 +9,7 @@ import type { SelectedBlock } from './types/content.types'; import { KeyboardController } from './services/KeyboardController'; import { ExportPreviewModal } from './components/ExportPreviewModal'; import type { NoteData } from '../background/messageTypes'; +import { apiConfig } from '@pages/background/config'; let noteCard: NoteCard | null = null; let keyboardController: KeyboardController | null = null; @@ -121,7 +122,12 @@ async function handleExportShortcut(): Promise { return true; } -function createNoteCard(targetElement: HTMLElement, originalText: string, pageUrl: string) { +function createNoteCard( + targetElement: HTMLElement, + originalText: string, + pageUrl: string, + rect?: { width: number } +) { // Prevent duplicate note cards for the same text being processed if (processingNoteId) { console.log('[ContentScript] Already processing a note, skipping duplicate creation'); @@ -136,6 +142,7 @@ function createNoteCard(targetElement: HTMLElement, originalText: string, pageUr id: noteId, originalText, targetElement, + rect, onClose: (closedNoteId: string) => { // Remove note from currentPageNotes by id currentPageNotes = currentPageNotes.filter((n) => n.id !== closedNoteId); @@ -330,7 +337,8 @@ function SelectionDisplay() { createNoteCard( selectedBlockRef.current.element, selectedBlockRef.current.text, - window.location.href + window.location.href, + { width: selectedBlockRef.current.rect.width } ); } }; @@ -346,6 +354,10 @@ function SelectionDisplay() { }; }, []); + if (!apiConfig.debug) { + return null; + } + if (!selectedBlock) { return (
diff --git a/src/pages/content/services/HighlightController.ts b/src/pages/content/services/HighlightController.ts index 326f286..20f1649 100644 --- a/src/pages/content/services/HighlightController.ts +++ b/src/pages/content/services/HighlightController.ts @@ -14,7 +14,7 @@ export class HighlightController { this.highlightLayer.style.cssText = ` position: fixed; pointer-events: none; - border: 2px dashed rgba(255, 200, 0, 0.6); + border: 2px dashed rgba(96, 165, 250, 0.6); border-radius: 4px; z-index: 2147483647; transition: all 0.1s ease; diff --git a/src/pages/content/services/NoteCard.ts b/src/pages/content/services/NoteCard.ts index 5a30348..011d23b 100644 --- a/src/pages/content/services/NoteCard.ts +++ b/src/pages/content/services/NoteCard.ts @@ -10,6 +10,7 @@ export interface NoteCardOptions { id: string; originalText: string; targetElement: HTMLElement; + rect?: { width: number }; onClose?: (id: string) => void; } @@ -43,6 +44,12 @@ export class NoteCard { private render(): void { if (!this.shadow) return; + // Calculate dynamic width from rect if provided + const rectWidth = this.options.rect?.width; + const minWidth = Math.max(200, rectWidth || 0); + const maxWidth = Math.min(600, rectWidth || 420); + const cardWidth = rectWidth ? `${Math.min(Math.max(rectWidth, minWidth), maxWidth)}px` : '100%'; + const style = document.createElement('style'); style.textContent = ` .note-card { @@ -53,10 +60,12 @@ export class NoteCard { border: 1px solid rgba(0, 0, 0, 0.12); border-radius: 8px; box-shadow: none; - min-width: 320px; - max-width: 420px; + width: ${cardWidth}; + min-width: 200px; + max-width: 600px; overflow: hidden; margin-top: 8px; + box-sizing: border-box; } @media (prefers-color-scheme: dark) { .note-card { diff --git a/src/pages/popup/Popup.tsx b/src/pages/popup/Popup.tsx index e976149..77c5d0d 100644 --- a/src/pages/popup/Popup.tsx +++ b/src/pages/popup/Popup.tsx @@ -25,13 +25,13 @@ export default function Popup() { const [disabledSites, setDisabledSites] = useState([]); // Get sorted providers from apiKeys with id, fallback to PROVIDERS - const sortedProviderItems = apiKeys.length > 0 - ? [...apiKeys].sort((a, b) => a.displayOrder - b.displayOrder) - : []; + const sortedProviderItems = + apiKeys.length > 0 ? [...apiKeys].sort((a, b) => a.displayOrder - b.displayOrder) : []; // For display, use name; for selection, use id - const providerOptions = sortedProviderItems.length > 0 - ? sortedProviderItems.map((k) => ({ id: k.id, name: k.name })) - : PROVIDERS.map((p) => ({ id: p, name: p })); + const providerOptions = + sortedProviderItems.length > 0 + ? sortedProviderItems.map((k) => ({ id: k.id, name: k.name })) + : PROVIDERS.map((p) => ({ id: p, name: p })); useEffect(() => { // Load settings from storage @@ -188,8 +188,9 @@ export default function Popup() { return (
- {/* Header with settings */} + {/* Header with plugin name and settings */}
+ InlineNote