sldshr commited on
Commit
7e128cb
·
verified ·
1 Parent(s): d96b931

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +123 -137
index.html CHANGED
@@ -22,9 +22,9 @@
22
  -webkit-tap-highlight-color: transparent;
23
  }
24
  input, textarea, [contenteditable="true"] { user-select: text; -webkit-user-select: text; }
25
- a, button, img, video { -webkit-user-drag: none; user-drag: none; }
26
 
27
- .btn, .card, .upload-zone, .modal-content, .lightbox, .custom-video-player { border-radius: 8px; }
28
  .card, .upload-zone, .modal-content { box-shadow: 0 4px 12px rgba(0,0,0,0.5); }
29
  .btn:active { filter: brightness(0.9); transform: translateY(1px); }
30
 
@@ -93,7 +93,15 @@
93
  border-radius: 8px;
94
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
95
  }
96
- .preview-item img, .preview-item video { width: 100%; height: 100%; object-fit: cover; }
 
 
 
 
 
 
 
 
97
  .preview-item .remove-btn {
98
  position: absolute;
99
  top: 4px;
@@ -139,7 +147,17 @@
139
  transition: border-color 0.2s, transform 0.1s;
140
  }
141
  .gallery-item:hover { border-color: #4a90e2; transform: scale(1.02); }
142
- .gallery-item img, .gallery-item video { width: 100%; height: 100%; object-fit: cover; loading: lazy; decoding: async; }
 
 
 
 
 
 
 
 
 
 
143
 
144
  .single-photo-view {
145
  background: #000;
@@ -149,7 +167,7 @@
149
  border-radius: 8px;
150
  overflow: hidden;
151
  }
152
- .single-photo-view img, .single-photo-view video { max-width: 100%; height: auto; display: block; margin: 0 auto; }
153
 
154
  /* Lightbox */
155
  .lightbox {
@@ -227,41 +245,26 @@
227
 
228
  .loader-view { position: absolute; inset: 0; background: #0f0f0f; z-index: 10; display: flex; align-items: center; justify-content: center; }
229
 
230
- /* Кастомный видеоплеер */
231
- .custom-video-player {
232
- position: relative;
233
- max-width: 95vw;
234
- height: 80vh;
235
- max-height: 80vh;
236
- background: #000;
237
  border: 1px solid #333;
 
 
238
  display: flex;
239
  flex-direction: column;
240
- overflow: hidden;
241
- border-radius: 8px;
242
- }
243
- .custom-video-player video {
244
- width: 100%;
245
- flex: 1;
246
- min-height: 0;
247
- object-fit: contain;
248
- background: #000;
249
- display: block;
250
- outline: none;
251
  }
252
- .video-controls {
253
  display: flex;
254
  align-items: center;
255
  gap: 8px;
256
- padding: 8px 10px;
257
- background: #1a1a1a;
258
- border-top: 1px solid #333;
259
- flex-wrap: nowrap;
260
- border-radius: 0 0 8px 8px;
261
- flex-shrink: 0;
262
- min-height: 40px;
263
  }
264
- .video-controls button {
265
  background: none;
266
  border: none;
267
  color: #fff;
@@ -277,8 +280,8 @@
277
  min-width: 40px;
278
  min-height: 40px;
279
  }
280
- .video-controls button:hover { color: #4a90e2; background: rgba(255,255,255,0.1); }
281
- .video-controls button svg { width: 22px; height: 22px; fill: currentColor; }
282
  .progress-container {
283
  flex: 1;
284
  height: 6px;
@@ -309,12 +312,9 @@
309
  cursor: pointer;
310
  }
311
  @media (max-width: 640px) {
312
- .custom-video-player {
313
- height: 70vh;
314
- max-height: 70vh;
315
- }
316
- .video-controls button { padding: 6px 8px; min-width: 36px; min-height: 36px; }
317
- .video-controls button svg { width: 20px; height: 20px; }
318
  .volume-slider { width: 60px; }
319
  }
320
  </style>
@@ -388,8 +388,8 @@
388
  window.pendingViews = {};
389
  window.viewSaveTimeout = null;
390
  let blobUrls = [];
391
- let currentVideoPlayer = null;
392
- let videoStates = {};
393
 
394
  function generateSlug(title) {
395
  let slug = title.toLowerCase().trim();
@@ -472,8 +472,6 @@
472
  window.renderPost(id);
473
  } else if (route === 'photo' && id && param) {
474
  window.renderPhoto(id, param);
475
- } else if (route === 'video' && id) {
476
- window.renderPost(id);
477
  } else {
478
  window.renderUploadPage();
479
  }
@@ -597,13 +595,13 @@
597
  const vc = document.getElementById('viewContainer');
598
  vc.innerHTML = `
599
  <div class="container">
600
- <h1 class="page-title">Загрузка изображений и видео</h1>
601
  <div class="card">
602
  <div class="upload-zone" id="uploadDropzone">
603
- <input type="file" id="upMediaFile" accept="image/*,video/*,.gif" multiple onchange="window.handleFilesSelect(event)">
604
  <span class="upload-icon">⇪</span>
605
- <h3>Выберите изображения, GIF или видео (до 50 файлов)</h3>
606
- <p>JPG, PNG, GIF, MP4, WebM и другие, суммарно до 5 ГБ</p>
607
  </div>
608
  <div id="previewContainer" class="preview-grid"></div>
609
 
@@ -642,12 +640,12 @@
642
  files.forEach((file, index) => {
643
  const blobUrl = URL.createObjectURL(file);
644
  window.uploadedBlobUrls.push(blobUrl);
645
- const isVideo = file.type.startsWith('video/');
646
  const item = document.createElement('div');
647
  item.className = 'preview-item';
648
- if (isVideo) {
649
  item.innerHTML = `
650
- <video src="${blobUrl}" muted playsinline></video>
651
  <div onclick="window.removeFile(${index})" class="remove-btn">&times;</div>
652
  `;
653
  } else {
@@ -671,12 +669,12 @@
671
  window.selectedFiles.forEach((file, i) => {
672
  const blobUrl = URL.createObjectURL(file);
673
  window.uploadedBlobUrls[i] = blobUrl;
674
- const isVideo = file.type.startsWith('video/');
675
  const item = document.createElement('div');
676
  item.className = 'preview-item';
677
- if (isVideo) {
678
  item.innerHTML = `
679
- <video src="${blobUrl}" muted playsinline></video>
680
  <div onclick="window.removeFile(${i})" class="remove-btn">&times;</div>
681
  `;
682
  } else {
@@ -743,7 +741,7 @@
743
  const filePath = `media/${postId}/${i}.${ext}`;
744
  const mediaUrl = `https://huggingface.co/datasets/${HF_REPO}/resolve/main/${filePath}`;
745
  extraOps.push({ operation: "addOrUpdate", path: filePath, content: file });
746
- const type = file.type.startsWith('video/') ? 'video' : (file.type.startsWith('image/gif') ? 'gif' : 'image');
747
  mediaItems.push({ url: mediaUrl, type: type });
748
  }
749
 
@@ -779,7 +777,7 @@
779
  <meta charset="UTF-8">
780
  <meta property="og:title" content="${title.replace(/"/g, '&quot;')}" />
781
  <meta property="og:description" content="${desc ? desc.replace(/"/g, '&quot;') : ''}" />
782
- <meta property="og:image" content="${firstMedia.type === 'video' ? '' : firstMedia.url}" />
783
  <meta property="og:url" content="${ogPageUrl}" />
784
  <meta property="og:type" content="website" />
785
  <title>${title}</title>
@@ -804,7 +802,7 @@
804
  description: desc,
805
  timestamp: metadataContent.timestamp,
806
  mediaItems,
807
- isVideo: mediaItems.some(item => item.type === 'video')
808
  };
809
 
810
  const success = await window.saveGlobalDB(extraOps, "Upload Post " + title);
@@ -851,7 +849,7 @@
851
  </button>
852
  </div>
853
  <div id="lightboxMediaContainer">
854
- <!-- Здесь будет либо img, либо кастомный видеоплеер -->
855
  </div>
856
  <div class="lightbox-controls">
857
  <button class="btn btn-secondary" id="prevBtn" onclick="window.navLightbox(-1)" title="Предыдущий файл">
@@ -871,7 +869,7 @@
871
  window.openLightbox(slug, 0);
872
  };
873
 
874
- // ==================== PHOTO PAGE (совместимость) ====================
875
  window.renderPhoto = (slug, index) => {
876
  const vc = document.getElementById('viewContainer');
877
  const post = window.globalDB.posts ? window.globalDB.posts[slug] : null;
@@ -886,8 +884,8 @@
886
  vc.innerHTML = `
887
  <div class="container" style="max-width: 800px;">
888
  <div class="single-photo-view">
889
- ${media.type === 'video'
890
- ? `<div id="single-video-container"></div>`
891
  : `<img src="${media.url}" loading="lazy" decoding="async" alt="media">`}
892
  </div>
893
  <div class="action-bar">
@@ -896,23 +894,23 @@
896
  </div>
897
  </div>
898
  `;
899
- if (media.type === 'video') {
900
- const container = document.getElementById('single-video-container');
901
  if (container) {
902
- const player = new CustomVideoPlayer(container, media.url, true);
903
- currentVideoPlayer = player;
904
  }
905
  }
906
  };
907
 
908
- // ==================== КЛАСС КАСТОМНОГО ВИДЕОПЛЕЕРА ====================
909
- class CustomVideoPlayer {
910
  constructor(container, src, autoPlay = false, initialState = null) {
911
  this.container = container;
912
  this.src = src;
913
  this.autoPlay = autoPlay;
914
  this.initialState = initialState;
915
- this.video = null;
916
  this.playPauseBtn = null;
917
  this.muteBtn = null;
918
  this.volumeSlider = null;
@@ -931,9 +929,9 @@
931
 
932
  init() {
933
  this.container.innerHTML = `
934
- <div class="custom-video-player">
935
- <video src="${this.src}" preload="auto" playsinline tabindex="0"></video>
936
- <div class="video-controls">
937
  <button class="play-pause-btn" title="Play/Pause">
938
  <svg viewBox="0 0 24 24"><path d="M8 5v14l11-7z"/></svg>
939
  </button>
@@ -949,7 +947,7 @@
949
  </div>
950
  `;
951
 
952
- this.video = this.container.querySelector('video');
953
  this.playPauseBtn = this.container.querySelector('.play-pause-btn');
954
  this.progressContainer = this.container.querySelector('.progress-container');
955
  this.progressFilled = this.container.querySelector('.progress-bar');
@@ -965,50 +963,50 @@
965
  document.addEventListener('mouseup', this._onMouseUp);
966
  document.addEventListener('touchend', this._onTouchEnd);
967
 
968
- this.video.addEventListener('loadedmetadata', () => {
969
- this.timeDuration.textContent = this.formatTime(this.video.duration);
970
  if (this.initialState && this.initialState.currentTime) {
971
- this.video.currentTime = this.initialState.currentTime;
972
  }
973
  if (this.initialState && this.initialState.volume !== undefined) {
974
- this.video.volume = this.initialState.volume;
975
  this.volumeSlider.value = this.initialState.volume;
976
  }
977
  if (this.initialState && this.initialState.paused !== undefined) {
978
  if (this.initialState.paused) {
979
- this.video.pause();
980
  } else {
981
- this.video.play().catch(e => console.log('Autoplay prevented'));
982
  }
983
  } else if (this.autoPlay) {
984
- this.video.play().catch(e => console.log('Autoplay prevented'));
985
  }
986
  });
987
 
988
- this.video.addEventListener('timeupdate', () => {
989
  if (!this.isDragging) {
990
- const percent = (this.video.currentTime / this.video.duration) * 100;
991
  this.progressFilled.style.width = percent + '%';
992
- this.timeCurrent.textContent = this.formatTime(this.video.currentTime);
993
  }
994
  });
995
- this.video.addEventListener('play', () => {
996
  this.playPauseBtn.innerHTML = '<svg viewBox="0 0 24 24"><path d="M6 19h4V5H6v14zm8-14v14h4V5h-4z"/></svg>';
997
  });
998
- this.video.addEventListener('pause', () => {
999
  this.playPauseBtn.innerHTML = '<svg viewBox="0 0 24 24"><path d="M8 5v14l11-7z"/></svg>';
1000
  });
1001
  this.playPauseBtn.addEventListener('click', () => this.togglePlay());
1002
- this.video.addEventListener('click', () => this.togglePlay());
1003
  this.muteBtn.addEventListener('click', () => this.toggleMute());
1004
  this.volumeSlider.addEventListener('input', (e) => {
1005
- this.video.volume = e.target.value;
1006
- this.video.muted = (e.target.value == 0);
1007
  this.updateMuteIcon();
1008
  });
1009
- this.video.addEventListener('keydown', (e) => this.handleKeydown(e));
1010
 
1011
- currentVideoPlayer = this;
1012
  }
1013
 
1014
  startDrag(e) {
@@ -1032,9 +1030,9 @@
1032
  let clientX = e.touches ? e.touches[0].clientX : e.clientX;
1033
  let pos = (clientX - rect.left) / rect.width;
1034
  pos = Math.max(0, Math.min(1, pos));
1035
- this.video.currentTime = pos * this.video.duration;
1036
  this.progressFilled.style.width = (pos * 100) + '%';
1037
- this.timeCurrent.textContent = this.formatTime(this.video.currentTime);
1038
  }
1039
 
1040
  handleKeydown(e) {
@@ -1043,46 +1041,46 @@
1043
  this.togglePlay();
1044
  } else if (e.code === 'ArrowLeft') {
1045
  e.preventDefault();
1046
- this.video.currentTime = Math.max(0, this.video.currentTime - 5);
1047
  } else if (e.code === 'ArrowRight') {
1048
  e.preventDefault();
1049
- this.video.currentTime = Math.min(this.video.duration, this.video.currentTime + 5);
1050
  } else if (e.code === 'ArrowUp') {
1051
  e.preventDefault();
1052
- this.video.volume = Math.min(1, this.video.volume + 0.1);
1053
- this.volumeSlider.value = this.video.volume;
1054
- this.video.muted = false;
1055
  this.updateMuteIcon();
1056
  } else if (e.code === 'ArrowDown') {
1057
  e.preventDefault();
1058
- this.video.volume = Math.max(0, this.video.volume - 0.1);
1059
- this.volumeSlider.value = this.video.volume;
1060
- if (this.video.volume === 0) this.video.muted = true;
1061
  this.updateMuteIcon();
1062
  }
1063
  }
1064
 
1065
  togglePlay() {
1066
- if (this.video.paused) {
1067
- this.video.play();
1068
  } else {
1069
- this.video.pause();
1070
  }
1071
  }
1072
 
1073
  toggleMute() {
1074
- this.video.muted = !this.video.muted;
1075
  this.updateMuteIcon();
1076
  }
1077
 
1078
  updateMuteIcon() {
1079
- if (this.video.muted || this.video.volume === 0) {
1080
  this.muteBtn.innerHTML = '<svg viewBox="0 0 24 24"><path d="M16.5 12c0-1.77-1.02-3.29-2.5-4.03v2.21l2.45 2.45c.03-.2.05-.41.05-.63zm2.5 0c0 .94-.2 1.82-.54 2.64l1.51 1.51C20.63 14.91 21 13.5 21 12c0-4.28-2.99-7.86-7-8.77v2.06c2.89.86 5 3.54 5 6.71zM4.27 3L3 4.27 7.73 9H3v6h4l5 5v-6.73l4.25 4.25c-.67.52-1.42.93-2.25 1.18v2.06c1.38-.31 2.63-.95 3.69-1.81L19.73 21 21 19.73l-9-9L4.27 3zM12 4L9.91 6.09 12 8.18V4z"/></svg>';
1081
  } else {
1082
  this.muteBtn.innerHTML = '<svg viewBox="0 0 24 24"><path d="M3 9v6h4l5 5V4L7 9H3zm13.5 3c0-1.77-1.02-3.29-2.5-4.03v8.05c1.48-.73 2.5-2.25 2.5-4.02zM14 3.23v2.06c2.89.86 5 3.54 5 6.71s-2.11 5.85-5 6.71v2.06c4.01-.91 7-4.49 7-8.77s-2.99-7.86-7-8.77z"/></svg>';
1083
  }
1084
- if (this.video.volume > 0 && !this.video.muted) {
1085
- this.volumeSlider.value = this.video.volume;
1086
  } else {
1087
  this.volumeSlider.value = 0;
1088
  }
@@ -1097,24 +1095,24 @@
1097
 
1098
  saveState() {
1099
  return {
1100
- currentTime: this.video.currentTime,
1101
- volume: this.video.volume,
1102
- paused: this.video.paused
1103
  };
1104
  }
1105
 
1106
  destroy() {
1107
- if (this.video) {
1108
- videoStates[this.container.dataset.stateKey] = this.saveState();
1109
- this.video.pause();
1110
- this.video.src = '';
1111
- this.video.load();
1112
  }
1113
  document.removeEventListener('mousemove', this._onMouseMove);
1114
  document.removeEventListener('touchmove', this._onTouchMove);
1115
  document.removeEventListener('mouseup', this._onMouseUp);
1116
  document.removeEventListener('touchend', this._onTouchEnd);
1117
- currentVideoPlayer = null;
1118
  }
1119
  }
1120
 
@@ -1130,26 +1128,20 @@
1130
  const prevBtn = document.getElementById('prevBtn');
1131
  const nextBtn = document.getElementById('nextBtn');
1132
 
1133
- const oldVideo = container.querySelector('video');
1134
- if (oldVideo) {
1135
- oldVideo.pause();
1136
- oldVideo.src = '';
1137
- oldVideo.load();
1138
- }
1139
- if (currentVideoPlayer) {
1140
- currentVideoPlayer.destroy();
1141
- currentVideoPlayer = null;
1142
  }
1143
 
1144
  const media = post.mediaItems[index];
1145
  container.innerHTML = '';
1146
 
1147
- if (media.type === 'video') {
1148
  const stateKey = `${slug}_${index}`;
1149
  container.dataset.stateKey = stateKey;
1150
- const savedState = videoStates[stateKey] || null;
1151
- const player = new CustomVideoPlayer(container, media.url, true, savedState);
1152
- currentVideoPlayer = player;
1153
  } else {
1154
  const img = document.createElement('img');
1155
  img.src = media.url;
@@ -1167,15 +1159,9 @@
1167
  window.closeLightbox = () => {
1168
  const lightbox = document.getElementById('lightbox');
1169
  if (lightbox) {
1170
- const video = lightbox.querySelector('video');
1171
- if (video) {
1172
- video.pause();
1173
- video.src = '';
1174
- video.load();
1175
- }
1176
- if (currentVideoPlayer) {
1177
- currentVideoPlayer.destroy();
1178
- currentVideoPlayer = null;
1179
  }
1180
  lightbox.classList.add('hidden');
1181
  }
 
22
  -webkit-tap-highlight-color: transparent;
23
  }
24
  input, textarea, [contenteditable="true"] { user-select: text; -webkit-user-select: text; }
25
+ a, button, img, audio { -webkit-user-drag: none; user-drag: none; }
26
 
27
+ .btn, .card, .upload-zone, .modal-content, .lightbox, .custom-audio-player { border-radius: 8px; }
28
  .card, .upload-zone, .modal-content { box-shadow: 0 4px 12px rgba(0,0,0,0.5); }
29
  .btn:active { filter: brightness(0.9); transform: translateY(1px); }
30
 
 
93
  border-radius: 8px;
94
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
95
  }
96
+ .preview-item img, .preview-item .audio-placeholder { width: 100%; height: 100%; object-fit: cover; }
97
+ .preview-item .audio-placeholder {
98
+ display: flex;
99
+ align-items: center;
100
+ justify-content: center;
101
+ font-size: 48px;
102
+ color: #777;
103
+ background: #1a1a1a;
104
+ }
105
  .preview-item .remove-btn {
106
  position: absolute;
107
  top: 4px;
 
147
  transition: border-color 0.2s, transform 0.1s;
148
  }
149
  .gallery-item:hover { border-color: #4a90e2; transform: scale(1.02); }
150
+ .gallery-item img { width: 100%; height: 100%; object-fit: cover; loading: lazy; decoding: async; }
151
+ .gallery-item .audio-placeholder {
152
+ width: 100%;
153
+ height: 100%;
154
+ display: flex;
155
+ align-items: center;
156
+ justify-content: center;
157
+ font-size: 48px;
158
+ color: #777;
159
+ background: #1a1a1a;
160
+ }
161
 
162
  .single-photo-view {
163
  background: #000;
 
167
  border-radius: 8px;
168
  overflow: hidden;
169
  }
170
+ .single-photo-view img { max-width: 100%; height: auto; display: block; margin: 0 auto; }
171
 
172
  /* Lightbox */
173
  .lightbox {
 
245
 
246
  .loader-view { position: absolute; inset: 0; background: #0f0f0f; z-index: 10; display: flex; align-items: center; justify-content: center; }
247
 
248
+ /* Кастомный аудиоплеер */
249
+ .custom-audio-player {
250
+ width: 90%;
251
+ max-width: 500px;
252
+ background: #1a1a1a;
 
 
253
  border: 1px solid #333;
254
+ border-radius: 8px;
255
+ padding: 16px;
256
  display: flex;
257
  flex-direction: column;
258
+ gap: 12px;
259
+ box-shadow: 0 4px 12px rgba(0,0,0,0.5);
 
 
 
 
 
 
 
 
 
260
  }
261
+ .audio-controls {
262
  display: flex;
263
  align-items: center;
264
  gap: 8px;
265
+ flex-wrap: wrap;
 
 
 
 
 
 
266
  }
267
+ .audio-controls button {
268
  background: none;
269
  border: none;
270
  color: #fff;
 
280
  min-width: 40px;
281
  min-height: 40px;
282
  }
283
+ .audio-controls button:hover { color: #4a90e2; background: rgba(255,255,255,0.1); }
284
+ .audio-controls button svg { width: 22px; height: 22px; fill: currentColor; }
285
  .progress-container {
286
  flex: 1;
287
  height: 6px;
 
312
  cursor: pointer;
313
  }
314
  @media (max-width: 640px) {
315
+ .custom-audio-player { width: 95%; }
316
+ .audio-controls button { padding: 6px 8px; min-width: 36px; min-height: 36px; }
317
+ .audio-controls button svg { width: 20px; height: 20px; }
 
 
 
318
  .volume-slider { width: 60px; }
319
  }
320
  </style>
 
388
  window.pendingViews = {};
389
  window.viewSaveTimeout = null;
390
  let blobUrls = [];
391
+ let currentAudioPlayer = null;
392
+ let audioStates = {};
393
 
394
  function generateSlug(title) {
395
  let slug = title.toLowerCase().trim();
 
472
  window.renderPost(id);
473
  } else if (route === 'photo' && id && param) {
474
  window.renderPhoto(id, param);
 
 
475
  } else {
476
  window.renderUploadPage();
477
  }
 
595
  const vc = document.getElementById('viewContainer');
596
  vc.innerHTML = `
597
  <div class="container">
598
+ <h1 class="page-title">Загрузка изображений и аудио</h1>
599
  <div class="card">
600
  <div class="upload-zone" id="uploadDropzone">
601
+ <input type="file" id="upMediaFile" accept="image/*,audio/*,.gif" multiple onchange="window.handleFilesSelect(event)">
602
  <span class="upload-icon">⇪</span>
603
+ <h3>Выберите изображения, GIF или аудио (до 50 файлов)</h3>
604
+ <p>JPG, PNG, GIF, MP3, WAV, OGG и другие, суммарно до 5 ГБ</p>
605
  </div>
606
  <div id="previewContainer" class="preview-grid"></div>
607
 
 
640
  files.forEach((file, index) => {
641
  const blobUrl = URL.createObjectURL(file);
642
  window.uploadedBlobUrls.push(blobUrl);
643
+ const isAudio = file.type.startsWith('audio/');
644
  const item = document.createElement('div');
645
  item.className = 'preview-item';
646
+ if (isAudio) {
647
  item.innerHTML = `
648
+ <div class="audio-placeholder">🎵</div>
649
  <div onclick="window.removeFile(${index})" class="remove-btn">&times;</div>
650
  `;
651
  } else {
 
669
  window.selectedFiles.forEach((file, i) => {
670
  const blobUrl = URL.createObjectURL(file);
671
  window.uploadedBlobUrls[i] = blobUrl;
672
+ const isAudio = file.type.startsWith('audio/');
673
  const item = document.createElement('div');
674
  item.className = 'preview-item';
675
+ if (isAudio) {
676
  item.innerHTML = `
677
+ <div class="audio-placeholder">🎵</div>
678
  <div onclick="window.removeFile(${i})" class="remove-btn">&times;</div>
679
  `;
680
  } else {
 
741
  const filePath = `media/${postId}/${i}.${ext}`;
742
  const mediaUrl = `https://huggingface.co/datasets/${HF_REPO}/resolve/main/${filePath}`;
743
  extraOps.push({ operation: "addOrUpdate", path: filePath, content: file });
744
+ const type = file.type.startsWith('audio/') ? 'audio' : (file.type.startsWith('image/gif') ? 'gif' : 'image');
745
  mediaItems.push({ url: mediaUrl, type: type });
746
  }
747
 
 
777
  <meta charset="UTF-8">
778
  <meta property="og:title" content="${title.replace(/"/g, '&quot;')}" />
779
  <meta property="og:description" content="${desc ? desc.replace(/"/g, '&quot;') : ''}" />
780
+ <meta property="og:image" content="${firstMedia.type === 'image' ? firstMedia.url : ''}" />
781
  <meta property="og:url" content="${ogPageUrl}" />
782
  <meta property="og:type" content="website" />
783
  <title>${title}</title>
 
802
  description: desc,
803
  timestamp: metadataContent.timestamp,
804
  mediaItems,
805
+ isAudio: mediaItems.some(item => item.type === 'audio')
806
  };
807
 
808
  const success = await window.saveGlobalDB(extraOps, "Upload Post " + title);
 
849
  </button>
850
  </div>
851
  <div id="lightboxMediaContainer">
852
+ <!-- Здесь будет либо изображение, либо кастомный аудиоплеер -->
853
  </div>
854
  <div class="lightbox-controls">
855
  <button class="btn btn-secondary" id="prevBtn" onclick="window.navLightbox(-1)" title="Предыдущий файл">
 
869
  window.openLightbox(slug, 0);
870
  };
871
 
872
+ // ==================== ФОТО СТРАНИЦА (совместимость) ====================
873
  window.renderPhoto = (slug, index) => {
874
  const vc = document.getElementById('viewContainer');
875
  const post = window.globalDB.posts ? window.globalDB.posts[slug] : null;
 
884
  vc.innerHTML = `
885
  <div class="container" style="max-width: 800px;">
886
  <div class="single-photo-view">
887
+ ${media.type === 'audio'
888
+ ? `<div id="single-audio-container"></div>`
889
  : `<img src="${media.url}" loading="lazy" decoding="async" alt="media">`}
890
  </div>
891
  <div class="action-bar">
 
894
  </div>
895
  </div>
896
  `;
897
+ if (media.type === 'audio') {
898
+ const container = document.getElementById('single-audio-container');
899
  if (container) {
900
+ const player = new CustomAudioPlayer(container, media.url, true);
901
+ currentAudioPlayer = player;
902
  }
903
  }
904
  };
905
 
906
+ // ==================== КЛАСС КАСТОМНОГО АУДИОПЛЕЕРА ====================
907
+ class CustomAudioPlayer {
908
  constructor(container, src, autoPlay = false, initialState = null) {
909
  this.container = container;
910
  this.src = src;
911
  this.autoPlay = autoPlay;
912
  this.initialState = initialState;
913
+ this.audio = null;
914
  this.playPauseBtn = null;
915
  this.muteBtn = null;
916
  this.volumeSlider = null;
 
929
 
930
  init() {
931
  this.container.innerHTML = `
932
+ <div class="custom-audio-player">
933
+ <audio src="${this.src}" preload="auto" tabindex="0"></audio>
934
+ <div class="audio-controls">
935
  <button class="play-pause-btn" title="Play/Pause">
936
  <svg viewBox="0 0 24 24"><path d="M8 5v14l11-7z"/></svg>
937
  </button>
 
947
  </div>
948
  `;
949
 
950
+ this.audio = this.container.querySelector('audio');
951
  this.playPauseBtn = this.container.querySelector('.play-pause-btn');
952
  this.progressContainer = this.container.querySelector('.progress-container');
953
  this.progressFilled = this.container.querySelector('.progress-bar');
 
963
  document.addEventListener('mouseup', this._onMouseUp);
964
  document.addEventListener('touchend', this._onTouchEnd);
965
 
966
+ this.audio.addEventListener('loadedmetadata', () => {
967
+ this.timeDuration.textContent = this.formatTime(this.audio.duration);
968
  if (this.initialState && this.initialState.currentTime) {
969
+ this.audio.currentTime = this.initialState.currentTime;
970
  }
971
  if (this.initialState && this.initialState.volume !== undefined) {
972
+ this.audio.volume = this.initialState.volume;
973
  this.volumeSlider.value = this.initialState.volume;
974
  }
975
  if (this.initialState && this.initialState.paused !== undefined) {
976
  if (this.initialState.paused) {
977
+ this.audio.pause();
978
  } else {
979
+ this.audio.play().catch(e => console.log('Autoplay prevented'));
980
  }
981
  } else if (this.autoPlay) {
982
+ this.audio.play().catch(e => console.log('Autoplay prevented'));
983
  }
984
  });
985
 
986
+ this.audio.addEventListener('timeupdate', () => {
987
  if (!this.isDragging) {
988
+ const percent = (this.audio.currentTime / this.audio.duration) * 100;
989
  this.progressFilled.style.width = percent + '%';
990
+ this.timeCurrent.textContent = this.formatTime(this.audio.currentTime);
991
  }
992
  });
993
+ this.audio.addEventListener('play', () => {
994
  this.playPauseBtn.innerHTML = '<svg viewBox="0 0 24 24"><path d="M6 19h4V5H6v14zm8-14v14h4V5h-4z"/></svg>';
995
  });
996
+ this.audio.addEventListener('pause', () => {
997
  this.playPauseBtn.innerHTML = '<svg viewBox="0 0 24 24"><path d="M8 5v14l11-7z"/></svg>';
998
  });
999
  this.playPauseBtn.addEventListener('click', () => this.togglePlay());
1000
+ this.audio.addEventListener('click', () => this.togglePlay());
1001
  this.muteBtn.addEventListener('click', () => this.toggleMute());
1002
  this.volumeSlider.addEventListener('input', (e) => {
1003
+ this.audio.volume = e.target.value;
1004
+ this.audio.muted = (e.target.value == 0);
1005
  this.updateMuteIcon();
1006
  });
1007
+ this.audio.addEventListener('keydown', (e) => this.handleKeydown(e));
1008
 
1009
+ currentAudioPlayer = this;
1010
  }
1011
 
1012
  startDrag(e) {
 
1030
  let clientX = e.touches ? e.touches[0].clientX : e.clientX;
1031
  let pos = (clientX - rect.left) / rect.width;
1032
  pos = Math.max(0, Math.min(1, pos));
1033
+ this.audio.currentTime = pos * this.audio.duration;
1034
  this.progressFilled.style.width = (pos * 100) + '%';
1035
+ this.timeCurrent.textContent = this.formatTime(this.audio.currentTime);
1036
  }
1037
 
1038
  handleKeydown(e) {
 
1041
  this.togglePlay();
1042
  } else if (e.code === 'ArrowLeft') {
1043
  e.preventDefault();
1044
+ this.audio.currentTime = Math.max(0, this.audio.currentTime - 5);
1045
  } else if (e.code === 'ArrowRight') {
1046
  e.preventDefault();
1047
+ this.audio.currentTime = Math.min(this.audio.duration, this.audio.currentTime + 5);
1048
  } else if (e.code === 'ArrowUp') {
1049
  e.preventDefault();
1050
+ this.audio.volume = Math.min(1, this.audio.volume + 0.1);
1051
+ this.volumeSlider.value = this.audio.volume;
1052
+ this.audio.muted = false;
1053
  this.updateMuteIcon();
1054
  } else if (e.code === 'ArrowDown') {
1055
  e.preventDefault();
1056
+ this.audio.volume = Math.max(0, this.audio.volume - 0.1);
1057
+ this.volumeSlider.value = this.audio.volume;
1058
+ if (this.audio.volume === 0) this.audio.muted = true;
1059
  this.updateMuteIcon();
1060
  }
1061
  }
1062
 
1063
  togglePlay() {
1064
+ if (this.audio.paused) {
1065
+ this.audio.play();
1066
  } else {
1067
+ this.audio.pause();
1068
  }
1069
  }
1070
 
1071
  toggleMute() {
1072
+ this.audio.muted = !this.audio.muted;
1073
  this.updateMuteIcon();
1074
  }
1075
 
1076
  updateMuteIcon() {
1077
+ if (this.audio.muted || this.audio.volume === 0) {
1078
  this.muteBtn.innerHTML = '<svg viewBox="0 0 24 24"><path d="M16.5 12c0-1.77-1.02-3.29-2.5-4.03v2.21l2.45 2.45c.03-.2.05-.41.05-.63zm2.5 0c0 .94-.2 1.82-.54 2.64l1.51 1.51C20.63 14.91 21 13.5 21 12c0-4.28-2.99-7.86-7-8.77v2.06c2.89.86 5 3.54 5 6.71zM4.27 3L3 4.27 7.73 9H3v6h4l5 5v-6.73l4.25 4.25c-.67.52-1.42.93-2.25 1.18v2.06c1.38-.31 2.63-.95 3.69-1.81L19.73 21 21 19.73l-9-9L4.27 3zM12 4L9.91 6.09 12 8.18V4z"/></svg>';
1079
  } else {
1080
  this.muteBtn.innerHTML = '<svg viewBox="0 0 24 24"><path d="M3 9v6h4l5 5V4L7 9H3zm13.5 3c0-1.77-1.02-3.29-2.5-4.03v8.05c1.48-.73 2.5-2.25 2.5-4.02zM14 3.23v2.06c2.89.86 5 3.54 5 6.71s-2.11 5.85-5 6.71v2.06c4.01-.91 7-4.49 7-8.77s-2.99-7.86-7-8.77z"/></svg>';
1081
  }
1082
+ if (this.audio.volume > 0 && !this.audio.muted) {
1083
+ this.volumeSlider.value = this.audio.volume;
1084
  } else {
1085
  this.volumeSlider.value = 0;
1086
  }
 
1095
 
1096
  saveState() {
1097
  return {
1098
+ currentTime: this.audio.currentTime,
1099
+ volume: this.audio.volume,
1100
+ paused: this.audio.paused
1101
  };
1102
  }
1103
 
1104
  destroy() {
1105
+ if (this.audio) {
1106
+ audioStates[this.container.dataset.stateKey] = this.saveState();
1107
+ this.audio.pause();
1108
+ this.audio.src = '';
1109
+ this.audio.load();
1110
  }
1111
  document.removeEventListener('mousemove', this._onMouseMove);
1112
  document.removeEventListener('touchmove', this._onTouchMove);
1113
  document.removeEventListener('mouseup', this._onMouseUp);
1114
  document.removeEventListener('touchend', this._onTouchEnd);
1115
+ currentAudioPlayer = null;
1116
  }
1117
  }
1118
 
 
1128
  const prevBtn = document.getElementById('prevBtn');
1129
  const nextBtn = document.getElementById('nextBtn');
1130
 
1131
+ if (currentAudioPlayer) {
1132
+ currentAudioPlayer.destroy();
1133
+ currentAudioPlayer = null;
 
 
 
 
 
 
1134
  }
1135
 
1136
  const media = post.mediaItems[index];
1137
  container.innerHTML = '';
1138
 
1139
+ if (media.type === 'audio') {
1140
  const stateKey = `${slug}_${index}`;
1141
  container.dataset.stateKey = stateKey;
1142
+ const savedState = audioStates[stateKey] || null;
1143
+ const player = new CustomAudioPlayer(container, media.url, true, savedState);
1144
+ currentAudioPlayer = player;
1145
  } else {
1146
  const img = document.createElement('img');
1147
  img.src = media.url;
 
1159
  window.closeLightbox = () => {
1160
  const lightbox = document.getElementById('lightbox');
1161
  if (lightbox) {
1162
+ if (currentAudioPlayer) {
1163
+ currentAudioPlayer.destroy();
1164
+ currentAudioPlayer = null;
 
 
 
 
 
 
1165
  }
1166
  lightbox.classList.add('hidden');
1167
  }