Ivan000 commited on
Commit
bdff6a9
·
verified ·
1 Parent(s): a1e2ea5

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +109 -4
templates/index.html CHANGED
@@ -77,6 +77,93 @@
77
  </div>
78
 
79
  <script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  function playAudio() {
81
  const url = $('#youtubeUrl').val().trim();
82
  if (!url) {
@@ -97,15 +184,17 @@
97
  success: function(response) {
98
  const blob = new Blob([response], { type: 'audio/mp3' });
99
  const audioUrl = URL.createObjectURL(blob);
100
-
101
  const videoInfoContainer = document.querySelector('#videoInfo .p-6');
 
102
  const existingAudioPlayers = videoInfoContainer.querySelectorAll('audio');
103
  existingAudioPlayers.forEach(player => player.remove());
104
-
105
  const audioPlayer = document.createElement('audio');
106
  audioPlayer.src = audioUrl;
107
  audioPlayer.controls = true;
108
-
 
109
  audioPlayer.autoplay = true;
110
 
111
  videoInfoContainer.appendChild(audioPlayer);
@@ -119,6 +208,22 @@
119
  }
120
  });
121
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
  </script>
123
  </body>
124
- </html>
 
77
  </div>
78
 
79
  <script>
80
+ const Toast = Swal.mixin({
81
+ toast: true,
82
+ position: 'top-end',
83
+ showConfirmButton: false,
84
+ timer: 3000,
85
+ timerProgressBar: true,
86
+ didOpen: (toast) => {
87
+ toast.addEventListener('mouseenter', Swal.stopTimer)
88
+ toast.addEventListener('mouseleave', Swal.resumeTimer)
89
+ }
90
+ });
91
+
92
+ function showLoading(message) {
93
+ return Swal.fire({
94
+ html: `
95
+ <div class="space-y-3">
96
+ <div class="w-16 h-16 mx-auto border-4 border-gray-200 border-t-blue-500 rounded-full animate-spin"></div>
97
+ <div class="text-gray-600 text-sm">${message}</div>
98
+ </div>
99
+ `,
100
+ showConfirmButton: false,
101
+ allowOutsideClick: false,
102
+ background: '#ffffff',
103
+ customClass: {
104
+ popup: 'rounded-2xl'
105
+ }
106
+ });
107
+ }
108
+
109
+ function showSuccess(message) {
110
+ Toast.fire({
111
+ icon: 'success',
112
+ title: message,
113
+ background: '#F0FDF4',
114
+ iconColor: '#22C55E'
115
+ });
116
+ }
117
+
118
+ function showError(message) {
119
+ Toast.fire({
120
+ icon: 'error',
121
+ title: message,
122
+ background: '#FEF2F2',
123
+ iconColor: '#EF4444'
124
+ });
125
+ }
126
+
127
+ function formatDuration(seconds) {
128
+ const minutes = Math.floor(seconds / 60);
129
+ const remainingSeconds = seconds % 60;
130
+ return `${minutes}:${remainingSeconds.toString().padStart(2, '0')}`;
131
+ }
132
+
133
+ function getVideoInfo() {
134
+ const url = $('#youtubeUrl').val().trim();
135
+ if (!url) {
136
+ showError('Please enter a YouTube URL');
137
+ return;
138
+ }
139
+
140
+ showLoading('Fetching video information...');
141
+ $('#videoInfo').addClass('hidden');
142
+
143
+ $.ajax({
144
+ url: '/get-info',
145
+ type: 'POST',
146
+ contentType: 'application/json',
147
+ data: JSON.stringify({ url: url }),
148
+ success: function(response) {
149
+ $('#thumbnailContainer').html(`
150
+ <img src="${response.thumbnail}" alt="Video Thumbnail"
151
+ class="w-full object-cover transition-transform duration-300 hover:scale-105">
152
+ `);
153
+ $('#videoTitle').text(response.title);
154
+ $('#channelName span').text(response.channel);
155
+ $('#duration span').text(formatDuration(response.duration));
156
+ $('#videoInfo').removeClass('hidden');
157
+ Swal.close();
158
+ showSuccess('Video information retrieved');
159
+ },
160
+ error: function(xhr) {
161
+ Swal.close();
162
+ showError(xhr.responseJSON?.error || 'Failed to get video information');
163
+ }
164
+ });
165
+ }
166
+
167
  function playAudio() {
168
  const url = $('#youtubeUrl').val().trim();
169
  if (!url) {
 
184
  success: function(response) {
185
  const blob = new Blob([response], { type: 'audio/mp3' });
186
  const audioUrl = URL.createObjectURL(blob);
187
+
188
  const videoInfoContainer = document.querySelector('#videoInfo .p-6');
189
+ // Remove any existing audio players
190
  const existingAudioPlayers = videoInfoContainer.querySelectorAll('audio');
191
  existingAudioPlayers.forEach(player => player.remove());
192
+
193
  const audioPlayer = document.createElement('audio');
194
  audioPlayer.src = audioUrl;
195
  audioPlayer.controls = true;
196
+ audioPlayer.style.width = '100%';
197
+ audioPlayer.style.marginTop = '1rem';
198
  audioPlayer.autoplay = true;
199
 
200
  videoInfoContainer.appendChild(audioPlayer);
 
208
  }
209
  });
210
  }
211
+
212
+ // Smooth page load animation
213
+ document.addEventListener('DOMContentLoaded', () => {
214
+ requestAnimationFrame(() => {
215
+ document.body.style.opacity = '0';
216
+ requestAnimationFrame(() => {
217
+ document.body.style.transition = 'opacity 0.5s ease-in';
218
+ document.body.style.opacity = '1';
219
+ });
220
+ });
221
+ });
222
+
223
+ // Check system dark mode preference
224
+ if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
225
+ document.documentElement.classList.add('dark');
226
+ }
227
  </script>
228
  </body>
229
+ </html>