`;
container.appendChild(card);
if (!isLast) {
const arrow = document.createElement('div');
arrow.className = 'text-center text-gray-400 font-bold text-2xl';
arrow.innerHTML = `↓`;
container.appendChild(arrow);
}
});
}
window.startCheck = () => {
validationMessage.classList.add('hidden');
const urlInput = document.getElementById('checkUrl');
const url = urlInput.value.trim();
try {
new URL(url);
} catch (_) {
validationMessage.textContent = 'Please enter a valid URL (e.g., https://example.com).';
validationMessage.classList.remove('hidden');
urlInput.classList.add('border-red-500', 'focus:border-red-500');
return;
}
urlInput.classList.remove('border-red-500', 'focus:border-red-500');
reportData = generateReportData(url);
changeTab(2);
simulateCheck();
};
window.downloadPDF = () => {
if (!reportData.url) {
alert('Please run a check first.');
return;
}
const { jsPDF } = window.jspdf;
const doc = new jsPDF({ orientation: 'p', unit: 'mm', format: 'a4' });
doc.setFontSize(22);
doc.setFont('helvetica', 'bold');
doc.text('Redirect Trace Report', 105, 20, { align: 'center' });
doc.setFontSize(11);
doc.text(`Initial URL: ${reportData.url}`, 105, 28, { align: 'center' });
const tableBody = reportData.chain.map(step => [step.url, `${step.status} ${step.statusText}`]);
doc.autoTable({
startY: 40,
theme: 'grid',
head: [['URL', 'Status Code']],
body: tableBody,
headStyles: { fillColor: [45, 55, 72] }, // slate-800
didParseCell: function(data) {
if (data.row.section === 'body') {
const status = parseInt(data.row.raw[1]);
if (status >= 400) data.cell.styles.textColor = [220, 38, 38];
if (status >= 300 && status < 400) data.cell.styles.textColor = [37, 99, 235];
if (status >= 200 && status < 300) data.cell.styles.textColor = [22, 163, 74];
}
}
});
doc.save(`Redirect_Report_${new URL(reportData.url).hostname}.pdf`);
};
// Initial setup
changeTab(1);
});
