Automated SKU Generator

Automated SKU Generator

Create unique and consistent SKUs based on product attributes.

Product Attributes

Generated SKU

Your generated SKU will appear here.

${skuEntry.sku}

`; }; const renderLogTable = () => { if (generatedSkus.length === 0) { configTableBody.innerHTML = `No SKUs generated yet.`; } else { configTableBody.innerHTML = [...generatedSkus].reverse().map(s => ` ${s.sku} ${s.productName} ${s.timestamp.toLocaleString()} `).join(''); } }; // --- UI & EVENT HANDLERS --- window.copyToClipboard = (text) => { const textarea = document.createElement('textarea'); textarea.value = text; document.body.appendChild(textarea); textarea.select(); document.execCommand('copy'); document.body.removeChild(textarea); }; const switchTab = (tabId) => { currentTab = tabId; Object.values(tabPanes).forEach(pane => pane.classList.add('hidden')); tabPanes[tabId].classList.remove('hidden'); Object.values(tabButtons).forEach(btn => btn.classList.replace('tab-active', 'tab-inactive')); tabButtons[tabId].classList.replace('tab-inactive', 'tab-active'); updateNavButtons(); }; const navigateTabs = (direction) => { const currentIndex = tabs.indexOf(currentTab); const newIndex = direction === 'next' ? currentIndex + 1 : currentIndex - 1; if (newIndex >= 0 && newIndex < tabs.length) switchTab(tabs[newIndex]); }; const updateNavButtons = () => { const currentIndex = tabs.indexOf(currentTab); prevBtn.disabled = currentIndex === 0; nextBtn.disabled = currentIndex === tabs.length - 1; prevBtn.classList.toggle('opacity-50', prevBtn.disabled); nextBtn.classList.toggle('opacity-50', nextBtn.disabled); }; const handlePdfDownload = () => { if(generatedSkus.length === 0) return; const pdfRenderContainer = document.getElementById('pdf-render-content'); let pdfHtml = `

Generated SKU Log

${generatedSkus.map(s => ``).join('')}
SKUProduct NameTimestamp
${s.sku}${s.productName}${s.timestamp.toLocaleString()}
`; pdfRenderContainer.innerHTML = pdfHtml; html2canvas(pdfRenderContainer, { scale: 2 }).then(canvas => { const imgData = canvas.toDataURL('image/png'); const { jsPDF } = window.jspdf; const pdf = new jsPDF({ orientation: 'portrait', unit: 'pt', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(), margin = 40; const contentWidth = pdfWidth - margin * 2; const pdfHeight = (canvas.height * contentWidth) / canvas.width; pdf.addImage(imgData, 'PNG', margin, margin, contentWidth, pdfHeight); pdf.save('SKU-Generator-Log.pdf'); }); }; const handleClearLog = () => { generatedSkus = []; renderLogTable(); resultsContainer.innerHTML = `

Your generated SKU will appear here.

`; downloadPdfBtn.disabled = true; }; // --- EVENT LISTENERS --- window.switchTab = switchTab; window.navigateTabs = navigateTabs; generateBtn.addEventListener('click', handleGeneration); downloadPdfBtn.addEventListener('click', handlePdfDownload); clearLogBtn.addEventListener('click', handleClearLog); // --- INITIALIZATION --- renderLogTable(); updateNavButtons(); switchTab('dashboard'); });
Scroll to Top