On-Page SEO Analyzer

On-Page SEO Analyzer

Analyze your content against key on-page SEO ranking factors.

Content for Analysis

SEO Analysis Report

Overall SEO Score

0

SEO Factor Checklist

Sustainable energy is crucial for our planet's future. This guide explores the various forms of green power. We must transition away from fossil fuels. One key aspect of sustainable energy is solar power, which harnesses the sun's radiation.

Solar panels on a roof

Another important area is wind power. Wind turbines are becoming more efficient. Investing in sustainable energy is not just an environmental choice, but an economic one. Learn more on our about page.

`; // --- TAB LOGIC --- let currentTabIndex = 0; const tabs = ['input', 'analysis']; function switchTab(idx) { currentTabIndex = idx; tabBtns.forEach((b, i) => { const tabName = b.dataset.tab; b.classList.toggle('active', tabs[i] === tabs[idx]); }); document.querySelectorAll('.tab-content').forEach(c => c.classList.remove('active')); document.getElementById(`${tabs[idx]}-content`).classList.add('active'); } analyzeBtn.addEventListener('click', () => { runAnalysis(); switchTab(1); }); // --- CORE LOGIC --- function runAnalysis() { const htmlString = contentHtmlInput.value; const keyword = targetKeywordInput.value.toLowerCase(); const parser = new DOMParser(); const doc = parser.parseFromString(htmlString, 'text/html'); const checks = {}; let totalScore = 0; // Plain text for density/length checks const textContent = doc.body.textContent || ""; const words = textContent.trim().split(/\s+/).filter(Boolean); const wordCount = words.length; // 1. Title Keyword const title = doc.querySelector('title')?.textContent.toLowerCase() || ""; checks.titleKeyword = { pass: title.includes(keyword) }; if (checks.titleKeyword.pass) totalScore += SEO_FACTORS.titleKeyword.weight; // 2. H1 Keyword const h1 = doc.querySelector('h1')?.textContent.toLowerCase() || ""; checks.h1Keyword = { pass: h1.includes(keyword) }; if (checks.h1Keyword.pass) totalScore += SEO_FACTORS.h1Keyword.weight; // 3. Content Length checks.contentLength = { pass: wordCount > 500, detail: `${wordCount} words` }; if (checks.contentLength.pass) totalScore += SEO_FACTORS.contentLength.weight; // 4. Keyword Density const keywordCount = (textContent.toLowerCase().match(new RegExp(keyword.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), 'g')) || []).length; const density = wordCount > 0 ? (keywordCount / wordCount) * 100 : 0; checks.keywordDensity = { pass: density >= 0.5 && density <= 2.0, detail: `${density.toFixed(2)}%` }; if (checks.keywordDensity.pass) totalScore += SEO_FACTORS.keywordDensity.weight; // 5. Meta Description const meta = doc.querySelector('meta[name="description"]')?.getAttribute('content') || ""; checks.metaDescription = { pass: meta.length > 0, detail: meta.length > 0 ? "Found" : "Missing" }; if (checks.metaDescription.pass) totalScore += SEO_FACTORS.metaDescription.weight; // 6. Internal Links const links = doc.querySelectorAll('a'); checks.internalLinks = { pass: links.length > 0, detail: `${links.length} found` }; if (checks.internalLinks.pass) totalScore += SEO_FACTORS.internalLinks.weight; // 7. Image Alts const images = doc.querySelectorAll('img'); const imagesWithAlts = Array.from(images).filter(img => img.alt && img.alt.trim() !== "").length; checks.imageAlts = { pass: images.length === 0 || imagesWithAlts === images.length, detail: `${imagesWithAlts}/${images.length} with alts` }; if (checks.imageAlts.pass) totalScore += SEO_FACTORS.imageAlts.weight; analysisResults = { score: totalScore, checks, keyword: targetKeywordInput.value, url: contentUrlInput.value }; renderAnalysis(); } // --- UI RENDERING --- function renderAnalysis() { const scoreEl = document.getElementById('seo-score'); const scoreBar = document.getElementById('score-bar'); const checklistContainer = document.getElementById('checklist-container'); scoreEl.textContent = analysisResults.score; scoreBar.style.width = `${analysisResults.score}%`; let scoreColor = 'bg-red-500'; if (analysisResults.score > 75) scoreColor = 'bg-green-500'; else if (analysisResults.score > 40) scoreColor = 'bg-yellow-500'; scoreBar.className = `h-4 rounded-full transition-all duration-500 ${scoreColor}`; checklistContainer.innerHTML = Object.entries(analysisResults.checks).map(([key, result]) => { const icon = result.pass ? `` : ``; return `
${icon} ${SEO_FACTORS[key].label} ${result.detail || (result.pass ? 'Pass' : 'Fail')}
`; }).join(''); } // --- PDF GENERATION --- async function generatePdfReport() { downloadPdfBtn.disabled = true; downloadPdfBtn.textContent = 'Generating...'; const scoreColor = analysisResults.score > 75 ? '#16a34a' : (analysisResults.score > 40 ? '#f59e0b' : '#dc2626'); const checklistHtml = Object.entries(analysisResults.checks).map(([key, result]) => `
${result.pass ? '✔' : '✖'} ${SEO_FACTORS[key].label} ${result.detail || (result.pass ? 'Pass' : 'Fail')}
`).join(''); const reportHtml = `

On-Page SEO Audit

For Keyword: "${analysisResults.keyword}"

${analysisResults.score}
/ 100

${analysisResults.url || 'No URL provided'}

SEO Checklist${new Date().toLocaleDateString()}
${checklistHtml}
`; const pdfTemplate = document.getElementById('pdf-template'); pdfTemplate.innerHTML = reportHtml; pdfTemplate.classList.remove('invisible'); try { const { jsPDF } = window.jspdf; const pdf = new jsPDF({ orientation: 'p', unit: 'pt', format: 'a4' }); const pages = pdfTemplate.querySelectorAll('.pdf-page'); for (let i = 0; i < pages.length; i++) { const canvas = await html2canvas(pages[i], { scale: 2 }); if (i > 0) pdf.addPage(); const imgData = canvas.toDataURL('image/png'); const pdfWidth = pdf.internal.pageSize.getWidth(), pdfHeight = (canvas.height * pdfWidth) / canvas.width; pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, pdfHeight); } pdf.save(`SEO_Report_${analysisResults.keyword.replace(/\s+/g, '_')}.pdf`); } catch (e) { console.error('PDF Generation Error:', e); } finally { downloadPdfBtn.disabled = false; downloadPdfBtn.textContent = 'Download PDF'; pdfTemplate.classList.add('invisible'); pdfTemplate.innerHTML = ''; } } // --- EVENT LISTENERS --- downloadPdfBtn.addEventListener('click', generatePdfReport); // --- INITIALIZATION --- switchTab(0); });
Scroll to Top