Skip to content

Commit

Permalink
Added SEO Analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
AsmitaMishra24 committed Aug 4, 2024
1 parent 4748ad5 commit 1a31947
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 0 deletions.
Binary file added SEO Analysis/icon128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added SEO Analysis/icon16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added SEO Analysis/icon48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions SEO Analysis/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SEO Analysis Tool</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<h1>SEO Analyzer</h1>
<input type="text" id="url-input" placeholder="Enter URL">
<button id="analyze-btn">Analyze</button>
<div id="results">
<h2>Results:</h2>
<p id="title-tag">Title Tag: <span></span></p>
<p id="meta-description">Meta Description: <span></span></p>
<p id="h1-tag">H1 Tag: <span></span></p>
<p id="word-count">Word Count: <span></span></p>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
22 changes: 22 additions & 0 deletions SEO Analysis/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"manifest_version": 3,
"name": "SEO Analyzer",
"version": "1.0",
"description": "A tool to analyze the SEO of a webpage.",
"permissions": [
"activeTab"
],
"action": {
"default_popup": "index.html",
"default_icon": {
"16": "icon16.png",
"48": "icon48.png",
"128": "icon128.png"
}
},
"icons": {
"16": "icon16.png",
"48": "icon48.png",
"128": "icon128.png"
}
}
43 changes: 43 additions & 0 deletions SEO Analysis/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
document.getElementById('analyze-btn').addEventListener('click', analyzeSEO);

async function analyzeSEO() {
const url = document.getElementById('url-input').value;
if (!url) {
alert('Please enter a URL');
return;
}

try {
const response = await fetch(`https://api.allorigins.win/get?url=${encodeURIComponent(url)}`);
if (!response.ok) {
throw new Error('Network response was not ok');
}

const rawResponse = await response.text();
console.log('Raw response:', rawResponse);

const data = JSON.parse(rawResponse);

const parser = new DOMParser();
const doc = parser.parseFromString(data.contents, 'text/html');

const title = doc.querySelector('title') ? doc.querySelector('title').innerText : 'No title found';

const metaDescription = doc.querySelector('meta[name="description"]')
? doc.querySelector('meta[name="description"]').getAttribute('content')
: 'No meta description found';

const h1 = doc.querySelector('h1') ? doc.querySelector('h1').innerText : 'No H1 tag found';

const wordCount = doc.body.innerText.split(/\s+/).filter(Boolean).length;

document.querySelector('#title-tag span').innerText = title;
document.querySelector('#meta-description span').innerText = metaDescription;
document.querySelector('#h1-tag span').innerText = h1;
document.querySelector('#word-count span').innerText = wordCount;

} catch (error) {
console.error('Error fetching or processing the URL:', error);
alert('Failed to fetch the URL or process the content. Please check the console for more details.');
}
}
32 changes: 32 additions & 0 deletions SEO Analysis/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #f0f0f0;
}

.container {
text-align: center;
background: #fff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

input, button {
padding: 10px;
margin: 5px;
font-size: 16px;
}

#results {
margin-top: 20px;
text-align: left;
}

#results h2 {
margin-bottom: 10px;
}

0 comments on commit 1a31947

Please sign in to comment.