privateuserh commited on
Commit
b366eeb
·
verified ·
1 Parent(s): b47fd5c

Update scripts/ui.js

Browse files
Files changed (1) hide show
  1. scripts/ui.js +37 -36
scripts/ui.js CHANGED
@@ -1,45 +1,46 @@
1
- // scripts/ui.js
2
 
3
- // --- Sample Data for Listings ---
4
- const streamingData = [{title:"The Grand Adventure",type:"Movie",genre:"Adventure, Comedy",platform:"Netflix",rating:"4.8",year:"2022",description:"A hilarious journey across continents with unexpected twists.",broadcastTime:"2023-12-10T19:30:00"},{title:"Dark Secrets",type:"TV Series",genre:"Drama, Thriller",platform:"HBO Max",rating:"4.7",year:"2021",description:"A small town's dark past resurfaces with shocking revelations.",broadcastTime:"2023-12-12T21:00:00"},{title:"Space Explorers",type:"Documentary",genre:"Science, Space",platform:"Disney+",rating:"4.9",year:"2023",description:"The latest discoveries from the frontiers of space exploration.",broadcastTime:"2023-12-14T18:00:00"}];
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
- function loadRSSFeed() {
18
- const container = getElement('rss-feed');
19
- if (!container) return;
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
- function loadRecommendations() {
30
- const container = getElement('recommendations-container');
31
- if (!container) return;
32
- container.innerHTML = '';
33
- streamingData.forEach(item => {
34
- const card = document.createElement('div');
35
- card.className = 'stream-card bg-white rounded-lg overflow-hidden shadow-md hover:shadow-xl transition duration-300 fade-in p-4';
36
- card.innerHTML = `<div class="mb-3"><div class="flex justify-between items-start"><h3 class="font-bold text-base">${item.title}</h3><span class="bg-yellow-100 text-yellow-800 text-xs px-2 py-1 rounded-full flex items-center"><i class="fas fa-star text-yellow-500 mr-1 text-xs"></i> ${item.rating}</span></div><p class="text-gray-600 text-xs mb-1">${item.type} • ${item.genre} • ${item.year}</p><div class="text-xs text-indigo-600 mb-2">${item.platform}</div></div><p class="text-gray-700 text-sm mb-4">${item.description}</p><div class="flex justify-between items-center"><button class="save-btn text-indigo-600 hover:text-indigo-800 text-xs font-medium"><i class="far fa-bookmark mr-1"></i> Save</button><a href="#" target="_blank" class="bg-indigo-600 hover:bg-indigo-700 text-white px-3 py-1 rounded-full text-xs font-medium transition"><i class="fas fa-play mr-1"></i> Watch</a></div>`;
37
- card.querySelector('.save-btn').addEventListener('click', () => showNotification('Reminder Set!', `We'll notify you when "${item.title}" is about to broadcast.`));
38
- container.appendChild(card);
39
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  }
41
 
42
  export function initUI() {
43
- loadRSSFeed();
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
  }