document.addEventListener("DOMContentLoaded", function () {
fetch("/static/components/navbar.html")
.then(response => response.text())
.then(data => {
document.getElementById("navbar-container").innerHTML = data;
})
.catch(error => console.error("Error loading the navbar:", error));
});
async function searchWord() {
let word = document.getElementById("wordInput").value.trim();
let resultDiv = document.getElementById("result");
if (word === "") {
resultDiv.innerHTML = "
â Please enter a word!
";
return;
}
let url = `https://api.dictionaryapi.dev/api/v2/entries/en/${word}`;
try {
let response = await fetch(url);
let data = await response.json();
if (data.title) {
resultDiv.innerHTML = `
â Word not found!
`;
} else {
let definition = data[0].meanings[0]?.definitions[0]?.definition || "No definition found.";
let phonetics = data[0].phonetics[0]?.text || "No phonetics available.";
let audio = data[0].phonetics[0]?.audio || "";
resultDiv.innerHTML = `
";
}
}
function handleKeyPress0(event){
if (event.key === "Enter") {
searchWord();
}
}
const YOUTUBE_API_KEY = "AIzaSyBnWZp2Bc_lv1duMO0r3D4THx5tBhISeXg"; // Replace with your actual API Key
function fetchContent() {
let query = document.getElementById("searchQuery").value;
if (!query) {
alert("Please enter a topic.");
return;
}
// Wikipedia API
$("#wikiContent").html("Loading...");
$.getJSON(`https://en.wikipedia.org/api/rest_v1/page/summary/${query}`, function(data) {
$("#wikiContent").html(data.extract ? data.extract : "No summary available.");
}).fail(function() {
$("#wikiContent").html("Error fetching data.");
});
// JavaTpoint
$("#javatpointContent").html("Loading...");
let javaTpointLink = `https://www.javatpoint.com/${query.replace(/ /g, '-')}`;
$("#javatpointContent").html(`View on JavaTpoint`);
$("#mediumContent").html("Loading...");
let mediumLink = `https://medium.com/search?q=${query.replace(/ /g, '+')}`;
$("#mediumContent").html(`View on Medium`);
$("#quoraContent").html("Loading...");
let quoraLink = `https://www.quora.com/search?q=${query.replace(/ /g, '+')}`;
$("#quoraContent").html(`View on Quora`);
// YouTube API with SafeSearch and keyword filtering
$("#youtubeContent").html("Loading...");
$.getJSON(`https://www.googleapis.com/youtube/v3/search?part=snippet&q=${query} tutorial|lecture|course&type=video&maxResults=5&safeSearch=strict&key=${YOUTUBE_API_KEY}`, function(data) {
let videos = "";
data.items.forEach(item => {
let videoId = item.id.videoId;
let title = item.snippet.title;
let thumbnail = item.snippet.thumbnails.medium.url;
let videoUrl = `https://www.youtube.com/watch?v=${videoId}`;
videos += `