Spaces:
Running
Running
Update scripts/ui.js
Browse files- scripts/ui.js +37 -36
scripts/ui.js
CHANGED
|
@@ -1,45 +1,46 @@
|
|
| 1 |
-
// scripts/ui.js
|
| 2 |
|
| 3 |
-
|
| 4 |
-
const
|
| 5 |
-
const rssFeedData = [{title:"New Episode: The Grand Adventure",source:"Netflix",time:"5 hours ago",excerpt:"The comedy adventure movie is now the most-watched title on Netflix this week."}, {title:"Breaking: New streaming partnership",source:"Streaming News",time:"1 day ago",excerpt:"Major platforms announce new content sharing agreement."}];
|
| 6 |
-
|
| 7 |
-
const getElement = (id) => document.getElementById(id);
|
| 8 |
-
|
| 9 |
-
function showNotification(title, message) {
|
| 10 |
-
const container = getElement('notification');
|
| 11 |
if (!container) return;
|
| 12 |
-
container.className = 'notification show';
|
| 13 |
-
container.innerHTML = `<div class="flex items-center"><i class="fas fa-bell text-yellow-300 mr-3"></i><div><p class="font-semibold">${title}</p><p class="text-sm">${message}</p></div></div>`;
|
| 14 |
-
setTimeout(() => { container.classList.remove('show'); }, 3000);
|
| 15 |
-
}
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
container.innerHTML = '';
|
| 21 |
-
rssFeedData.forEach(item => {
|
| 22 |
-
const feedItem = document.createElement('div');
|
| 23 |
-
feedItem.className = 'rss-item bg-gray-50 p-3 rounded-lg';
|
| 24 |
-
feedItem.innerHTML = `<h4 class="font-medium text-sm mb-1">${item.title}</h4><div class="flex items-center text-xs text-gray-500 mb-2"><span>${item.source}</span><span class="mx-2">•</span><span>${item.time}</span></div><p class="text-xs text-gray-700">${item.excerpt}</p>`;
|
| 25 |
-
container.appendChild(feedItem);
|
| 26 |
-
});
|
| 27 |
-
}
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
}
|
| 41 |
|
| 42 |
export function initUI() {
|
| 43 |
-
|
| 44 |
loadRecommendations();
|
| 45 |
}
|
|
|
|
| 1 |
+
// in scripts/ui.js
|
| 2 |
|
| 3 |
+
async function loadRecommendations() {
|
| 4 |
+
const container = document.getElementById('recommendations-container');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
if (!container) return;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
try {
|
| 8 |
+
const response = await fetch('https://YOUR-WORKER-URL/recommendations');
|
| 9 |
+
const listings = await response.json();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
container.innerHTML = ''; // Clear previous listings
|
| 12 |
+
listings.forEach(item => {
|
| 13 |
+
const card = document.createElement('div');
|
| 14 |
+
// Add a subtle border if the item is pinned
|
| 15 |
+
const pinnedClass = item.is_pinned ? 'border-2 border-indigo-400' : '';
|
| 16 |
+
|
| 17 |
+
card.className = `stream-card bg-white rounded-lg overflow-hidden shadow-md hover:shadow-xl transition duration-300 p-4 relative ${pinnedClass}`;
|
| 18 |
+
|
| 19 |
+
// The card's content, now including the source_name
|
| 20 |
+
card.innerHTML = `
|
| 21 |
+
${item.is_pinned ? '<div class="absolute top-2 right-2 text-xs bg-indigo-500 text-white px-2 py-1 rounded-full animate-pulse"><i class="fas fa-thumbtack mr-1"></i> Pinned</div>' : ''}
|
| 22 |
+
<div class="mb-3">
|
| 23 |
+
<h3 class="font-bold text-base">${item.title}</h3>
|
| 24 |
+
<div class="text-xs text-gray-500 mb-2 mt-1">
|
| 25 |
+
From: <span class="font-semibold text-indigo-600">${item.source_name}</span>
|
| 26 |
+
</div>
|
| 27 |
+
</div>
|
| 28 |
+
<p class="text-gray-700 text-sm mb-4">${item.description}</p>
|
| 29 |
+
<div class="flex justify-between items-center">
|
| 30 |
+
<span class="text-xs font-bold uppercase text-gray-400">${item.category.replace('_', ' ')}</span>
|
| 31 |
+
<a href="${item.url}" target="_blank" rel="noopener noreferrer" class="bg-indigo-600 hover:bg-indigo-700 text-white px-3 py-1 rounded-full text-xs font-medium transition">
|
| 32 |
+
Visit Site
|
| 33 |
+
</a>
|
| 34 |
+
</div>
|
| 35 |
+
`;
|
| 36 |
+
container.appendChild(card);
|
| 37 |
+
});
|
| 38 |
+
} catch (error) {
|
| 39 |
+
container.innerHTML = `<p class="text-center text-red-500">Could not load recommendations.</p>`;
|
| 40 |
+
}
|
| 41 |
}
|
| 42 |
|
| 43 |
export function initUI() {
|
| 44 |
+
// This will run our function on page load
|
| 45 |
loadRecommendations();
|
| 46 |
}
|