-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
194 lines (171 loc) · 5.46 KB
/
script.js
File metadata and controls
194 lines (171 loc) · 5.46 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
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
// Temperature Functionality
navigator.geolocation.getCurrentPosition(success, error);
function success(position) {
const lat = position.coords.latitude;
const lon = position.coords.longitude;
fetch(`https://wttr.in/${lat},${lon}?format=j1`)
.then((res) => res.json())
.then((data) => {
const tempC = data.current_condition[0].temp_C;
const desc = data.current_condition[0].weatherDesc[0].value;
document.getElementById("temperature-degree").textContent = `${tempC}°C`;
const city = data.nearest_area[0].areaName[0].value;
document.getElementById("temperature-location").textContent = city;
})
.catch((err) => {
document.getElementById("temperature-degree").textContent = `--°C`;
document.getElementById(
"temperature-location"
).textContent = `Weather load failed.`;
});
}
function error() {
document.getElementById("temperature-degree").textContent = `--°C`;
document.getElementById(
"temperature-location"
).textContent = `Location not available.`;
}
// Clock Functionality
const time = document.getElementById("display-Time");
setInterval(() => {
const now = new Date();
let hours = now.getHours();
let minutes = now.getMinutes();
let seconds = now.getSeconds();
const formattedHours = [
hours < 10 ? "0" + hours : hours,
minutes < 10 ? "0" + minutes : minutes,
seconds < 10 ? "0" + seconds : seconds,
].join(":");
time.textContent = formattedHours;
});
// Random Quotes
const quoteElement = document.getElementById("display-Quotes");
const quotes = [
"Stay wild, moon child.",
"Dream big, work hard.",
"Create your own path.",
"Less talk, more action.",
"Be here now.",
"Live, love, laugh.",
"Do it with passion.",
"Make your own magic.",
"Be fearless in life.",
"Chase the impossible.",
"Start where you are.",
"Enjoy the little things.",
"Feel the fear, do it.",
"Let it be.",
"Choose joy today.",
"Believe in your dreams.",
"Live for the moment.",
"Make it count.",
"Work hard, stay humble.",
"Be the change.",
"Seek the unknown.",
"Never stop dreaming.",
"Stay curious, stay kind.",
"Keep moving forward.",
"Turn dreams into reality.",
"Laugh more, stress less.",
"Follow your own path.",
"Dare to be different.",
"You are enough.",
"Start today, not tomorrow.",
"Success is the journey.",
"Make today amazing.",
"Don’t stop believing.",
"Live without regrets.",
"The best is yet to come.",
"Embrace the chaos.",
"Be a light.",
"Take the risk.",
"Dream it, do it.",
"Stay true to yourself.",
"Create your own sunshine.",
"Take it one step.",
"Every moment counts.",
"Learn from yesterday.",
"Stay humble, hustle hard.",
"Life begins at the end.",
"Be brave, be bold.",
"Happiness is a choice.",
];
function getRandomQuotes() {
const randomIndex = Math.floor(Math.random() * quotes.length);
return quotes[randomIndex];
}
quoteElement.textContent = getRandomQuotes();
// Search Functionality
const searchForm = document.getElementById("search-bar");
const searchInput = document.getElementById("searchInput");
const dialogWrapper = document.getElementById("dialog-Wrapper");
searchForm.addEventListener("submit", function (event) {
event.preventDefault();
const query = searchInput.value.trim();
if (query) {
const urlPattern =
/^(https?:\/\/)?([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,6}(\/[^\s]*)?$/;
if (urlPattern.test(query)) {
window.location.href = query.startsWith("http")
? query
: "https://" + query;
} else {
const googleSearchUrl = `https://www.google.com/search?q=${encodeURIComponent(
query
)}`;
window.location.href = googleSearchUrl;
}
}
searchInput.value = "";
});
// Bookmark Functionality
const dialog = document.getElementById("bookmark-Form");
function openBookmarkForm() {
dialog.showModal();
}
function closeBookmarkForm() {
dialog.close();
}
dialog.addEventListener("click", (e) => {
if (!dialogWrapper.contains(e.target)) {
closeBookmarkForm();
}
});
// Save bookmark (URL only)
const form = document.getElementById("bookmark-submitForm");
form.addEventListener("submit", function (e) {
e.preventDefault();
let url = document.getElementById("bookmark-Name").value.trim();
if (!url.startsWith("http://") && !url.startsWith("https://")) {
url = "https://" + url;
}
const bookmarks = JSON.parse(localStorage.getItem("bookmarks")) || [];
bookmarks.push(url);
localStorage.setItem("bookmarks", JSON.stringify(bookmarks));
form.reset();
closeBookmarkForm();
renderBookmarks();
});
function renderBookmarks() {
const bookmarks = JSON.parse(localStorage.getItem("bookmarks")) || [];
const bookmarkList = document.getElementById("bookmark-List");
bookmarkList.innerHTML = ""; // Clear existing
bookmarks.forEach((url) => {
// const faviconUrl = "https://www.google.com/s2/favicons?domain=" + url;
const faviconUrl = "https://www.google.com/s2/favicons?sz=64&domain=" + url;
const anchor = document.createElement("a");
anchor.href = url;
anchor.target = "_blank";
anchor.className =
"h-12 sm:h-14 w-12 sm:w-14 bg-[#FAFAFA] rounded-2xl flex justify-center items-center border border-[#EEEEEE] p-2.5 sm:p-4";
const img = document.createElement("img");
img.src = faviconUrl;
img.alt = "Favicon";
img.className = "w-full h-full object-contain";
anchor.appendChild(img);
bookmarkList.appendChild(anchor);
});
}
// Initial render on page load
renderBookmarks();