Spaces:
Running
Running
File size: 7,298 Bytes
411e06d 0d9e6d1 09b0ba5 0d9e6d1 44ae114 0d9e6d1 44ae114 0d9e6d1 44ae114 0d9e6d1 44ae114 0d9e6d1 44ae114 0d9e6d1 44ae114 0d9e6d1 621a8a0 0d9e6d1 621a8a0 0d9e6d1 44ae114 0d9e6d1 621a8a0 | 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 | document.addEventListener('DOMContentLoaded', () => {
// --- DOM ---
const clockEl = document.getElementById('clock');
const dateEl = document.getElementById('date');
const greetingEl = document.getElementById('greeting');
const searchForm = document.getElementById('search-form');
const searchInput = document.getElementById('search-input');
const searchEngine = document.getElementById('search-engine');
const themeToggle = document.getElementById('theme-toggle');
const notesToggle = document.getElementById('notes-toggle'); // optional in your HTML
const notesPanel = document.getElementById('notes-panel'); // optional
const cardGrid = document.getElementById('card-grid');
// --- HARD-CODED CATEGORIES/LINKS (edit these arrays to taste) ---
const CATEGORIES = [
{
id: 'reddit',
name: 'Reddit',
icon: 'fa-brands fa-reddit',
links: [
{ name: 'r/EmulationOnAndroid', url: 'https://www.reddit.com/r/emulationonandroid/', icon: 'fa-solid fa-gamepad' },
{ name: 'r/Singularity', url: 'https://www.reddit.com/r/singularity/', icon: 'fa-solid fa-robot' },
{ name: 'r/OpenAI', url: 'https://www.reddit.com/r/openai/', icon: 'fa-solid fa-brain' },
{ name: 'r/Programming', url: 'https://www.reddit.com/r/programming/', icon: 'fa-solid fa-code' },
{ name: 'r/MLB', url: 'https://www.reddit.com/r/MLB/', icon: 'fa-solid fa-baseball' },
{ name: 'r/DataIsBeautiful', url: 'https://www.reddit.com/r/dataisbeautiful/', icon: 'fa-solid fa-chart-simple' }
]
},
{
id: 'news',
name: 'News & Tech',
icon: 'fa-solid fa-newspaper',
links: [
{ name: 'Hacker News', url: 'https://news.ycombinator.com/', icon: 'fa-brands fa-hacker-news' },
{ name: 'TechCrunch', url: 'https://techcrunch.com/', icon: 'fa-solid fa-microchip' },
{ name: 'The Verge', url: 'https://www.theverge.com/', icon: 'fa-solid fa-bolt' },
{ name: 'Ars Technica', url: 'https://arstechnica.com/', icon: 'fa-solid fa-flask' },
{ name: 'Reuters', url: 'https://www.reuters.com/', icon: 'fa-solid fa-globe' },
{ name: 'AP News', url: 'https://apnews.com/', icon: 'fa-solid fa-circle-info' },
{ name: 'BBC', url: 'https://www.bbc.com/news', icon: 'fa-solid fa-earth-europe' }
]
},
{
id: 'streaming',
name: 'Streaming',
icon: 'fa-solid fa-clapperboard',
links: [
{ name: 'YouTube', url: 'https://www.youtube.com/', icon: 'fa-brands fa-youtube' },
{ name: 'Netflix', url: 'https://www.netflix.com/', icon: 'fa-brands fa-n' }, // FA6 has brand 'n' via kit/alias; if it doesn’t show, swap to fa-tv
{ name: 'Hulu', url: 'https://www.hulu.com/', icon: 'fa-solid fa-film' },
{ name: 'Prime Video', url: 'https://www.primevideo.com/', icon: 'fa-brands fa-amazon' },
{ name: 'Disney+', url: 'https://www.disneyplus.com/', icon: 'fa-solid fa-star' },
{ name: 'Max', url: 'https://www.max.com/', icon: 'fa-solid fa-video' },
{ name: 'Crunchyroll', url: 'https://www.crunchyroll.com/', icon: 'fa-brands fa-critical-role' } // fallback brand icon
]
}
];
// --- SEARCH ENGINES (+ optional HF Space variable DEFAULT_ENGINE) ---
const SEARCH_ENGINES = {
google: 'https://www.google.com/search?q=',
duckduckgo: 'https://duckduckgo.com/?q=',
youtube: 'https://www.youtube.com/results?search_query=',
github: 'https://github.com/search?q='
};
if (window.huggingface?.variables?.DEFAULT_ENGINE &&
SEARCH_ENGINES[window.huggingface.variables.DEFAULT_ENGINE]) {
if (searchEngine) searchEngine.value = window.huggingface.variables.DEFAULT_ENGINE;
}
// --- RENDER ---
function renderCards() {
if (!cardGrid) return;
cardGrid.innerHTML = '';
CATEGORIES.forEach(cat => cardGrid.appendChild(createCard(cat)));
}
function createCard(category) {
const card = document.createElement('div');
card.className = 'card';
card.dataset.categoryId = category.id;
// Links list
const linksHtml = category.links.map(link => `
<li>
<a href="${link.url}" target="_blank" rel="noopener noreferrer">
<i class="${link.icon || 'fa-solid fa-link'}"></i> ${link.name}
</a>
</li>
`).join('');
card.innerHTML = `
<div class="card-header">
<h2><i class="${category.icon || 'fa-solid fa-folder'}"></i> ${category.name}</h2>
</div>
<ul>${linksHtml}</ul>
`;
return card;
}
// --- SEARCH ---
if (searchForm) {
searchForm.addEventListener('submit', (e) => {
e.preventDefault();
const q = (searchInput?.value || '').trim();
if (!q) return;
const engine = searchEngine?.value || 'google';
window.open(SEARCH_ENGINES[engine] + encodeURIComponent(q), '_blank', 'noopener');
if (searchInput) searchInput.value = '';
});
}
// --- THEME ---
if (themeToggle) {
themeToggle.addEventListener('click', () => {
document.body.classList.toggle('light-theme');
const isLight = document.body.classList.contains('light-theme');
localStorage.setItem('theme', isLight ? 'light' : 'dark');
themeToggle.innerHTML = isLight ? '<i class="fa-solid fa-sun"></i>' : '<i class="fa-solid fa-moon"></i>';
});
const savedTheme = localStorage.getItem('theme');
if (savedTheme === 'light') {
document.body.classList.add('light-theme');
themeToggle.innerHTML = '<i class="fa-solid fa-sun"></i>';
}
}
// --- CLOCK & GREETING ---
function updateClock() {
const now = new Date();
if (clockEl) {
clockEl.textContent = [
String(now.getHours()).padStart(2,'0'),
String(now.getMinutes()).padStart(2,'0'),
String(now.getSeconds()).padStart(2,'0')
].join(':');
}
if (dateEl) {
dateEl.textContent = now.toLocaleDateString('en-US', { weekday:'long', year:'numeric', month:'long', day:'numeric' });
}
}
function setGreeting() {
const hour = new Date().getHours();
const name = localStorage.getItem('userName') || '';
const g = hour < 12 ? 'Good Morning' : hour < 18 ? 'Good Afternoon' : 'Good Evening';
if (greetingEl) greetingEl.textContent = g + (name ? `, ${name}` : '');
}
// --- KEYBOARD SHORTCUTS ---
document.addEventListener('keydown', (e) => {
if (!isInputFocused() && (e.key === '/' || (e.ctrlKey && e.key === 'k'))) {
e.preventDefault();
searchInput?.focus();
}
if (e.key === 'n' && !isInputFocused() && notesToggle && notesPanel) {
// Toggle notes panel if you kept it in the HTML
notesPanel.classList.toggle('active');
}
if (e.key === 'Escape' && notesPanel) {
notesPanel.classList.remove('active');
searchInput?.blur();
}
});
function isInputFocused() {
const a = document.activeElement;
return a && ['INPUT','TEXTAREA','SELECT'].includes(a.tagName);
}
// --- INIT ---
updateClock();
setGreeting();
setInterval(updateClock, 1000);
renderCards();
});
|