- Created manifest.json for the Crawl4AI Assistant extension. - Added popup HTML, CSS, and JS files for the extension interface. - Included icons and favicon for the extension. - Implemented functionality for schema capture and code generation. - Updated index.md to reflect the availability of the new extension. - Enhanced LLM Context Builder layout and styles for consistency. - Adjusted global styles for better branding and responsiveness.
39 lines
1.3 KiB
JavaScript
39 lines
1.3 KiB
JavaScript
// Service worker for Crawl4AI Assistant
|
|
|
|
// Handle messages from content script
|
|
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
|
if (message.action === 'downloadCode') {
|
|
try {
|
|
// Create a data URL for the Python code
|
|
const dataUrl = 'data:text/plain;charset=utf-8,' + encodeURIComponent(message.code);
|
|
|
|
// Download the file
|
|
chrome.downloads.download({
|
|
url: dataUrl,
|
|
filename: message.filename || 'crawl4ai_schema.py',
|
|
saveAs: true
|
|
}, (downloadId) => {
|
|
if (chrome.runtime.lastError) {
|
|
console.error('Download failed:', chrome.runtime.lastError);
|
|
sendResponse({ success: false, error: chrome.runtime.lastError.message });
|
|
} else {
|
|
console.log('Download started with ID:', downloadId);
|
|
sendResponse({ success: true, downloadId: downloadId });
|
|
}
|
|
});
|
|
} catch (error) {
|
|
console.error('Error creating download:', error);
|
|
sendResponse({ success: false, error: error.message });
|
|
}
|
|
|
|
return true; // Keep the message channel open for async response
|
|
}
|
|
|
|
return false;
|
|
});
|
|
|
|
// Clean up on extension install/update
|
|
chrome.runtime.onInstalled.addListener(() => {
|
|
// Clear any stored state
|
|
chrome.storage.local.clear();
|
|
}); |