5d42e03b90
- Add explicit return value to message listener in content.js - Fix documentation references in QUICKSTART.md - Clarify that GET_PAGE_INFO listener is reserved for future use Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
36 lines
1.2 KiB
JavaScript
36 lines
1.2 KiB
JavaScript
// Content script for DocuElevate browser extension
|
|
|
|
// This script runs on all web pages to detect file URLs
|
|
// and enable communication between page content and the extension
|
|
|
|
// Listen for messages from the popup (reserved for future use)
|
|
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
|
if (message.type === 'GET_PAGE_INFO') {
|
|
// Return information about the current page
|
|
const pageInfo = {
|
|
url: window.location.href,
|
|
title: document.title
|
|
};
|
|
sendResponse(pageInfo);
|
|
return true; // Indicates response will be sent asynchronously
|
|
}
|
|
return false; // No async response
|
|
});
|
|
|
|
// Detect if current page is a direct file link
|
|
function isDirectFileUrl(url) {
|
|
const fileExtensions = [
|
|
'.pdf', '.doc', '.docx', '.xls', '.xlsx', '.ppt', '.pptx',
|
|
'.txt', '.csv', '.rtf', '.jpg', '.jpeg', '.png', '.gif',
|
|
'.bmp', '.tiff', '.webp', '.svg'
|
|
];
|
|
|
|
const urlLower = url.toLowerCase();
|
|
return fileExtensions.some(ext => urlLower.endsWith(ext));
|
|
}
|
|
|
|
// Add visual indicator for file pages (optional enhancement)
|
|
if (isDirectFileUrl(window.location.href)) {
|
|
console.log('DocuElevate: Direct file URL detected');
|
|
}
|