-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
56 lines (49 loc) · 2.23 KB
/
Copy pathscript.js
File metadata and controls
56 lines (49 loc) · 2.23 KB
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
// Update time and date
function updateTimeAndDate() {
const now = new Date();
const options = { hour12: false, hour: '2-digit', minute: '2-digit' };
const timeString = now.toLocaleString([], options);
const monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
const month = monthNames[now.getMonth()];
const day = now.getDate();
const year = now.getFullYear();
const dayOfWeek = now.toLocaleString([], { weekday: 'long' });
const dateString = `${dayOfWeek}, ${day} ${month} ${year}`;
document.getElementById('time').textContent = timeString;
document.getElementById('date').textContent = dateString;
}
// Update time and date every second
setInterval(updateTimeAndDate, 1000);
// Toggle search provider
const searchProvider = document.getElementById("searchProvider");
const searchProviders = ["Google", "Perplexity", "Exa.ai"];
let currentProviderIndex = 0;
searchProvider.addEventListener("click", () => {
currentProviderIndex = (currentProviderIndex + 1) % searchProviders.length;
searchProvider.textContent = searchProviders[currentProviderIndex];
});
// Define the handleSearchInput function first
function handleSearchInput(event) {
if (event.key === "Enter") {
const searchQuery = event.target.value.trim();
const searchProvider = document.getElementById("searchProvider").textContent;
if (searchQuery) {
let searchUrl;
if (searchProvider === "Google") {
searchUrl = `https://www.google.com/search?q=${encodeURIComponent(searchQuery)}`;
} else if (searchProvider === "Perplexity") {
searchUrl = `https://www.perplexity.ai/search?q=${encodeURIComponent(searchQuery)}`;
} else if (searchProvider === "Exa.ai") {
searchUrl = `https://www.exa.ai/search?q=${encodeURIComponent(searchQuery)}`;
}
if (searchUrl) {
window.open(searchUrl, "_blank");
}
}
}
}
// Attach the event listener for the search input once the DOM is fully loaded
document.addEventListener('DOMContentLoaded', function() {
const searchInput = document.getElementById('searchInput');
searchInput.addEventListener('keydown', handleSearchInput);
});