Spaces:
Sleeping
Sleeping
File size: 7,713 Bytes
eef4815 c7e8bf4 eef4815 3152818 eef4815 3152818 eef4815 28781df 0e9adc9 28781df eef4815 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
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 = "<p style='color: red;'>โ Please enter a word!</p>";
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 = `<p style="color: red;">โ Word not found!</p>`;
} 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 = `
<h2>${word}</h2>
<p><strong>Definition:</strong> ${definition}</p>
<p><strong>Phonetics:</strong> ${phonetics}</p>
${audio ? `<audio controls><source src="${audio}" type="audio/mpeg"></audio>` : ""}
`;
}
} catch (error) {
resultDiv.innerHTML = "<p style='color: red;'>โ ๏ธ Error fetching data. Please try again.</p>";
}
}
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(`<a href='${javaTpointLink}' target='_blank'>View on JavaTpoint</a>`);
$("#mediumContent").html("Loading...");
let mediumLink = `https://medium.com/search?q=${query.replace(/ /g, '+')}`;
$("#mediumContent").html(`<a href='${mediumLink}' target='_blank'>View on Medium</a>`);
$("#quoraContent").html("Loading...");
let quoraLink = `https://www.quora.com/search?q=${query.replace(/ /g, '+')}`;
$("#quoraContent").html(`<a href='${quoraLink}' target='_blank'>View on Quora</a>`);
// 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 += `
<div class="card mb-2">
<img src="${thumbnail}" alt="${title}" class="video-thumbnail" onclick="playVideo('${videoId}', this)">
<div class="card-body">
<p class="card-text">${title}</p>
<a href="${videoUrl}" target="_blank" class="btn btn-sm btn-danger">Open in YouTube</a>
</div>
</div>
`;
});
$("#youtubeContent").html(videos || "No videos found.");
}).fail(function() {
$("#youtubeContent").html("Error fetching videos.");
});
}
function handleKeyPress(event) {
if (event.key === "Enter") {
fetchContent();
}
}
function playVideo(videoId, element) {
let videoFrame = `<iframe width='100%' height='300' src='https://www.youtube.com/embed/${videoId}' frameborder='0' allowfullscreen></iframe>`;
let parentCard = element.closest(".card");
parentCard.innerHTML = videoFrame;
}
function searchBox() {
var query = document.getElementById("searchInput").value.toLowerCase();
var pages = {
"home": "index.html",
"ai": "ai.html",
"about": "about.html",
"contact": "contact.html",
"services": "services.html",
"library": "library.html"
};
if (query in pages) {
window.location.href = pages[query];
} else {
alert("Page not found. Try searching: Home, AI, About, Contact, Services, Library.");
}
return false; // Prevent form submission
}
let recognition;
let isListening = false;
let speechSynthesisUtterance;
let isSpeaking = false;
// ๐ค Speech-to-Text Function
function toggleSpeechRecognition() {
if (!recognition) {
recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
recognition.lang = "en-US";
recognition.interimResults = false;
recognition.maxAlternatives = 1;
recognition.onstart = function() {
document.getElementById("speak-btn").textContent = "๐ Stop";
};
recognition.onresult = function(event) {
let transcript = event.results[0][0].transcript;
document.getElementById("user-input").value = transcript;
};
recognition.onerror = function(event) {
console.error("Error:", event.error);
};
recognition.onend = function() {
document.getElementById("speak-btn").textContent = "๐ค Speak";
isListening = false;
};
}
if (isListening) {
recognition.stop();
} else {
recognition.start();
}
isListening = !isListening;
}
// ๐ Text-to-Speech Function
function toggleReadAloud(button, text) {
if (!isSpeaking) {
if ('speechSynthesis' in window) {
speechSynthesis.cancel();
speechSynthesisUtterance = new SpeechSynthesisUtterance(text);
speechSynthesisUtterance.lang = 'en-US';
speechSynthesisUtterance.rate = 1;
speechSynthesisUtterance.onstart = () => {
button.textContent = "โน๏ธ Stop";
};
speechSynthesisUtterance.onend = () => {
button.textContent = "๐ Read";
isSpeaking = false;
};
speechSynthesis.speak(speechSynthesisUtterance);
isSpeaking = true;
} else {
alert("Text-to-Speech is not supported in your browser.");
}
} else {
speechSynthesis.cancel();
button.textContent = "๐ Read";
isSpeaking = false;
}
}
// Library
// Function to load the footer dynamically
function loadFooter() {
fetch("/static/components/footer.html")
.then(response => response.text())
.then(data => {
document.getElementById("footer-container").innerHTML = data;
})
.catch(error => console.error("Error loading the footer:", error));
}
// Call the function after the page loads
document.addEventListener("DOMContentLoaded", loadFooter);
|