Post Scheduler Generator (template-based)

Post Scheduler Generator

Your generated post schedule. Configure details in the 'Configuration' tab and click 'Generate & View Schedule'.

Platforms

Please select a valid start date.

'; return; } const durationWeeks = parseInt(durationInput.value, 10) || 1; const platforms = Array.from(document.querySelectorAll('.psg-platform:checked')).map(cb => cb.value); const templates = Array.from(document.querySelectorAll('.psg-template-item')).map(item => ({ name: item.querySelector('.psg-template-name').value.trim() || 'Untitled', color: item.querySelector('.psg-template-color').value })).filter(t => t.name !== 'Untitled'); if (platforms.length === 0 || templates.length === 0) { scheduleOutput.innerHTML = '

Please select at least one platform and add at least one post template.

'; return; } let schedule = []; let postCounter = 0; const days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']; for (let week = 0; week < durationWeeks; week++) { for (let day = 0; day < 7; day++) { const currentDate = new Date(startDate); currentDate.setDate(startDate.getDate() + (week * 7) + day); const dateString = currentDate.toLocaleDateString('en-CA'); // YYYY-MM-DD const dayOfWeek = days[currentDate.getDay()]; platforms.forEach(platform => { const template = templates[postCounter % templates.length]; schedule.push({ date: dateString, day: dayOfWeek, platform: platform, template: template }); postCounter++; }); } } let tableHTML = ` ${schedule.map(post => ` `).join('')}
Date Day Platform Post Template/Topic
${post.date} ${post.day} ${post.platform} ${post.template.name}
`; scheduleOutput.innerHTML = tableHTML; } async function downloadPDF() { if (!scheduleOutput.querySelector('table')) { alert("Please generate a schedule before downloading."); return; } const { jsPDF } = window.jspdf; const pdf = new jsPDF('l', 'pt', 'a4'); // landscape pdfButton.innerText = 'Generating...'; pdfButton.disabled = true; try { const canvas = await html2canvas(scheduleOutput.querySelector('table'), { scale: 2 }); const imgData = canvas.toDataURL('image/png'); const imgProps= pdf.getImageProperties(imgData); const pdfWidth = pdf.internal.pageSize.getWidth() - 40; const pdfHeight = (imgProps.height * pdfWidth) / imgProps.width; pdf.text("Social Media Post Schedule", 20, 30); pdf.addImage(imgData, 'PNG', 20, 50, pdfWidth, pdfHeight); pdf.save('post_schedule.pdf'); } catch (error) { console.error("PSG TOOL: PDF Generation Error - ", error); alert("An error occurred while generating the PDF."); } finally { pdfButton.innerText = 'Download Schedule (PDF)'; pdfButton.disabled = false; } } // --- Event Listeners --- addTemplateButton.addEventListener('click', () => addTemplate()); nextButton.addEventListener('click', () => { if (currentTabIndex === 0) psg_showTab(1); }); prevButton.addEventListener('click', () => { if (currentTabIndex === 1) { generateSchedule(); psg_showTab(0); } }); pdfButton.addEventListener('click', downloadPDF); // --- Initial Setup --- startDateInput.valueAsDate = new Date(); addTemplate('Educational Post', '#a2d2ff'); addTemplate('Company News / Update', '#ffb703'); addTemplate('Behind the Scenes', '#d4edda'); addTemplate('Testimonial / Case Study', '#bde0fe'); generateSchedule(); }); window.psg_openTab = function(evt, tabName) { const tabs = ['psg-tab-dashboard', 'psg-tab-config']; const newIndex = tabs.indexOf(tabName); if (newIndex === -1) return; const currentTabIndex = Array.from(document.querySelectorAll('.psg-tab-button')).findIndex(btn => btn.classList.contains('psg-active')); if (newIndex > currentTabIndex) { document.getElementById('psg-next-button').click(); } else if (newIndex < currentTabIndex) { document.getElementById('psg-prev-button').click(); } }; })();
Scroll to Top