Internal Link Analysis Tool

${diversity.toFixed(1)}%

Most Linked Page

${mostLinked}

`; // Main Table const dashboardTableBody = document.getElementById('dashboard-table-body'); dashboardTableBody.innerHTML = links.map(link => { const statusOk = link.status >= 200 && link.status < 300; const statusRedirect = link.status >= 300 && link.status < 400; const statusClass = statusOk ? 'bg-green-100 text-green-800' : statusRedirect ? 'bg-yellow-100 text-yellow-800' : 'bg-red-100 text-red-800'; const statusText = statusOk ? 'OK' : statusRedirect ? 'Redirect' : 'Broken'; return ` ${link.url} ${link.anchor} ${statusText} (${link.status}) `; }).join(''); // Charts const okCount = links.filter(l => l.status >= 200 && l.status < 300).length; const redirectCount = links.filter(l => l.status >= 300 && l.status < 400).length; const brokenCount = brokenLinks; if (statusChart) statusChart.destroy(); statusChart = new Chart(document.getElementById('status-chart').getContext('2d'), { type: 'doughnut', data: { labels: ['OK', 'Redirect', 'Broken'], datasets: [{ data: [okCount, redirectCount, brokenCount], backgroundColor: ['#34d399', '#fbbf24', '#f87171'] }] }, options: { responsive: true, plugins: { legend: { position: 'top' } } } }); const anchorCounts = links.reduce((acc, link) => { const anchor = link.anchor.toLowerCase(); acc[anchor] = (acc[anchor] || 0) + 1; return acc; }, {}); const topAnchors = Object.entries(anchorCounts).sort(([,a],[,b]) => b-a).slice(0, 5); if (anchorChart) anchorChart.destroy(); anchorChart = new Chart(document.getElementById('anchor-chart').getContext('2d'), { type: 'bar', data: { labels: topAnchors.map(a => a[0]), datasets: [{ label: 'Count', data: topAnchors.map(a => a[1]), backgroundColor: '#a78bfa' }] }, options: { indexAxis: 'y', plugins: { legend: { display: false } } } }); }; // --- EVENT HANDLERS --- const handleConfigChange = (e) => { const input = e.target; if (input.tagName !== 'INPUT') return; const id = parseInt(input.closest('tr').dataset.id); const field = input.dataset.field; const value = input.type === 'number' ? parseInt(input.value) || 0 : input.value; const link = links.find(l => l.id === id); if(link) link[field] = value; }; const handleAddLink = () => { const newId = links.length > 0 ? Math.max(...links.map(l => l.id)) + 1 : 1; links.push({ id: newId, url: "/new-page", anchor: "new link", status: 200 }); renderConfigTable(); }; const handleDeleteLink = (e) => { const btn = e.target.closest('.delete-btn'); if (btn) { const id = parseInt(btn.closest('tr').dataset.id); links = links.filter(l => l.id !== id); renderConfigTable(); } }; const generatePDF = () => { const pdfContent = document.getElementById('pdf-content'); html2canvas(pdfContent, { scale: 2, useCORS: true }).then(canvas => { const imgData = canvas.toDataURL('image/png'); const pdf = new jsPDF({ orientation: 'l', unit: 'mm', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(); const imgWidth = pdfWidth - 20; const imgHeight = (canvas.height * imgWidth) / canvas.width; pdf.setFontSize(22).setFont('helvetica', 'bold').text('Internal Link Analysis Report', pdfWidth / 2, 15, { align: 'center' }); pdf.addImage(imgData, 'PNG', 10, 25, imgWidth, imgHeight); pdf.save('internal-link-report.pdf'); }); }; // --- ATTACH LISTENERS --- prevBtn.addEventListener('click', () => showTab('dashboard')); nextBtn.addEventListener('click', () => showTab('config')); tabButtons.dashboard.addEventListener('click', () => showTab('dashboard')); tabButtons.config.addEventListener('click', () => showTab('config')); document.getElementById('add-link-btn').addEventListener('click', handleAddLink); document.getElementById('config-table-body').addEventListener('change', handleConfigChange); document.getElementById('config-table-body').addEventListener('click', handleDeleteLink); document.getElementById('download-pdf-btn').addEventListener('click', generatePDF); // --- INITIAL SETUP --- showTab('dashboard'); });
Scroll to Top