Skip to content

Commit

Permalink
Added Review Aggregator extension
Browse files Browse the repository at this point in the history
  • Loading branch information
sreevidya-16 authored Aug 3, 2024
1 parent ef92400 commit 2350527
Show file tree
Hide file tree
Showing 4 changed files with 203 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Review Aggregator/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Review Aggregator</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<h1>Review Aggregator</h1>
<input type="text" id="urlInput" placeholder="Enter URL">
<button id="fetchReviews">Fetch Reviews</button>
<div id="reviewsContainer"></div>
</div>
<script src="main.js"></script>
</body>
</html>
66 changes: 66 additions & 0 deletions Review Aggregator/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
document.getElementById('fetchReviews').addEventListener('click', function() {
const url = document.getElementById('urlInput').value;

if (url) {
fetchReviews(url).then(reviews => {
displayReviews(reviews);
}).catch(error => {
console.error('Error fetching reviews:', error);
alert('Failed to fetch reviews. Check the console for details.');
});
} else {
alert('Please enter a URL.');
}
});

async function fetchReviews(url) {
try {
// Construct the API request URL
const apiUrl = `https://api.example.com/reviews?url=${encodeURIComponent(url)}`;
console.log('Request URL:', apiUrl);

// Fetch data from the API
const response = await fetch(apiUrl);

// Log the response status and headers
console.log('Response Status:', response.status);
console.log('Response Headers:', response.headers);

if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}

// Parse the JSON response
const data = await response.json();
console.log('Response Data:', data);

// Check if the reviews array exists
if (!data.reviews || !Array.isArray(data.reviews)) {
throw new Error('Invalid response format');
}

return data.reviews;
} catch (error) {
console.error('Error fetching reviews:', error);
alert('Failed to fetch reviews. Check the console for details.');
throw error; // Re-throw to be caught by the calling function
}
}



function displayReviews(reviews) {
const container = document.getElementById('reviewsContainer');
container.innerHTML = '';

reviews.forEach(review => {
const reviewElement = document.createElement('div');
reviewElement.classList.add('review');
reviewElement.innerHTML = `
<h3>${review.title}</h3>
<p>${review.content}</p>
`;
container.appendChild(reviewElement);
});
}

33 changes: 33 additions & 0 deletions Review Aggregator/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"manifest_version": 3,
"name": "Review Aggregator",
"version": "1.0",
"description": "Aggregates and displays reviews from various sources.",
"permissions": [
"activeTab",
"storage"
],
"background": {
"service_worker": "background.js"
},
"action": {
"default_popup": "index.html",
"default_icon": {
"16": "icons/icon16.png",
"48": "icons/icon48.png",
"128": "icons/icon128.png"
}

},
"permissions": [
"activeTab",
"http://*/*",
"https://*/*"
],
"icons": {
"16": "icons/icon16.png",
"48": "icons/icon48.png",
"128": "icons/icon128.png"
}
}

86 changes: 86 additions & 0 deletions Review Aggregator/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
body {
font-family: Arial, sans-serif;
width: 100%;
max-width: 400px; /* Max width for larger screens */
margin: 0;
padding: 0;
}

.container {
padding: 20px;
}

h1 {
font-size: 1.5em; /* Responsive font size */
margin-bottom: 10px;
}

input, button {
width: 100%; /* Full width elements */
padding: 12px;
margin-bottom: 10px;
border-radius: 4px;
border: 1px solid #ccc;
}

input {
font-size: 1em;
}

button {
background-color: #007bff;
color: #fff;
border: none;
cursor: pointer;
font-size: 1em;
}

button:hover {
background-color: #0056b3;
}

#reviewsContainer {
margin-top: 10px;
}

.review {
border: 1px solid #ddd;
padding: 12px;
margin-bottom: 10px;
border-radius: 4px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.review h3 {
margin: 0;
font-size: 1.2em; /* Responsive font size */
}

.review p {
margin: 5px 0;
}

/* Responsive Design */

@media (max-width: 600px) {
.container {
padding: 10px;
}

h1 {
font-size: 1.2em; /* Slightly smaller font size on small screens */
}

input, button {
padding: 10px;
}

.review {
padding: 10px;
}

.review h3 {
font-size: 1em; /* Adjust font size on small screens */
}
}

0 comments on commit 2350527

Please sign in to comment.