app.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. function showMessage(text, type = 'success') {
  2. const messageEl = document.getElementById('message');
  3. messageEl.textContent = text;
  4. messageEl.className = `message ${type}`;
  5. setTimeout(() => {
  6. messageEl.className = 'message hidden';
  7. }, 5000);
  8. }
  9. async function syncLibrary() {
  10. showMessage('Syncing with Audiobookshelf...', 'success');
  11. try {
  12. const response = await fetch('/api/sync');
  13. const data = await response.json();
  14. if (data.status === 'success') {
  15. showMessage(data.message, 'success');
  16. setTimeout(() => window.location.reload(), 1500);
  17. } else {
  18. showMessage(data.message || 'Sync failed', 'error');
  19. }
  20. } catch (error) {
  21. showMessage('Error syncing with Audiobookshelf: ' + error.message, 'error');
  22. }
  23. }
  24. async function generateRecommendations() {
  25. showMessage('Generating AI recommendations...', 'success');
  26. try {
  27. const response = await fetch('/api/recommendations/generate');
  28. const data = await response.json();
  29. if (data.status === 'success') {
  30. showMessage(`Generated ${data.count} new recommendations!`, 'success');
  31. setTimeout(() => window.location.reload(), 1500);
  32. } else {
  33. showMessage(data.message || 'Failed to generate recommendations', 'error');
  34. }
  35. } catch (error) {
  36. showMessage('Error generating recommendations: ' + error.message, 'error');
  37. }
  38. }