-
Notifications
You must be signed in to change notification settings - Fork 0
/
newtab.js
703 lines (607 loc) · 24.2 KB
/
newtab.js
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
document.addEventListener('DOMContentLoaded', () => {
const toggleButton = document.getElementById('dark-mode-toggle');
const currentTheme = localStorage.getItem('theme') || 'light';
document.body.classList.add(currentTheme + '-mode');
toggleButton.classList.toggle('dark', currentTheme === 'dark');
toggleButton.addEventListener('click', () => {
document.body.classList.toggle('light-mode');
document.body.classList.toggle('dark-mode');
const theme = document.body.classList.contains('dark-mode') ? 'dark' : 'light';
localStorage.setItem('theme', theme);
toggleButton.classList.toggle('dark', theme === 'dark');
});
});
document.addEventListener('DOMContentLoaded', () => {
const filterIcon = document.getElementById('filter-icon');
const newsFilters = document.getElementById('news-filters');
const newsSource = document.getElementById('news-source');
const applyNewsFiltersButton = document.getElementById('apply-news-filters');
// Show/hide source-specific options
newsSource.addEventListener('change', () => {
document.querySelectorAll('.source-options').forEach(el => el.style.display = 'none');
document.getElementById(`${newsSource.value}-options`).style.display = 'block';
});
// Show/hide filters
filterIcon.addEventListener('click', () => {
newsFilters.style.display = newsFilters.style.display === 'none' ? 'block' : 'none';
});
// Apply filters
applyNewsFiltersButton.addEventListener('click', async () => {
const source = newsSource.value;
let options = {};
switch(source) {
case 'hackernews':
options = {
storyType: document.getElementById('news-story-type').value,
limit: parseInt(document.getElementById('news-limit').value, 10)
};
break;
case 'googlenews':
options = {
category: document.getElementById('google-category').value
};
break;
case 'techcrunch':
options = {
category: document.getElementById('techcrunch-category').value
};
break;
}
try {
const articles = await fetchNews(source, options);
displayNews(articles);
newsFilters.style.display = 'none';
// Save preferences
chrome.storage.local.set({
selectedNewsSource: source,
newsOptions: options
});
} catch (error) {
document.getElementById('news').innerHTML = 'Failed to load news.';
}
});
// Load saved preferences and fetch news
chrome.storage.local.get(['selectedNewsSource', 'newsOptions'], function(result) {
const savedSource = result.selectedNewsSource || 'hackernews';
const savedOptions = result.newsOptions || { storyType: 'top', limit: 10 };
newsSource.value = savedSource;
newsSource.dispatchEvent(new Event('change'));
// Set saved options based on source
if (savedSource === 'hackernews') {
document.getElementById('news-story-type').value = savedOptions.storyType;
document.getElementById('news-limit').value = savedOptions.limit;
} else if (savedSource === 'googlenews') {
document.getElementById('google-category').value = savedOptions.category;
} else if (savedSource === 'techcrunch') {
document.getElementById('techcrunch-category').value = savedOptions.category;
}
// Fetch initial news
fetchNews(savedSource, savedOptions)
.then(displayNews)
.catch(error => {
document.getElementById('news').innerHTML = 'Failed to load news.';
});
});
});
document.addEventListener('DOMContentLoaded', () => {
const filterIcon = document.getElementById('product-hunt-filter-icon');
const productHuntFilters = document.getElementById('product-hunt-filters');
const applyProductHuntFiltersButton = document.getElementById('apply-product-hunt-filters');
const productHuntContainer = document.getElementById('product-hunt');
const productHuntHeading = document.querySelector('.product-hunt-column h2');
// Show or hide filters section on icon click
filterIcon.addEventListener('click', () => {
productHuntFilters.style.display = productHuntFilters.style.display === 'none' ? 'block' : 'none';
});
// Function to fetch Product Hunt launches based on user-selected filters
function fetchProductHuntLaunches(timeFrame, upvoteThreshold, showMedia) {
const apiKey = '-XJKPhHe0yzeKZhMCPfUBwfo6Mzlrjv6_vtNgxeMPFw'; // Replace with your Product Hunt API key
const baseQuery = `{
posts(first: 10, order: VOTES`;
let dateFilter = '';
const today = new Date();
switch (timeFrame) {
case 'daily':
dateFilter = `, postedAfter: "${new Date(today.setDate(today.getDate() - 1)).toISOString()}"`;
break;
case 'weekly':
dateFilter = `, postedAfter: "${new Date(today.setDate(today.getDate() - 7)).toISOString()}"`;
break;
case 'monthly':
dateFilter = `, postedAfter: "${new Date(today.setMonth(today.getMonth() - 1)).toISOString()}"`;
break;
case 'yearly':
dateFilter = `, postedAfter: "${new Date(today.setFullYear(today.getFullYear() - 1)).toISOString()}"`;
break;
case 'all-time':
default:
dateFilter = '';
break;
}
const query = `${baseQuery}${dateFilter}) {
edges {
node {
id
name
description
tagline
votesCount
url
thumbnail {
url
}
}
}
}}`;
fetch('https://api.producthunt.com/v2/api/graphql', {
method: 'POST',
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({ query })
})
.then(response => response.json())
.then(data => {
if (data.data && data.data.posts.edges.length > 0) {
const filteredPosts = data.data.posts.edges.filter(post => post.node.votesCount >= upvoteThreshold);
chrome.storage.local.set({
productHuntData: filteredPosts,
productHuntCacheTime: Date.now()
});
displayProductHuntLaunches(filteredPosts, showMedia);
} else {
productHuntContainer.innerText = 'No launches found.';
}
})
.catch(error => {
productHuntContainer.innerText = 'Failed to load Product Hunt launches.';
console.error('Error fetching launches:', error);
});
}
// Display Product Hunt launches based on user preferences
function displayProductHuntLaunches(posts, showMedia) {
productHuntContainer.innerHTML = '';
posts.forEach(post => {
const productItem = document.createElement('div');
productItem.classList.add('product-item');
productItem.innerHTML = `
${showMedia && post.node.thumbnail.url ? `<img src="${post.node.thumbnail.url}" alt="${post.node.name}" class="product-image">` : ''}
<div>
<h3>
<a href="${post.node.url}" target="_blank">${post.node.name}</a>
<span class="vote-count">
(${post.node.votesCount}
<span class="arrow">↑</span>)
</span>
<h4>${post.node.tagline}</h4>
<p>${post.node.description}</p>
</div>
`;
productHuntContainer.appendChild(productItem);
});
}
// Function to update the Product Hunt heading based on the time frame
function updateProductHuntHeading(timeFrame) {
let headingText = "Product Hunt Launches";
switch (timeFrame) {
case 'daily':
headingText = "Today's Launches";
break;
case 'weekly':
headingText = "This Week's Launches";
break;
case 'monthly':
headingText = "This Month's Launches";
break;
case 'yearly':
headingText = "This Year's Launches";
break;
case 'all-time':
headingText = "All Time Launches";
break;
}
// Update the heading text and reattach the settings icon
productHuntHeading.innerHTML = `${headingText} <span id="product-hunt-filter-icon" class="filter-icon">⚙️</span>`;
// Reattach the event listener for the newly inserted settings icon
document.getElementById('product-hunt-filter-icon').addEventListener('click', () => {
productHuntFilters.style.display = productHuntFilters.style.display === 'none' ? 'block' : 'none';
});
}
// Apply filters and fetch news based on user input
applyProductHuntFiltersButton.addEventListener('click', () => {
const timeFrame = document.getElementById('product-hunt-time-frame').value;
const upvoteThreshold = parseInt(document.getElementById('product-hunt-upvotes').value, 10) || 0;
const showMedia = document.getElementById('product-hunt-show-media').checked;
// Save user selections in local storage
chrome.storage.local.set({
selectedTimeFrame: timeFrame,
selectedUpvoteThreshold: upvoteThreshold,
selectedShowMedia: showMedia
});
// Update heading based on the selected time frame
updateProductHuntHeading(timeFrame);
// Fetch news with selected filters
fetchProductHuntLaunches(timeFrame, upvoteThreshold, showMedia);
// Hide filters after applying
productHuntFilters.style.display = 'none';
});
// Load saved user selections and apply filters on page load
chrome.storage.local.get(['selectedTimeFrame', 'selectedUpvoteThreshold', 'selectedShowMedia'], function(result) {
const savedTimeFrame = result.selectedTimeFrame || 'weekly';
const savedUpvoteThreshold = result.selectedUpvoteThreshold || 0;
const savedShowMedia = result.selectedShowMedia !== false;
// Set the time frame, upvote threshold, and media checkbox
document.getElementById('product-hunt-time-frame').value = savedTimeFrame;
document.getElementById('product-hunt-upvotes').value = savedUpvoteThreshold;
document.getElementById('product-hunt-show-media').checked = savedShowMedia;
// Update heading based on the saved time frame
updateProductHuntHeading(savedTimeFrame);
// Fetch news with saved filters
fetchProductHuntLaunches(savedTimeFrame, savedUpvoteThreshold, savedShowMedia);
});
});
document.addEventListener('DOMContentLoaded', () => {
const monthlyFilterIcon = document.getElementById('monthly-product-hunt-filter-icon');
const monthlyProductHuntFilters = document.getElementById('monthly-product-hunt-filters');
const applyMonthlyProductHuntFiltersButton = document.getElementById('apply-monthly-product-hunt-filters');
const monthlyProductHuntContainer = document.getElementById('monthly-product-hunt');
// Show or hide monthly filters section on icon click
monthlyFilterIcon.addEventListener('click', () => {
monthlyProductHuntFilters.style.display = monthlyProductHuntFilters.style.display === 'none' ? 'block' : 'none';
});
// Function to fetch monthly Product Hunt launches
function fetchMonthlyProductHuntLaunches(timeFrame, upvoteThreshold, showMedia) {
const apiKey = '-XJKPhHe0yzeKZhMCPfUBwfo6Mzlrjv6_vtNgxeMPFw'; // Use your API key
const today = new Date();
// Calculate the date range based on selected time frame
let dateFilter = '';
switch (timeFrame) {
case 'daily':
dateFilter = `, postedAfter: "${new Date(today.setDate(today.getDate() - 1)).toISOString()}"`;
break;
case 'weekly':
dateFilter = `, postedAfter: "${new Date(today.setDate(today.getDate() - 7)).toISOString()}"`;
break;
case 'monthly':
dateFilter = `, postedAfter: "${new Date(today.setMonth(today.getMonth() - 1)).toISOString()}"`;
break;
case 'yearly':
dateFilter = `, postedAfter: "${new Date(today.setFullYear(today.getFullYear() - 1)).toISOString()}"`;
break;
case 'all-time':
default:
dateFilter = '';
break;
}
const query = `{
posts(first: 10, order: VOTES${dateFilter}) {
edges {
node {
id
name
description
tagline
votesCount
url
thumbnail {
url
}
}
}
}
}`;
fetch('https://api.producthunt.com/v2/api/graphql', {
method: 'POST',
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({ query })
})
.then(response => response.json())
.then(data => {
if (data.data && data.data.posts.edges.length > 0) {
const filteredPosts = data.data.posts.edges.filter(post => post.node.votesCount >= upvoteThreshold);
displayMonthlyProductHuntLaunches(filteredPosts, showMedia);
} else {
monthlyProductHuntContainer.innerText = 'No monthly launches found.';
}
})
.catch(error => {
monthlyProductHuntContainer.innerText = 'Failed to load monthly launches.';
console.error('Error fetching monthly launches:', error);
});
}
// Function to display monthly Product Hunt launches
function displayMonthlyProductHuntLaunches(posts, showMedia) {
monthlyProductHuntContainer.innerHTML = '';
posts.forEach(post => {
const productItem = document.createElement('div');
productItem.classList.add('product-item');
productItem.innerHTML = `
${showMedia && post.node.thumbnail.url ? `<img src="${post.node.thumbnail.url}" alt="${post.node.name}" class="product-image">` : ''}
<div>
<h3>
<a href="${post.node.url}" target="_blank">${post.node.name}</a>
<span class="vote-count">
(${post.node.votesCount}
<span class="arrow">↑</span>)
</span>
</h3>
<h4>${post.node.tagline}</h4>
<p>${post.node.description}</p>
</div>
`;
monthlyProductHuntContainer.appendChild(productItem);
});
}
// Function to update the Monthly Product Hunt heading based on time frame
function updateMonthlyProductHuntHeading(timeFrame) {
let headingText = "Monthly Top Launches";
switch (timeFrame) {
case 'daily':
headingText = "Today's Launches";
break;
case 'weekly':
headingText = "This Week's Launches";
break;
case 'monthly':
headingText = "This Month's Launches";
break;
case 'yearly':
headingText = "This Year's Launches";
break;
case 'all-time':
headingText = "All Time Launches";
break;
}
// Update the heading text and reattach the settings icon
const monthlyProductHuntHeading = document.querySelector('.monthly-product-hunt-column h2');
monthlyProductHuntHeading.innerHTML = `${headingText} <span id="monthly-product-hunt-filter-icon" class="filter-icon">⚙️</span>`;
// Reattach the event listener for the filter icon
document.getElementById('monthly-product-hunt-filter-icon').addEventListener('click', () => {
monthlyProductHuntFilters.style.display = monthlyProductHuntFilters.style.display === 'none' ? 'block' : 'none';
});
}
// Apply monthly filters button click handler
applyMonthlyProductHuntFiltersButton.addEventListener('click', () => {
const timeFrame = document.getElementById('monthly-product-hunt-time-frame').value;
const upvoteThreshold = parseInt(document.getElementById('monthly-product-hunt-upvotes').value, 10) || 0;
const showMedia = document.getElementById('monthly-product-hunt-show-media').checked;
// Update heading based on the selected time frame
updateMonthlyProductHuntHeading(timeFrame);
// Save user selections in local storage
chrome.storage.local.set({
monthlySelectedTimeFrame: timeFrame,
monthlySelectedUpvoteThreshold: upvoteThreshold,
monthlySelectedShowMedia: showMedia
});
// Fetch monthly launches with selected filters
fetchMonthlyProductHuntLaunches(timeFrame, upvoteThreshold, showMedia);
// Hide filters after applying
monthlyProductHuntFilters.style.display = 'none';
});
// Load saved monthly user selections and apply filters on page load
chrome.storage.local.get(
['monthlySelectedTimeFrame', 'monthlySelectedUpvoteThreshold', 'monthlySelectedShowMedia'],
function(result) {
const savedTimeFrame = result.monthlySelectedTimeFrame || 'monthly'; // Default to monthly
const savedUpvoteThreshold = result.monthlySelectedUpvoteThreshold || 0;
const savedShowMedia = result.monthlySelectedShowMedia !== false;
// Set the saved values
document.getElementById('monthly-product-hunt-time-frame').value = savedTimeFrame;
document.getElementById('monthly-product-hunt-upvotes').value = savedUpvoteThreshold;
document.getElementById('monthly-product-hunt-show-media').checked = savedShowMedia;
// Update heading based on the saved time frame
updateMonthlyProductHuntHeading(savedTimeFrame);
// Fetch monthly launches with saved filters
fetchMonthlyProductHuntLaunches(savedTimeFrame, savedUpvoteThreshold, savedShowMedia);
}
);
});
// News fetching functions
async function fetchNews(source, options) {
const newsContainer = document.getElementById('news');
newsContainer.innerHTML = 'Loading news...';
try {
let articles;
switch(source) {
case 'hackernews':
articles = await fetchHackerNews(options.storyType, options.limit);
break;
case 'googlenews':
articles = await fetchGoogleNews(options.category);
break;
case 'techcrunch':
articles = await fetchTechCrunchNews(options.category);
break;
default:
throw new Error('Invalid news source');
}
return articles;
} catch (error) {
console.error('Error fetching news:', error);
newsContainer.innerHTML = `Error loading news: ${error.message}`;
throw error;
}
}
// Existing Hacker News function with slight modifications
async function fetchHackerNews(storyType = 'top', limit = 10) {
try {
const response = await fetch(`https://hacker-news.firebaseio.com/v0/${storyType}stories.json`);
const storyIds = await response.json();
const limitedStoryIds = storyIds.slice(0, limit);
const storyPromises = limitedStoryIds.map(id =>
fetch(`https://hacker-news.firebaseio.com/v0/item/${id}.json`)
.then(response => response.json())
);
const stories = await Promise.all(storyPromises);
return stories.map(story => ({
title: story.title,
url: story.url || `https://news.ycombinator.com/item?id=${story.id}`,
source: 'Hacker News',
publishedAt: story.time * 1000,
author: story.by,
score: story.score,
comments: story.descendants || 0
}));
} catch (error) {
console.error('Error fetching Hacker News:', error);
throw error;
}
}
async function fetchGoogleNews(category) {
try {
// Using RSS2JSON service to handle CORS and convert RSS to JSON
const rssToJsonApi = 'https://api.rss2json.com/v1/api.json';
const googleNewsRss = `https://news.google.com/rss/search?q=${category}&hl=en-US&gl=US&ceid=US:en`;
const response = await fetch(`${rssToJsonApi}?rss_url=${encodeURIComponent(googleNewsRss)}`);
const data = await response.json();
if (data.status !== 'ok') {
throw new Error('Failed to fetch Google News');
}
return data.items.slice(0, 10).map(item => ({
title: item.title,
url: item.link,
source: 'Google News',
publishedAt: new Date(item.pubDate).getTime(),
author: item.author || 'Google News',
description: item.description
}));
} catch (error) {
console.error('Error fetching Google News:', error);
throw error;
}
}
async function fetchTechCrunchNews(category = 'startups') {
try {
// Using RSS2JSON service (same as Google News)
const rssToJsonApi = 'https://api.rss2json.com/v1/api.json';
const techCrunchRss = `https://techcrunch.com/category/${category}/feed/`;
const response = await fetch(`${rssToJsonApi}?rss_url=${encodeURIComponent(techCrunchRss)}`);
const data = await response.json();
if (data.status !== 'ok') {
throw new Error('Failed to fetch TechCrunch news');
}
return data.items.slice(0, 10).map(item => ({
title: item.title,
url: item.link,
source: 'TechCrunch',
publishedAt: new Date(item.pubDate).getTime(),
author: item.author,
description: item.description.replace(/<[^>]*>/g, '').substring(0, 200) + '...',
image: item.thumbnail
}));
} catch (error) {
console.error('Error fetching TechCrunch news:', error);
throw error;
}
}
// Display news function
function displayNews(articles) {
const newsContainer = document.getElementById('news');
newsContainer.innerHTML = '';
if (!articles || articles.length === 0) {
newsContainer.innerHTML = 'No news articles found.';
return;
}
articles.forEach(article => {
if (!article.title || !article.url) return; // Skip invalid articles
const newsItem = document.createElement('div');
newsItem.classList.add('news-item');
const timeAgo = calculateTimeAgo(article.publishedAt);
// Clean up description if it exists (remove HTML tags)
const cleanDescription = article.description ?
article.description.replace(/<[^>]*>/g, '').substring(0, 200) + '...' : '';
newsItem.innerHTML = `
<div class="news-content">
<h3>
<a href="${article.url}" target="_blank" rel="noopener noreferrer">
${article.title}
</a>
</h3>
<div class="news-metadata">
${article.source ? `<span>${article.source}</span>` : ''}
${article.author ? `<span>by ${article.author}</span>` : ''}
<span>${timeAgo}</span>
${article.score ? `<span>${article.score} points</span>` : ''}
${article.comments ? `
<a href="https://news.ycombinator.com/item?id=${article.id}" target="_blank">
${article.comments} comments
</a>
` : ''}
</div>
${cleanDescription ? `<p class="description">${cleanDescription}</p>` : ''}
</div>
`;
newsContainer.appendChild(newsItem);
});
}
// Helper function to calculate time ago
function calculateTimeAgo(timestamp) {
const seconds = Math.floor((new Date() - timestamp) / 1000);
let interval = seconds / 31536000; // years
if (interval > 1) return Math.floor(interval) + ' years ago';
interval = seconds / 2592000; // months
if (interval > 1) return Math.floor(interval) + ' months ago';
interval = seconds / 86400; // days
if (interval > 1) return Math.floor(interval) + ' days ago';
interval = seconds / 3600; // hours
if (interval > 1) return Math.floor(interval) + ' hours ago';
interval = seconds / 60; // minutes
if (interval > 1) return Math.floor(interval) + ' minutes ago';
return Math.floor(seconds) + ' seconds ago';
}
async function fetchCombinedStartupNews() {
try {
// Fetch from multiple sources in parallel
const [hackerNews, techCrunch] = await Promise.all([
fetchHackerNews('top', 5),
fetchTechCrunchNews()
]);
// Combine and sort by date
const combined = [...hackerNews, ...techCrunch]
.sort((a, b) => b.publishedAt - a.publishedAt);
return combined.slice(0, 10); // Return top 10 most recent
} catch (error) {
console.error('Error fetching combined news:', error);
throw error;
}
}
// Time and date update function
function updateDateTime() {
const timeElement = document.getElementById('time');
const dateElement = document.getElementById('date');
if (!timeElement || !dateElement) {
console.error('Time or date element not found!');
return;
}
const now = new Date();
// Format time (HH:MM PM/AM)
timeElement.textContent = now.toLocaleTimeString('en-US', {
hour: '2-digit',
minute: '2-digit',
hour12: true
});
// Format date (Weekday, Month Day, Year)
dateElement.textContent = now.toLocaleDateString('en-US', {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric'
});
}
// Initialize immediately
updateDateTime();
// Then set up the interval
setInterval(updateDateTime, 1000);
// Also set up the DOMContentLoaded listener as a backup
document.addEventListener('DOMContentLoaded', () => {
updateDateTime();
});
// Hide social icons related code
/* document.addEventListener('DOMContentLoaded', () => {
const moreOptions = document.querySelector('.more-options');
// ... rest of social icons code
}); */