diff --git a/api/record_history.php b/api/record_history.php new file mode 100644 index 0000000..56f9830 --- /dev/null +++ b/api/record_history.php @@ -0,0 +1,35 @@ + false, 'error' => 'Invalid input']); + exit; +} + +$title = $input['title']; +$artist = $input['artist']; +$cover = $input['cover'] ?? null; + +try { + $db = db(); + + // Check if the last recorded song is the same to avoid duplicates on refresh + $stmt = $db->prepare("SELECT title, artist FROM song_history ORDER BY played_at DESC LIMIT 1"); + $stmt->execute(); + $last = $stmt->fetch(); + + if ($last && $last['title'] === $title && $last['artist'] === $artist) { + echo json_encode(['success' => true, 'message' => 'Already recorded']); + exit; + } + + $stmt = $db->prepare("INSERT INTO song_history (title, artist, cover) VALUES (?, ?, ?)"); + $stmt->execute([$title, $artist, $cover]); + + echo json_encode(['success' => true]); +} catch (PDOException $e) { + echo json_encode(['success' => false, 'error' => $e->getMessage()]); +} diff --git a/db/migrations/001_create_song_history.sql b/db/migrations/001_create_song_history.sql new file mode 100644 index 0000000..8c67f5e --- /dev/null +++ b/db/migrations/001_create_song_history.sql @@ -0,0 +1,7 @@ +CREATE TABLE IF NOT EXISTS song_history ( + id INT AUTO_INCREMENT PRIMARY KEY, + title VARCHAR(255) NOT NULL, + artist VARCHAR(255) NOT NULL, + cover VARCHAR(500), + played_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP +); diff --git a/history.php b/history.php new file mode 100644 index 0000000..696bb40 --- /dev/null +++ b/history.php @@ -0,0 +1,263 @@ +query("SELECT * FROM song_history WHERE played_at > DATE_SUB(NOW(), INTERVAL 24 HOUR) ORDER BY played_at DESC LIMIT 50"); +$history = $stmt->fetchAll(); +?> + + +
+ + +
+
@@ -1929,6 +1949,13 @@ $facebook_link = "https://www.facebook.com/profile.php?id=61587890927489";
if (coverPlaceholder) coverPlaceholder.style.display = 'none';
trackCover.style.opacity = '1';
+ // Record History in Database
+ fetch('api/record_history.php', {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ title: title, artist: artist, cover: coverUrl })
+ }).catch(err => console.error("Error recording history:", err));
+
// Dynamic Color Extraction
trackCover.onload = function() {
try {
@@ -2032,6 +2059,36 @@ $facebook_link = "https://www.facebook.com/profile.php?id=61587890927489";
fetchTopSongs();
}, 30000);
+ // Theme Toggle Functionality
+ function toggleTheme() {
+ const body = document.body;
+ const currentTheme = body.getAttribute('data-theme');
+ const newTheme = currentTheme === 'light' ? 'dark' : 'light';
+ const themeBtn = document.getElementById('theme-toggle').querySelector('i');
+
+ body.setAttribute('data-theme', newTheme);
+ localStorage.setItem('theme', newTheme);
+
+ if (newTheme === 'light') {
+ themeBtn.classList.remove('bi-moon-fill');
+ themeBtn.classList.add('bi-sun-fill');
+ } else {
+ themeBtn.classList.remove('bi-sun-fill');
+ themeBtn.classList.add('bi-moon-fill');
+ }
+ }
+
+ // Initialize Theme
+ (function() {
+ const savedTheme = localStorage.getItem('theme') || 'dark';
+ if (savedTheme === 'light') {
+ document.body.setAttribute('data-theme', 'light');
+ const themeBtn = document.getElementById('theme-toggle').querySelector('i');
+ themeBtn.classList.remove('bi-moon-fill');
+ themeBtn.classList.add('bi-sun-fill');
+ }
+ })();
+
// Handle possible audio interruptions
audio.addEventListener('error', function(e) {
console.error('Audio error:', e);