Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -12,9 +12,6 @@
"32": "icon-32.png"
}
},
"chrome_url_overrides": {
"newtab": "src/pages/newtab/index.html"
},
"icons": {
"128": "icon-128.png"
},
Expand Down
Binary file modified public/dev-icon-128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/dev-icon-32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/icon-128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/icon-32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 1 addition & 18 deletions src/pages/background/config.ts
Original file line number Diff line number Diff line change
@@ -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,
};
16 changes: 14 additions & 2 deletions src/pages/content/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -121,7 +122,12 @@ async function handleExportShortcut(): Promise<boolean> {
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');
Expand All @@ -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);
Expand Down Expand Up @@ -330,7 +337,8 @@ function SelectionDisplay() {
createNoteCard(
selectedBlockRef.current.element,
selectedBlockRef.current.text,
window.location.href
window.location.href,
{ width: selectedBlockRef.current.rect.width }
);
}
};
Expand All @@ -346,6 +354,10 @@ function SelectionDisplay() {
};
}, []);

if (!apiConfig.debug) {
return null;
}

if (!selectedBlock) {
return (
<div className="fixed bottom-4 left-4 bg-amber-400 text-black px-4 py-2 rounded-lg z-50">
Expand Down
2 changes: 1 addition & 1 deletion src/pages/content/services/HighlightController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 11 additions & 2 deletions src/pages/content/services/NoteCard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface NoteCardOptions {
id: string;
originalText: string;
targetElement: HTMLElement;
rect?: { width: number };
onClose?: (id: string) => void;
}

Expand Down Expand Up @@ -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%';
Comment on lines +49 to +51

Copilot AI Mar 29, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The width clamping math is incorrect when rectWidth is below 200: maxWidth becomes rectWidth, so cardWidth can end up < 200px (e.g., 100px), violating the intended 200–600px range. Consider simplifying to a single clamp like clamp(rectWidth, 200, 600) and using that value for the width when rectWidth is provided.

Suggested change
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 cardWidth = rectWidth
? `${Math.max(200, Math.min(rectWidth, 600))}px`
: '100%';

Copilot uses AI. Check for mistakes.
Comment on lines +47 to +51

Copilot AI Mar 29, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NoteCard now supports rect-based dynamic sizing (200–600px), but there are existing unit tests for NoteCard and none appear to assert the computed width behavior. Adding tests for sizing edge cases (rectWidth < 200, 200–600, > 600) would help prevent regressions.

Suggested change
// 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%';
// Calculate dynamic width from rect if provided, clamped between 200px and 600px
const rectWidth = this.options.rect?.width;
const cardWidth = rectWidth
? `${Math.min(Math.max(rectWidth, 200), 600)}px`
: '100%';

Copilot uses AI. Check for mistakes.

const style = document.createElement('style');
style.textContent = `
.note-card {
Expand All @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions src/pages/content/services/sanitizeHtml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/**
* Sanitize HTML string for display (e.g., NoteCard).
* Removes script tags, event handlers, dangerous URLs, dangerous tags,
* and strips think/cognition tags while keeping their content.
* and removes think/cognition tags and their content entirely.
*/
export function sanitizeHtml(html: string): string {
let sanitized = html;
Expand All @@ -31,9 +31,9 @@ export function sanitizeHtml(html: string): string {
sanitized = sanitized.replace(/expression\s*\([^)]*\)/gi, '');
sanitized = sanitized.replace(/binding\s*:/gi, 'noop:');
sanitized = sanitized.replace(/url\s*\(['"]javascript:[^'"]*['"]\)/gi, '');
// Remove think/cognition tags but keep their content
sanitized = sanitized.replace(/<think[^>]*>([\s\S]*?)<\/think>/gi, '$1');
sanitized = sanitized.replace(/<cognition[^>]*>([\s\S]*?)<\/cognition>/gi, '$1');
// Remove think/cognition tags and their content entirely
sanitized = sanitized.replace(/<think[^>]*>[\s\S]*?<\/think>/gi, '');
sanitized = sanitized.replace(/<cognition[^>]*>[\s\S]*?<\/cognition>/gi, '');
return sanitized;
}

Expand Down
15 changes: 8 additions & 7 deletions src/pages/popup/Popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ export default function Popup() {
const [disabledSites, setDisabledSites] = useState<string[]>([]);

// 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
Expand Down Expand Up @@ -188,8 +188,9 @@ export default function Popup() {

return (
<div className="popup-container">
{/* Header with settings */}
{/* Header with plugin name and settings */}
<div className="popup-header">
<span className="popup-title">InlineNote</span>
<button
className="settings-btn"
onClick={handleOpenSettings}
Expand Down
9 changes: 8 additions & 1 deletion src/pages/popup/popup.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,17 @@
/* Header */
.popup-header {
display: flex;
justify-content: flex-end;
justify-content: space-between;
align-items: center;
margin-bottom: 12px;
}

.popup-title {
font-size: 15px;
font-weight: 600;
color: #1e293b;
}

.settings-btn {
width: 36px;
height: 36px;
Expand Down
Loading