Onttraders commited on
Commit
6b2c51b
·
verified ·
1 Parent(s): de20df8

🐳 14/04 - 17:39 - Build a trending algorithm.Tracks rank higher based on:- Number of plays- Number of unlocks- Recent activity (last 24–48 hours)Add:- “Trending Now” section- “Rising Beats”Update ran

Browse files
Files changed (3) hide show
  1. app.js +203 -3
  2. discover.html +91 -3
  3. index.html +122 -1
app.js CHANGED
@@ -159,14 +159,209 @@ const BF = (() => {
159
  try { Object.assign(shareCounts, JSON.parse(localStorage.getItem('bf_track_shares') || '{}')); } catch {}
160
  const unlockCounts = {};
161
  try { JSON.parse(localStorage.getItem('bf_download_states') || '[]').forEach(s => { if (s.unlocked) unlockCounts[s.trackId] = (unlockCounts[s.trackId] || 0) + 1; }); } catch {}
 
 
162
 
163
- return getAllTracks().map(t => {
 
 
 
 
 
164
  const p = parseFloat(t.plays || '0');
165
  const plays = (t.plays || '').includes('K') ? p * 1000 : p;
166
  const shares = shareCounts[t.id] || 0;
167
  const unlocks = unlockCounts[t.id] || 0;
168
- return { ...t, _trendScore: plays + (unlocks * 10) + (shares * 5) };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
  }).sort((a, b) => b._trendScore - a._trendScore);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170
  };
171
 
172
  // ===== SHARE TRACKING =====
@@ -175,6 +370,7 @@ const BF = (() => {
175
  let shares = JSON.parse(localStorage.getItem('bf_track_shares') || '{}');
176
  shares[trackId] = (shares[trackId] || 0) + 1;
177
  localStorage.setItem('bf_track_shares', JSON.stringify(shares));
 
178
  } catch {}
179
  };
180
 
@@ -763,6 +959,7 @@ const BF = (() => {
763
  const playTrack = (track, fromQueue) => {
764
  localStorage.setItem('currentTrack', JSON.stringify(track));
765
  localStorage.setItem('isPlaying', 'true');
 
766
  syncPlayer();
767
  // Update queue context if track is in queue
768
  if (!fromQueue) {
@@ -1762,7 +1959,10 @@ const BF = (() => {
1762
  // Creator onboarding & incentives
1763
  isFirstTimeCreator, getOnboardingState, getCreatorBadges,
1764
  getTopCreatorsThisWeek, getMotivationalPrompt,
1765
- dismissOnboarding, isOnboardingDismissed
 
 
 
1766
  };
1767
  })(); + MONETIZATION_DEFAULTS.minimumPrice };
1768
  }
 
159
  try { Object.assign(shareCounts, JSON.parse(localStorage.getItem('bf_track_shares') || '{}')); } catch {}
160
  const unlockCounts = {};
161
  try { JSON.parse(localStorage.getItem('bf_download_states') || '[]').forEach(s => { if (s.unlocked) unlockCounts[s.trackId] = (unlockCounts[s.trackId] || 0) + 1; }); } catch {}
162
+ const recentActivity = {};
163
+ try { Object.assign(recentActivity, JSON.parse(localStorage.getItem('bf_recent_activity') || '{}')); } catch {}
164
 
165
+ const now = Date.now();
166
+ const HOUR = 3600000;
167
+ let prevRankings = {};
168
+ try { prevRankings = JSON.parse(localStorage.getItem('bf_prev_rankings') || '{}'); } catch {}
169
+
170
+ const ranked = getAllTracks().map(t => {
171
  const p = parseFloat(t.plays || '0');
172
  const plays = (t.plays || '').includes('K') ? p * 1000 : p;
173
  const shares = shareCounts[t.id] || 0;
174
  const unlocks = unlockCounts[t.id] || 0;
175
+
176
+ // Base score
177
+ const baseScore = plays + (unlocks * 10) + (shares * 5);
178
+
179
+ // Recency boost: recent activity gets exponential weight
180
+ const act = recentActivity[t.id] || { lastPlay: 0, lastUnlock: 0, recentPlays: 0, recentUnlocks: 0 };
181
+ const hoursSincePlay = act.lastPlay ? (now - act.lastPlay) / HOUR : Infinity;
182
+ const hoursSinceUnlock = act.lastUnlock ? (now - act.lastUnlock) / HOUR : Infinity;
183
+
184
+ let recencyBoost = 1;
185
+ if (hoursSincePlay < 24) recencyBoost *= 3;
186
+ else if (hoursSincePlay < 48) recencyBoost *= 2;
187
+ else if (hoursSincePlay < 72) recencyBoost *= 1.5;
188
+
189
+ if (hoursSinceUnlock < 24) recencyBoost *= 2.5;
190
+ else if (hoursSinceUnlock < 48) recencyBoost *= 1.8;
191
+
192
+ // Recent volume boost
193
+ const recentVolumeBoost = Math.min((act.recentPlays || 0) / 100, 5) + Math.min((act.recentUnlocks || 0) / 5, 3);
194
+
195
+ // New upload bonus
196
+ let uploadBonus = 0;
197
+ if (t.publishedAt) {
198
+ const hoursSinceUpload = (now - new Date(t.publishedAt).getTime()) / HOUR;
199
+ if (hoursSinceUpload < 24) uploadBonus = 500;
200
+ else if (hoursSinceUpload < 48) uploadBonus = 300;
201
+ else if (hoursSinceUpload < 72) uploadBonus = 100;
202
+ }
203
+
204
+ const trendScore = (baseScore * recencyBoost) + (recentVolumeBoost * 100) + uploadBonus;
205
+ const prevRank = prevRankings[t.id] || null;
206
+
207
+ return { ...t, _trendScore: trendScore, _recencyBoost: recencyBoost, _recentPlays: act.recentPlays || 0, _recentUnlocks: act.recentUnlocks || 0, _prevRank: prevRank };
208
  }).sort((a, b) => b._trendScore - a._trendScore);
209
+
210
+ // Save current rankings for position-change tracking
211
+ const newRankings = {};
212
+ ranked.forEach((t, i) => { newRankings[t.id] = i + 1; });
213
+ try { localStorage.setItem('bf_current_rankings', JSON.stringify(newRankings)); } catch {}
214
+
215
+ return ranked.map((t, i) => ({
216
+ ...t,
217
+ _rank: i + 1,
218
+ _rankChange: t._prevRank ? (t._prevRank - (i + 1)) : 0
219
+ }));
220
+ };
221
+
222
+ // ===== RISING BEATS =====
223
+ const getRisingBeats = () => {
224
+ const recentActivity = {};
225
+ try { Object.assign(recentActivity, JSON.parse(localStorage.getItem('bf_recent_activity') || '{}')); } catch {}
226
+ const shareCounts = {};
227
+ try { Object.assign(shareCounts, JSON.parse(localStorage.getItem('bf_track_shares') || '{}')); } catch {}
228
+ const unlockCounts = {};
229
+ try { JSON.parse(localStorage.getItem('bf_download_states') || '[]').forEach(s => { if (s.unlocked) unlockCounts[s.trackId] = (unlockCounts[s.trackId] || 0) + 1; }); } catch {}
230
+
231
+ const now = Date.now();
232
+ const HOUR = 3600000;
233
+
234
+ return getAllTracks().map(t => {
235
+ const p = parseFloat(t.plays || '0');
236
+ const totalPlays = (t.plays || '').includes('K') ? p * 1000 : p;
237
+ const shares = shareCounts[t.id] || 0;
238
+ const unlocks = unlockCounts[t.id] || 0;
239
+
240
+ const act = recentActivity[t.id] || { recentPlays: 0, recentUnlocks: 0, recentShares: 0 };
241
+ const recentScore = ((act.recentPlays || 0) * 1) + ((act.recentUnlocks || 0) * 10) + ((act.recentShares || 0) * 5);
242
+
243
+ // Velocity: how fast is it growing relative to total
244
+ const velocityScore = totalPlays > 0 ? (recentScore / totalPlays) * 1000 : (recentScore > 0 ? 500 : 0);
245
+
246
+ // New upload bonus — fresh tracks get a big boost
247
+ let uploadBonus = 0;
248
+ if (t.publishedAt) {
249
+ const hoursSinceUpload = (now - new Date(t.publishedAt).getTime()) / HOUR;
250
+ if (hoursSinceUpload < 12) uploadBonus = 800;
251
+ else if (hoursSinceUpload < 24) uploadBonus = 500;
252
+ else if (hoursSinceUpload < 48) uploadBonus = 300;
253
+ else if (hoursSinceUpload < 72) uploadBonus = 100;
254
+ }
255
+ // Also check date field for older tracks
256
+ if (!t.publishedAt && t.date) {
257
+ const d = t.date.toLowerCase();
258
+ if (d.includes('just') || d.includes('minute') || d.includes('hour')) uploadBonus = Math.max(uploadBonus, 400);
259
+ else if (d.includes('1 day') || d.includes('2 day')) uploadBonus = Math.max(uploadBonus, 200);
260
+ }
261
+
262
+ const risingScore = (recentScore * 3) + velocityScore + uploadBonus;
263
+
264
+ return {
265
+ ...t,
266
+ _risingScore: risingScore,
267
+ _recentPlays: act.recentPlays || 0,
268
+ _recentUnlocks: act.recentUnlocks || 0,
269
+ _recentShares: act.recentShares || 0,
270
+ _velocity: velocityScore
271
+ };
272
+ })
273
+ .filter(t => t._risingScore > 10)
274
+ .sort((a, b) => b._risingScore - a._risingScore);
275
+ };
276
+
277
+ // ===== TREND INDICATOR =====
278
+ const getTrackTrendIndicator = (trackId) => {
279
+ try {
280
+ const prev = JSON.parse(localStorage.getItem('bf_prev_rankings') || '{}');
281
+ const cur = JSON.parse(localStorage.getItem('bf_current_rankings') || '{}');
282
+ const prevPos = prev[trackId];
283
+ const curPos = cur[trackId];
284
+ if (!prevPos && !curPos) return { direction: 'new', arrow: '🆕', label: 'New', cssClass: 'text-gray-400' };
285
+ if (!prevPos) return { direction: 'new', arrow: '🆕', label: 'New', cssClass: 'text-cyan-400' };
286
+ const change = prevPos - curPos;
287
+ if (change > 2) return { direction: 'up', arrow: '↑', label: '+' + change, cssClass: 'text-green-400' };
288
+ if (change > 0) return { direction: 'up', arrow: '↑', label: '+' + change, cssClass: 'text-green-400' };
289
+ if (change < -2) return { direction: 'down', arrow: '↓', label: '' + change, cssClass: 'text-red-400' };
290
+ if (change < 0) return { direction: 'down', arrow: '↓', label: '' + change, cssClass: 'text-red-400' };
291
+ return { direction: 'stable', arrow: '→', label: '—', cssClass: 'text-gray-600' };
292
+ } catch {
293
+ return { direction: 'stable', arrow: '→', label: '—', cssClass: 'text-gray-600' };
294
+ }
295
+ };
296
+
297
+ // ===== ACTIVITY RECORDING =====
298
+ const recordActivity = (trackId, type) => {
299
+ try {
300
+ let activity = JSON.parse(localStorage.getItem('bf_recent_activity') || '{}');
301
+ if (!activity[trackId]) activity[trackId] = { lastPlay: 0, lastUnlock: 0, lastShare: 0, recentPlays: 0, recentUnlocks: 0, recentShares: 0 };
302
+ const now = Date.now();
303
+ const cutoff = now - (48 * 3600000); // 48h window
304
+ // Reset counters if data is stale
305
+ if ((activity[trackId]._lastReset || 0) < cutoff) {
306
+ activity[trackId].recentPlays = 0;
307
+ activity[trackId].recentUnlocks = 0;
308
+ activity[trackId].recentShares = 0;
309
+ activity[trackId]._lastReset = now;
310
+ }
311
+ if (type === 'play') { activity[trackId].lastPlay = now; activity[trackId].recentPlays = (activity[trackId].recentPlays || 0) + 1; }
312
+ else if (type === 'unlock') { activity[trackId].lastUnlock = now; activity[trackId].recentUnlocks = (activity[trackId].recentUnlocks || 0) + 1; }
313
+ else if (type === 'share') { activity[trackId].lastShare = now; activity[trackId].recentShares = (activity[trackId].recentShares || 0) + 1; }
314
+ localStorage.setItem('bf_recent_activity', JSON.stringify(activity));
315
+ } catch {}
316
+ };
317
+
318
+ // ===== SIMULATE RECENT ACTIVITY (demo data) =====
319
+ const simulateRecentActivity = () => {
320
+ try {
321
+ let activity = JSON.parse(localStorage.getItem('bf_recent_activity') || '{}');
322
+ const allTracks = getAllTracks();
323
+ const now = Date.now();
324
+ const HOUR = 3600000;
325
+ // Generate plausible recent activity for top tracks
326
+ allTracks.forEach((t, i) => {
327
+ if (!activity[t.id]) activity[t.id] = { lastPlay: 0, lastUnlock: 0, lastShare: 0, recentPlays: 0, recentUnlocks: 0, recentShares: 0, _lastReset: now };
328
+ const p = parseFloat(t.plays || '0');
329
+ const totalPlays = (t.plays || '').includes('K') ? p * 1000 : p;
330
+ // Top tracks get more recent activity
331
+ if (i < 3) {
332
+ activity[t.id].recentPlays = Math.floor(200 + Math.random() * 400);
333
+ activity[t.id].recentUnlocks = Math.floor(10 + Math.random() * 25);
334
+ activity[t.id].recentShares = Math.floor(5 + Math.random() * 15);
335
+ activity[t.id].lastPlay = now - (Math.random() * 12 * HOUR);
336
+ activity[t.id].lastUnlock = now - (Math.random() * 24 * HOUR);
337
+ } else if (i < 6) {
338
+ activity[t.id].recentPlays = Math.floor(80 + Math.random() * 200);
339
+ activity[t.id].recentUnlocks = Math.floor(3 + Math.random() * 12);
340
+ activity[t.id].recentShares = Math.floor(2 + Math.random() * 8);
341
+ activity[t.id].lastPlay = now - (Math.random() * 24 * HOUR);
342
+ } else {
343
+ activity[t.id].recentPlays = Math.floor(10 + Math.random() * 80);
344
+ activity[t.id].recentUnlocks = Math.floor(Math.random() * 5);
345
+ activity[t.id].recentShares = Math.floor(Math.random() * 3);
346
+ }
347
+ // Freshly uploaded tracks get extra boost
348
+ if (t.date && (t.date.includes('Just') || t.date.includes('hour') || t.date.includes('minute'))) {
349
+ activity[t.id].recentPlays += Math.floor(100 + Math.random() * 300);
350
+ activity[t.id].recentUnlocks += Math.floor(5 + Math.random() * 15);
351
+ activity[t.id].lastPlay = now - (Math.random() * 4 * HOUR);
352
+ }
353
+ });
354
+ activity._simulated = true;
355
+ localStorage.setItem('bf_recent_activity', JSON.stringify(activity));
356
+ } catch {}
357
+ };
358
+
359
+ // ===== SAVE RANKINGS SNAPSHOT =====
360
+ const saveRankingSnapshot = () => {
361
+ try {
362
+ const current = JSON.parse(localStorage.getItem('bf_current_rankings') || '{}');
363
+ localStorage.setItem('bf_prev_rankings', JSON.stringify(current));
364
+ } catch {}
365
  };
366
 
367
  // ===== SHARE TRACKING =====
 
370
  let shares = JSON.parse(localStorage.getItem('bf_track_shares') || '{}');
371
  shares[trackId] = (shares[trackId] || 0) + 1;
372
  localStorage.setItem('bf_track_shares', JSON.stringify(shares));
373
+ recordActivity(trackId, 'share');
374
  } catch {}
375
  };
376
 
 
959
  const playTrack = (track, fromQueue) => {
960
  localStorage.setItem('currentTrack', JSON.stringify(track));
961
  localStorage.setItem('isPlaying', 'true');
962
+ recordActivity(track.id, 'play');
963
  syncPlayer();
964
  // Update queue context if track is in queue
965
  if (!fromQueue) {
 
1959
  // Creator onboarding & incentives
1960
  isFirstTimeCreator, getOnboardingState, getCreatorBadges,
1961
  getTopCreatorsThisWeek, getMotivationalPrompt,
1962
+ dismissOnboarding, isOnboardingDismissed,
1963
+ // Trending algorithm
1964
+ getRisingBeats, getTrackTrendIndicator, recordActivity,
1965
+ simulateRecentActivity, saveRankingSnapshot
1966
  };
1967
  })(); + MONETIZATION_DEFAULTS.minimumPrice };
1968
  }
discover.html CHANGED
@@ -259,6 +259,21 @@
259
  </div>
260
  </div>
261
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
262
  <!-- New Releases -->
263
  <div>
264
  <h2 class="text-lg font-semibold mb-4 flex items-center gap-2">
@@ -371,8 +386,12 @@
371
 
372
  function renderTrending() {
373
  const grid = document.getElementById('trendingGrid');
374
- grid.innerHTML = trendingTracks.map((track, i) => `
375
- <div class="track-card glass-panel rounded-2xl p-4 group cursor-pointer">
 
 
 
 
376
  <div class="relative aspect-square rounded-xl overflow-hidden mb-4">
377
  <img src="${track.image}" class="w-full h-full object-cover transition duration-500 group-hover:scale-110">
378
  <div class="absolute inset-0 bg-black/50 opacity-0 group-hover:opacity-100 transition flex items-center justify-center backdrop-blur-[2px]">
@@ -383,6 +402,7 @@
383
  <div class="absolute top-2 left-2 px-2 py-1 rounded bg-black/70 text-xs font-bold text-white">
384
  #${i + 1}
385
  </div>
 
386
  </div>
387
  <h3 class="font-semibold text-white truncate group-hover:text-cyan-400 transition">${track.title}</h3>
388
  <p class="text-sm text-gray-400 truncate">${track.artist}</p>
@@ -392,7 +412,8 @@
392
  </p>
393
  ${BF.renderDL(track.id, track.title, track.artist)}
394
  </div>
395
- `).join('');
 
396
  lucide.createIcons();
397
  }
398
 
@@ -441,10 +462,77 @@
441
  function previousTrack() {}
442
  function nextTrack() {}
443
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
444
  // Initialize
445
  try {
446
  renderTrending();
447
  renderNewReleases();
 
448
  } catch (e) {
449
  console.error('Error initializing discover page:', e);
450
  }
 
259
  </div>
260
  </div>
261
 
262
+ <!-- Rising Beats -->
263
+ <div class="mb-8" id="risingBeatsDiscoverSection">
264
+ <div class="flex items-center justify-between mb-6">
265
+ <h2 class="text-lg font-semibold flex items-center gap-2">
266
+ <i data-lucide="flame" class="w-5 h-5 text-orange-500"></i>
267
+ Rising Beats
268
+ <span class="text-xs text-orange-400/60 font-normal ml-1">🔥 Fastest growing tracks</span>
269
+ </h2>
270
+ <button class="text-xs text-gray-500 hover:text-cyan-400 transition flex items-center gap-1" onclick="refreshDiscoverRising()">
271
+ <i data-lucide="refresh-cw" class="w-3.5 h-3.5"></i> Refresh
272
+ </button>
273
+ </div>
274
+ <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4" id="risingBeatsGrid"></div>
275
+ </div>
276
+
277
  <!-- New Releases -->
278
  <div>
279
  <h2 class="text-lg font-semibold mb-4 flex items-center gap-2">
 
386
 
387
  function renderTrending() {
388
  const grid = document.getElementById('trendingGrid');
389
+ // Use enhanced trending algorithm
390
+ const enhancedTrending = BF.getTrendingTracks().slice(0, 8);
391
+ grid.innerHTML = enhancedTrending.map((track, i) => {
392
+ const trend = BF.getTrackTrendIndicator(track.id);
393
+ return `
394
+ <div class="track-card glass-panel rounded-2xl p-4 group cursor-pointer" onclick="BF.playTrack(${JSON.stringify(track).replace(/"/g, '&quot;')})">
395
  <div class="relative aspect-square rounded-xl overflow-hidden mb-4">
396
  <img src="${track.image}" class="w-full h-full object-cover transition duration-500 group-hover:scale-110">
397
  <div class="absolute inset-0 bg-black/50 opacity-0 group-hover:opacity-100 transition flex items-center justify-center backdrop-blur-[2px]">
 
402
  <div class="absolute top-2 left-2 px-2 py-1 rounded bg-black/70 text-xs font-bold text-white">
403
  #${i + 1}
404
  </div>
405
+ ${trend.direction !== 'stable' ? `<div class="absolute top-2 right-2 px-1.5 py-0.5 rounded text-[9px] font-bold ${trend.cssClass} bg-black/60 backdrop-blur-sm">${trend.arrow} ${trend.label}</div>` : ''}
406
  </div>
407
  <h3 class="font-semibold text-white truncate group-hover:text-cyan-400 transition">${track.title}</h3>
408
  <p class="text-sm text-gray-400 truncate">${track.artist}</p>
 
412
  </p>
413
  ${BF.renderDL(track.id, track.title, track.artist)}
414
  </div>
415
+ `;
416
+ }).join('');
417
  lucide.createIcons();
418
  }
419
 
 
462
  function previousTrack() {}
463
  function nextTrack() {}
464
 
465
+ // ===== RISING BEATS =====
466
+ // Initialize activity simulation
467
+ if (!JSON.parse(localStorage.getItem('bf_recent_activity') || '{}')._simulated) {
468
+ BF.simulateRecentActivity();
469
+ }
470
+
471
+ function renderDiscoverRising() {
472
+ const rising = BF.getRisingBeats().slice(0, 8);
473
+ const grid = document.getElementById('risingBeatsGrid');
474
+ if (!grid) return;
475
+
476
+ if (!rising.length) {
477
+ const section = document.getElementById('risingBeatsDiscoverSection');
478
+ if (section) section.style.display = 'none';
479
+ return;
480
+ }
481
+
482
+ grid.innerHTML = rising.map((track, i) => {
483
+ const velocity = track._velocity || 0;
484
+ const hotness = velocity > 200 ? '🔥🔥🔥' : velocity > 100 ? '🔥🔥' : velocity > 30 ? '🔥' : '📈';
485
+ const recentPlays = track._recentPlays || 0;
486
+ const recentUnlocks = track._recentUnlocks || 0;
487
+ const trend = BF.getTrackTrendIndicator(track.id);
488
+
489
+ return `
490
+ <div class="track-card glass-panel rounded-2xl p-4 group cursor-pointer" onclick="BF.playTrack(${JSON.stringify(track).replace(/"/g, '&quot;')})">
491
+ <div class="relative aspect-square rounded-xl overflow-hidden mb-4">
492
+ <img src="${track.image}" class="w-full h-full object-cover transition duration-500 group-hover:scale-110">
493
+ <div class="absolute inset-0 bg-black/50 opacity-0 group-hover:opacity-100 transition flex items-center justify-center backdrop-blur-[2px]">
494
+ <div class="w-12 h-12 rounded-full bg-orange-500 text-white flex items-center justify-center" style="box-shadow:0 0 20px rgba(249,115,22,0.3)">
495
+ <i data-lucide="play" class="w-6 h-6 fill-current ml-1"></i>
496
+ </div>
497
+ </div>
498
+ <div class="absolute top-2 left-2 px-2 py-1 rounded bg-black/70 text-xs font-bold flex items-center gap-1">
499
+ <span>${hotness}</span>
500
+ <span>#${i + 1}</span>
501
+ </div>
502
+ <div class="absolute top-2 right-2 px-1.5 py-0.5 rounded text-[9px] font-bold ${trend.cssClass} bg-black/60 backdrop-blur-sm flex items-center gap-0.5">
503
+ ${trend.arrow} ${trend.label}
504
+ </div>
505
+ </div>
506
+ <h3 class="font-semibold text-white truncate group-hover:text-orange-400 transition">${track.title}</h3>
507
+ <p class="text-sm text-gray-400 truncate">${track.artist}</p>
508
+ <div class="mt-2 flex items-center justify-between text-xs text-gray-500">
509
+ <span class="flex items-center gap-1">
510
+ <i data-lucide="play-circle" class="w-3 h-3"></i>
511
+ +${recentPlays} plays
512
+ </span>
513
+ <span class="flex items-center gap-1 text-cyan-400">
514
+ <i data-lucide="download" class="w-3 h-3"></i>
515
+ ${recentUnlocks} unlocks
516
+ </span>
517
+ </div>
518
+ <div class="mt-2">${BF.renderDL(track.id, track.title, track.artist)}</div>
519
+ </div>
520
+ `;
521
+ }).join('');
522
+ lucide.createIcons();
523
+ }
524
+
525
+ function refreshDiscoverRising() {
526
+ BF.simulateRecentActivity();
527
+ renderDiscoverRising();
528
+ BF.showToast('Rankings refreshed 🔥');
529
+ }
530
+
531
  // Initialize
532
  try {
533
  renderTrending();
534
  renderNewReleases();
535
+ renderDiscoverRising();
536
  } catch (e) {
537
  console.error('Error initializing discover page:', e);
538
  }
index.html CHANGED
@@ -222,6 +222,24 @@
222
  <div class="space-y-2" id="freshList"></div>
223
  </section>
224
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
225
  <!-- You Might Like -->
226
  <section class="mb-10 hidden" id="recSection">
227
  <div class="flex items-center justify-between mb-5">
@@ -349,9 +367,20 @@
349
  </a>
350
  `).join('');
351
 
352
- // Trending Row
 
 
 
 
 
 
 
353
  const trending = BF.getTrendingTracks().slice(0, 8);
354
  document.getElementById('trendingRow').innerHTML = trending.map(track => {
 
 
 
 
355
  const isSuperFanLocked = [2, 4, 6].includes(track.id);
356
  const isFanActive = BF.isSuperFanOf(track.artist);
357
  const locked = isSuperFanLocked && !isFanActive;
@@ -363,6 +392,7 @@
363
  <div class="w-10 h-10 rounded-full bg-cyan-500 text-black flex items-center justify-center glow-cyan"><i data-lucide="play" class="w-5 h-5 fill-current ml-0.5"></i></div>
364
  </div>
365
  ${locked ? '<div class="bf-locked-overlay"><span class="bf-superfan-badge"><i data-lucide="lock" class="w-3 h-3"></i> Super Fan Only</span><p class="text-[9px] text-gray-400 mt-1">Unlock</p></div>' : ''}
 
366
  </div>
367
  <h3 class="text-sm font-semibold text-white truncate group-hover:text-cyan-400 transition ${locked ? 'opacity-60' : ''}">${track.title}</h3>
368
  <p class="text-xs text-gray-500 truncate ${locked ? 'opacity-60' : ''}">${track.artist}</p>
@@ -766,6 +796,97 @@
766
  lucide.createIcons();
767
  })();
768
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
769
  // Producer motivational prompt
770
  (function checkProducerPrompt() {
771
  try {
 
222
  <div class="space-y-2" id="freshList"></div>
223
  </section>
224
 
225
+ <!-- Rising Beats -->
226
+ <section class="mb-10" id="risingBeatsSection">
227
+ <div class="flex items-center justify-between mb-5">
228
+ <h2 class="text-lg sm:text-xl font-bold flex items-center gap-2">
229
+ <i data-lucide="flame" class="w-5 h-5 text-orange-500"></i>
230
+ Rising Beats
231
+ <span class="text-xs text-orange-400/60 font-normal ml-1">🔥 Fastest growing</span>
232
+ </h2>
233
+ <div class="flex items-center gap-2">
234
+ <button class="text-xs text-gray-500 hover:text-cyan-400 transition flex items-center gap-1" onclick="refreshRisingBeats()">
235
+ <i data-lucide="refresh-cw" class="w-3.5 h-3.5"></i> Refresh
236
+ </button>
237
+ <span class="text-[10px] text-gray-600 flex items-center gap-1" id="risingUpdateTime">Updated just now</span>
238
+ </div>
239
+ </div>
240
+ <div class="scroll-row flex gap-3 pb-2" id="risingRow"></div>
241
+ </section>
242
+
243
  <!-- You Might Like -->
244
  <section class="mb-10 hidden" id="recSection">
245
  <div class="flex items-center justify-between mb-5">
 
367
  </a>
368
  `).join('');
369
 
370
+ // Initialize recent activity simulation for trending algorithm
371
+ if (!JSON.parse(localStorage.getItem('bf_recent_activity') || '{}')._simulated) {
372
+ BF.simulateRecentActivity();
373
+ }
374
+ // Save ranking snapshot for position-change tracking
375
+ BF.saveRankingSnapshot();
376
+
377
+ // Trending Row with trend indicators
378
  const trending = BF.getTrendingTracks().slice(0, 8);
379
  document.getElementById('trendingRow').innerHTML = trending.map(track => {
380
+ const trend = BF.getTrackTrendIndicator(track.id);
381
+ const trendBadge = trend.direction !== 'stable'
382
+ ? `<span class="absolute top-2 left-2 px-1.5 py-0.5 rounded text-[9px] font-bold ${trend.cssClass} bg-black/60 backdrop-blur-sm flex items-center gap-0.5">${trend.arrow} ${trend.label}</span>`
383
+ : '';
384
  const isSuperFanLocked = [2, 4, 6].includes(track.id);
385
  const isFanActive = BF.isSuperFanOf(track.artist);
386
  const locked = isSuperFanLocked && !isFanActive;
 
392
  <div class="w-10 h-10 rounded-full bg-cyan-500 text-black flex items-center justify-center glow-cyan"><i data-lucide="play" class="w-5 h-5 fill-current ml-0.5"></i></div>
393
  </div>
394
  ${locked ? '<div class="bf-locked-overlay"><span class="bf-superfan-badge"><i data-lucide="lock" class="w-3 h-3"></i> Super Fan Only</span><p class="text-[9px] text-gray-400 mt-1">Unlock</p></div>' : ''}
395
+ ${trendBadge}
396
  </div>
397
  <h3 class="text-sm font-semibold text-white truncate group-hover:text-cyan-400 transition ${locked ? 'opacity-60' : ''}">${track.title}</h3>
398
  <p class="text-xs text-gray-500 truncate ${locked ? 'opacity-60' : ''}">${track.artist}</p>
 
796
  lucide.createIcons();
797
  })();
798
 
799
+ // ===== RISING BEATS =====
800
+ function renderRisingBeats() {
801
+ const rising = BF.getRisingBeats().slice(0, 8);
802
+ const container = document.getElementById('risingRow');
803
+ if (!container) return;
804
+
805
+ if (!rising.length) {
806
+ document.getElementById('risingBeatsSection').style.display = 'none';
807
+ return;
808
+ }
809
+
810
+ container.innerHTML = rising.map((track, i) => {
811
+ const isLocked = BF.isTrackLocked(track.id, track.artist);
812
+ const isSF = BF.isSuperFanOf(track.artist);
813
+ const safeTitle = String(track.title).replace(/'/g, "\\'");
814
+ const safeArtist = String(track.artist).replace(/'/g, "\\'");
815
+
816
+ // Rising badge: velocity indicator
817
+ const velocity = track._velocity || 0;
818
+ const hotness = velocity > 200 ? '🔥🔥🔥' : velocity > 100 ? '🔥🔥' : velocity > 30 ? '🔥' : '📈';
819
+ const recentPlays = track._recentPlays || 0;
820
+ const recentUnlocks = track._recentUnlocks || 0;
821
+
822
+ return `
823
+ <div class="track-card flex-shrink-0 w-40 sm:w-48 glass-panel rounded-xl p-3 group cursor-pointer relative" onclick="BF.playTrack(${JSON.stringify(track).replace(/"/g, '&quot;')})">
824
+ <div class="relative aspect-square rounded-lg overflow-hidden mb-3">
825
+ <img src="${track.image}" class="w-full h-full object-cover transition duration-500 group-hover:scale-110" loading="lazy">
826
+ <div class="play-btn-overlay absolute inset-0 bg-black/50 flex items-center justify-center">
827
+ <div class="w-10 h-10 rounded-full bg-orange-500 text-white flex items-center justify-center" style="box-shadow:0 0 16px rgba(249,115,22,0.3)"><i data-lucide="play" class="w-5 h-5 fill-current ml-0.5"></i></div>
828
+ </div>
829
+ <span class="absolute top-2 left-2 px-1.5 py-0.5 rounded text-[9px] font-bold text-orange-400 bg-black/60 backdrop-blur-sm">${hotness} #${i + 1}</span>
830
+ ${isLocked ? '<div class="bf-locked-overlay"><span class="bf-superfan-badge"><i data-lucide="lock" class="w-3 h-3"></i> Unlock</span></div>' : ''}
831
+ </div>
832
+ <h3 class="text-sm font-semibold text-white truncate group-hover:text-orange-400 transition">${track.title}</h3>
833
+ <p class="text-xs text-gray-500 truncate">${track.artist}</p>
834
+ <div class="mt-1.5 flex items-center gap-2 text-[10px]">
835
+ <span class="text-green-400 font-semibold">+${recentPlays} plays</span>
836
+ <span class="text-gray-600">·</span>
837
+ <span class="text-cyan-400">${recentUnlocks} unlocks</span>
838
+ </div>
839
+ <div class="mt-1.5">${BF.renderDL(track.id, track.title, track.artist)}</div>
840
+ </div>
841
+ `;
842
+ }).join('');
843
+ lucide.createIcons();
844
+ }
845
+
846
+ function refreshRisingBeats() {
847
+ BF.simulateRecentActivity();
848
+ renderRisingBeats();
849
+ const timeEl = document.getElementById('risingUpdateTime');
850
+ if (timeEl) timeEl.textContent = 'Updated just now';
851
+ BF.showToast('Rankings refreshed 🔥');
852
+ }
853
+
854
+ renderRisingBeats();
855
+
856
+ // ===== DYNAMIC RANKING UPDATES =====
857
+ // Re-render trending and rising every 30 seconds
858
+ let _rankingUpdateCount = 0;
859
+ setInterval(() => {
860
+ _rankingUpdateCount++;
861
+ BF.saveRankingSnapshot();
862
+ // Re-render trending row with updated rankings
863
+ const newTrending = BF.getTrendingTracks().slice(0, 8);
864
+ const trendingRow = document.getElementById('trendingRow');
865
+ if (trendingRow && newTrending.length) {
866
+ // Only full re-render every 3rd cycle to avoid flickering
867
+ if (_rankingUpdateCount % 3 === 0) {
868
+ // Update trend indicators on existing cards
869
+ newTrending.forEach((track, idx) => {
870
+ const card = trendingRow.children[idx];
871
+ if (card) {
872
+ const trend = BF.getTrackTrendIndicator(track.id);
873
+ // Find and update trend badge
874
+ const oldBadge = card.querySelector('[data-trend-badge]');
875
+ if (oldBadge) {
876
+ oldBadge.className = `px-1.5 py-0.5 rounded text-[9px] font-bold ${trend.cssClass} bg-black/60 backdrop-blur-sm flex items-center gap-0.5`;
877
+ oldBadge.setAttribute('data-trend-badge', 'true');
878
+ oldBadge.innerHTML = `${trend.arrow} ${trend.label}`;
879
+ }
880
+ }
881
+ });
882
+ }
883
+ }
884
+ // Update rising beats
885
+ renderRisingBeats();
886
+ const timeEl = document.getElementById('risingUpdateTime');
887
+ if (timeEl) timeEl.textContent = 'Updated ' + (_rankingUpdateCount * 30) + 's ago';
888
+ }, 30000);
889
+
890
  // Producer motivational prompt
891
  (function checkProducerPrompt() {
892
  try {