Skip to content
Merged
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
10 changes: 5 additions & 5 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ icons/ → Extension icons (16, 48, 128px)
## Architecture

**Two Trigger Methods:**
- Popup button → `popup.js` injects libs + calls `extractContent()` + `generateFilename()`
- Popup button → `popup.js` injects libs + calls `extractContent()` + `generateBaseName()`
- Right-click menu → `background.js` injects libs + `content-script.js`

**Data Flow:**
1. Inject `lib/*.js` scripts into page context
2. `extractContent()` uses Readability to extract article content
2. `extractContent()` uses Readability to extract article content (includes pre-analyzed images)
3. Turndown converts HTML to Markdown (with GFM tables/strikethrough)
4. `generateFilename()` creates safe filename from title + date
5. Images embedded as `![alt](url)` - no local download
6. Markdown saved via `window.showSaveFilePicker()`
4. `generateBaseName()` creates safe base name from title + date
5. Images embedded as `![alt](url)` or downloaded locally (experimental setting)
6. Markdown saved via Chrome downloads API to `Downloads/EzyCopy/`

## Key Libraries

Expand Down
44 changes: 22 additions & 22 deletions content-script.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// This script is injected after the lib scripts (readability, turndown, ezycopy, platform)
// extractContent(), formatContent(), generateFilename(), generateSubfolder(),
// extractImagesFromHtml(), and rewriteImagePaths() are available from lib/
// This script is injected after the lib scripts (readability, turndown, ezycopy)
// extractContent(), formatContent(), generateBaseName() are global functions from lib/ezycopy.js
// extraction.images contains pre-analyzed image data (no need for separate extraction call)
// EzyCopyFiles.rewriteImagePaths() is available from file-helpers.js

/**
* Build success message based on actions performed
Expand Down Expand Up @@ -55,8 +56,8 @@ async function downloadMarkdownFile(content, filename) {
const { copyToClipboard: shouldCopy, downloadMarkdown: shouldDownload, includeImages } = settings;
const { selectiveCopy, downloadImagesLocally } = settings.experimental || {};

// Extract content (respects selectiveCopy setting)
const extraction = extractContent({ selectiveCopy });
// Extract content (respects selectiveCopy and includeImages settings)
const extraction = extractContent({ selectiveCopy, includeImages });

let clipboardContent = null;
let downloadContent = null;
Expand All @@ -72,27 +73,26 @@ async function downloadMarkdownFile(content, filename) {
downloadContent = formatContent(extraction, 'download', settings);

// Handle image downloads if all conditions met
if (includeImages && downloadImagesLocally && extraction.html) {
const images = extractImagesFromHtml(extraction.html);
if (images.length > 0) {
showFeedback(`Downloading ${images.length} images...`, "#2196F3");

const subfolder = generateSubfolder(extraction.title);
const imageResult = await chrome.runtime.sendMessage({
action: 'downloadImages',
images: images,
subfolder: subfolder
});

if (imageResult.downloadedCount > 0) {
downloadContent = rewriteImagePaths(downloadContent, imageResult.urlToPathMap);
imageCount = imageResult.downloadedCount;
}
// Images are pre-analyzed in extraction result (single-pass optimization)
if (includeImages && downloadImagesLocally && extraction.images?.length > 0) {
const images = extraction.images;
showFeedback(`Downloading ${images.length} images...`, "#2196F3");

const subfolder = generateBaseName(extraction.title);
const imageResult = await chrome.runtime.sendMessage({
action: 'downloadImages',
images: images,
subfolder: subfolder
});

if (imageResult.downloadedCount > 0) {
downloadContent = EzyCopyFiles.rewriteImagePaths(downloadContent, imageResult.urlToPathMap);
imageCount = imageResult.downloadedCount;
}
}
}

const filename = generateFilename(extraction.title);
const filename = generateBaseName(extraction.title) + '.md';

// Execute outputs
let copiedToClipboard = false;
Expand Down
11 changes: 0 additions & 11 deletions file-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,6 @@
}
}

function generatePageSubfolder(pageTitle) {
const safeTitle = pageTitle
.substring(0, 50)
.replace(/[^a-zA-Z0-9]/g, '-')
.replace(/-+/g, '-')
.replace(/^-|-$/g, '');
const timestamp = new Date().toISOString().slice(0, 10);
return `${safeTitle}-${timestamp}`;
}

function rewriteImagePaths(markdown, urlToPathMap) {
let result = markdown;

Expand All @@ -71,7 +61,6 @@
getBasePath,
getImagesPath,
sanitizeImageFilename,
generatePageSubfolder,
rewriteImagePaths,
};
})(typeof self !== 'undefined' ? self : this);
1 change: 0 additions & 1 deletion injection-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"lib/turndown-plugin-gfm.js",
"file-helpers.js",
"lib/ezycopy.js",
"lib/platform.js",
"content-script.js",
];

Expand Down
Loading