uploadte to corect preview and print the labels for 1 row
This commit is contained in:
@@ -30,6 +30,9 @@ function initializePrintExtension() {
|
||||
}
|
||||
|
||||
function addExtensionStatusIndicator() {
|
||||
// Detect browser type
|
||||
const browserType = getBrowserType();
|
||||
|
||||
// Create status indicator element
|
||||
const statusIndicator = document.createElement('div');
|
||||
statusIndicator.id = 'extension-status';
|
||||
@@ -37,24 +40,39 @@ function addExtensionStatusIndicator() {
|
||||
position: fixed;
|
||||
top: 10px;
|
||||
right: 10px;
|
||||
background: #28a745;
|
||||
color: white;
|
||||
padding: 5px 10px;
|
||||
background: ${browserType === 'chrome' ? '#28a745' : '#ffc107'};
|
||||
color: ${browserType === 'chrome' ? 'white' : 'black'};
|
||||
padding: 8px 12px;
|
||||
border-radius: 4px;
|
||||
font-size: 12px;
|
||||
z-index: 9999;
|
||||
box-shadow: 0 2px 4px rgba(0,0,0,0.2);
|
||||
max-width: 250px;
|
||||
`;
|
||||
statusIndicator.textContent = '🖨️ Print Extension Active';
|
||||
|
||||
if (browserType === 'chrome') {
|
||||
statusIndicator.textContent = '🖨️ Print Extension Active (Direct Print Available)';
|
||||
} else {
|
||||
statusIndicator.innerHTML = `🖨️ Print Extension Active<br><small>${browserType.toUpperCase()} - Browser Print Mode</small>`;
|
||||
}
|
||||
|
||||
document.body.appendChild(statusIndicator);
|
||||
|
||||
// Hide after 3 seconds
|
||||
// Hide after 4 seconds (longer for non-Chrome browsers)
|
||||
setTimeout(() => {
|
||||
statusIndicator.style.opacity = '0';
|
||||
statusIndicator.style.transition = 'opacity 0.5s';
|
||||
setTimeout(() => statusIndicator.remove(), 500);
|
||||
}, 3000);
|
||||
}, browserType === 'chrome' ? 3000 : 5000);
|
||||
}
|
||||
|
||||
// Detect browser type
|
||||
function getBrowserType() {
|
||||
const userAgent = navigator.userAgent.toLowerCase();
|
||||
if (userAgent.includes('edg/')) return 'edge';
|
||||
if (userAgent.includes('brave')) return 'brave';
|
||||
if (userAgent.includes('chrome') && !userAgent.includes('edg/')) return 'chrome';
|
||||
return 'chromium';
|
||||
}
|
||||
|
||||
function overridePrintButton() {
|
||||
@@ -71,9 +89,15 @@ function overridePrintButton() {
|
||||
// Add new event listener for extension printing
|
||||
newPrintButton.addEventListener('click', handleExtensionPrint);
|
||||
|
||||
// Update button text to indicate direct printing
|
||||
newPrintButton.innerHTML = '🖨️ Print Direct';
|
||||
newPrintButton.title = 'Print directly to default printer (Chrome Extension)';
|
||||
// Update button text based on browser capabilities
|
||||
const browserType = getBrowserType();
|
||||
if (browserType === 'chrome') {
|
||||
newPrintButton.innerHTML = '🖨️ Print Direct';
|
||||
newPrintButton.title = 'Print directly to default printer (Chrome Extension)';
|
||||
} else {
|
||||
newPrintButton.innerHTML = '🖨️ Print Enhanced';
|
||||
newPrintButton.title = `Enhanced printing for ${browserType.toUpperCase()} browser - Opens optimized print dialog`;
|
||||
}
|
||||
|
||||
console.log('Print button override complete');
|
||||
} else {
|
||||
@@ -103,12 +127,16 @@ function handleExtensionPrint(event) {
|
||||
// Create complete HTML for printing
|
||||
const printHTML = createPrintableHTML(labelPreview);
|
||||
|
||||
// Get selected printer from dropdown
|
||||
const selectedPrinterId = window.getSelectedPrinter ? window.getSelectedPrinter() : 'default';
|
||||
|
||||
// Try direct printing first, then fallback
|
||||
chrome.runtime.sendMessage({
|
||||
action: 'print_label',
|
||||
data: {
|
||||
html: printHTML,
|
||||
timestamp: Date.now()
|
||||
timestamp: Date.now(),
|
||||
printerId: selectedPrinterId
|
||||
}
|
||||
}, (response) => {
|
||||
if (response && response.success) {
|
||||
@@ -122,7 +150,8 @@ function handleExtensionPrint(event) {
|
||||
action: 'fallback_print',
|
||||
data: {
|
||||
html: printHTML,
|
||||
timestamp: Date.now()
|
||||
timestamp: Date.now(),
|
||||
printerId: selectedPrinterId
|
||||
}
|
||||
}, handlePrintResponse);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user