-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
441 additions
and
2 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
Vanilla-JS-Projects/Intermediate/Wikipedia-Clone/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<h1 align='center'><b>💥 Wikipedia Clone 💥</b></h1> | ||
|
||
<!-- -------------------------------------------------------------------------------------------------------------- --> | ||
|
||
<h3 align='center'>Tech Stack Used 🎮</h3> | ||
|
||
<div align='center'> | ||
|
||
![HTML5](https://img.shields.io/badge/html5-%23E34F26.svg?style=for-the-badge&logo=html5&logoColor=white) | ||
![CSS3](https://img.shields.io/badge/css3-%231572B6.svg?style=for-the-badge&logo=css3&logoColor=white) | ||
![JavaScript](https://img.shields.io/badge/javascript-%23323330.svg?style=for-the-badge&logo=javascript&logoColor=%23F7DF1E) | ||
</div> | ||
|
||
|
||
![Line](https://github.com/Avdhesh-Varshney/WebMasterLog/assets/114330097/4b78510f-a941-45f8-a9d5-80ed0705e847) | ||
|
||
<!-- -------------------------------------------------------------------------------------------------------------- --> | ||
|
||
## :zap: Description 📃 | ||
|
||
<div> | ||
<p>Wikipedia clone is a web platform that mimics Wikipedia’s functionality, allowing users to create, edit, and manage articles /p> | ||
</div> | ||
|
||
<!-- -------------------------------------------------------------------------------------------------------------- --> | ||
|
||
## :zap: How to run it? 🕹️ | ||
|
||
<div > | ||
<p>To run this project locally, follow these steps: | ||
|
||
1. Fork the repository. | ||
|
||
2. Clone the repository to your local computer | ||
|
||
3. Open the project folder in your preferred code editor, now you can view website in live. | ||
|
||
</p> | ||
</div> | ||
|
||
<!-- -------------------------------------------------------------------------------------------------------------- --> | ||
|
||
## :zap: Screenshots 📸 | ||
<!-- add the screenshot of the project (Mandatory) --> | ||
|
||
![image](screenshot.webp) | ||
|
||
|
||
![Line](https://github.com/Avdhesh-Varshney/WebMasterLog/assets/114330097/4b78510f-a941-45f8-a9d5-80ed0705e847) | ||
|
||
<!-- -------------------------------------------------------------------------------------------------------------- --> | ||
|
||
<h4 align='center'>Developed By <b><i>Aman Verma</i></b></h4> | ||
<p align='center'> | ||
<a href='https://www.linkedin.com/in/aman-verma-47b626294/'> | ||
<img src='https://img.shields.io/badge/linkedin-%230077B5.svg?style=for-the-badge&logo=linkedin&logoColor=white' /> | ||
</a> | ||
<a href='https://github.com/amanver45'> | ||
<img src='https://img.shields.io/badge/github-%23121011.svg?style=for-the-badge&logo=github&logoColor=white' /> | ||
</a> | ||
</p> | ||
|
||
<h4 align='center'>Happy Coding 🧑💻</h4> | ||
|
||
<h3 align="center">Show some ❤️ by 🌟 this repository!</h3> |
25 changes: 25 additions & 0 deletions
25
Vanilla-JS-Projects/Intermediate/Wikipedia-Clone/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Wiki Clone</title> | ||
<link rel="stylesheet" href="style.css" /> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<div class="header-container"> | ||
<h1>Search Wikipedia</h1> | ||
<span id="theme-toggler">Light</span> | ||
</div> | ||
|
||
<form id="search-form"> | ||
<input type="text" id="search-input" placeholder="Enter search term" /> | ||
<button type="submit">Search</button> | ||
</form> | ||
|
||
<div id="search-results"></div> | ||
</div> | ||
|
||
<script src="script.js"></script> | ||
</body> | ||
</html> |
Binary file not shown.
82 changes: 82 additions & 0 deletions
82
Vanilla-JS-Projects/Intermediate/Wikipedia-Clone/script.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
const searchForm = document.getElementById("search-form"); | ||
const searchInput = document.getElementById("search-input"); | ||
const searchResults = document.getElementById("search-results"); | ||
|
||
// Theme toggler elements | ||
const themeToggler = document.getElementById("theme-toggler"); | ||
const body = document.body; | ||
|
||
async function searchWikipeida(query) { | ||
const encodedQuery = encodeURIComponent(query); | ||
const endpoint = `https://en.wikipedia.org/w/api.php?action=query&list=search&prop=info&inprop=url&utf8=&format=json&origin=*&srlimit=10&srsearch=${encodedQuery}`; | ||
|
||
const reponse = await fetch(endpoint); | ||
|
||
if (!reponse.ok) { | ||
throw new Error("Faild to fetch search results form wikipedia API."); | ||
} | ||
|
||
const json = await reponse.json(); | ||
return json; | ||
} | ||
|
||
function displayResults(results) { | ||
// Remove the loading spinner | ||
searchResults.innerHTML = ""; | ||
|
||
results.forEach((result) => { | ||
const url = `https://en.wikipedia.org/?curid=${results.pageid}`; | ||
const titleLink = `<a href="${url}" target="_blank" rel="noopener">${result.title} </a>`; | ||
const urlLink = `<a href="${url} class="result-link" target="_blank" rel="noopener">${url}</a>`; | ||
|
||
const resultItme = document.createElement("div"); | ||
resultItme.className = "result-item"; | ||
resultItme.innerHTML = ` | ||
<h3 class="result-title">${titleLink}</h3> | ||
${urlLink} | ||
<p class="result-snippet">${result.snippet}</p> | ||
`; | ||
|
||
searchResults.appendChild(resultItme); | ||
}); | ||
} | ||
|
||
searchForm.addEventListener("submit", async (e) => { | ||
e.preventDefault(); | ||
|
||
const query = searchInput.value.trim(); | ||
|
||
if (!query) { | ||
searchResults.innerHTML = "<p>Please enter a valid search term. </p>"; | ||
return; | ||
} | ||
|
||
searchResults.innerHTML = "<div class='spinner'>Loading ... </div>"; | ||
|
||
try { | ||
const results = await searchWikipeida(query); | ||
|
||
if (results.query.searchinfo.totalhits === 0) { | ||
searchResults.innerHTML = "<p>No results found. </p>"; | ||
} else { | ||
displayResults(results.query.search); | ||
} | ||
} catch (error) { | ||
console.error(error); | ||
searchResults.innerHTML = `<p>An error occured while searching. Please try again later. </p>`; | ||
} | ||
}); | ||
|
||
// Event listener for the theme toggler | ||
themeToggler.addEventListener("click", () => { | ||
body.classList.toggle("dark-theme"); | ||
if (body.classList.contains("dark-theme")) { | ||
themeToggler.textContent = "Dark"; | ||
themeToggler.style.background = "#fff"; | ||
themeToggler.style.color = "#333"; | ||
} else { | ||
themeToggler.textContent = "Light"; | ||
themeToggler.style.border = "2px solid #ccc"; | ||
themeToggler.style.color = "#333"; | ||
} | ||
}); |
Oops, something went wrong.