Random mode
This commit is contained in:
@@ -59,9 +59,12 @@ class EncryptedVideoScroller {
|
|||||||
this.auth = auth;
|
this.auth = auth;
|
||||||
this.currentIndex = 0;
|
this.currentIndex = 0;
|
||||||
this.videos = [];
|
this.videos = [];
|
||||||
|
this.sequentialVideos = [];
|
||||||
|
this.randomMode = false;
|
||||||
this.isLoading = false;
|
this.isLoading = false;
|
||||||
this.container = document.getElementById('videoContainer');
|
this.container = document.getElementById('videoContainer');
|
||||||
this.loadingEl = document.getElementById('loading');
|
this.loadingEl = document.getElementById('loading');
|
||||||
|
this.randomBtn = document.getElementById('randomBtn');
|
||||||
this.touchStartY = 0;
|
this.touchStartY = 0;
|
||||||
this.touchEndY = 0;
|
this.touchEndY = 0;
|
||||||
this.isDragging = false;
|
this.isDragging = false;
|
||||||
@@ -94,6 +97,11 @@ class EncryptedVideoScroller {
|
|||||||
this.toggleHeader();
|
this.toggleHeader();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Random mode toggle button
|
||||||
|
if (this.randomBtn) {
|
||||||
|
this.randomBtn.addEventListener('click', () => this.toggleRandomMode());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleHeader() {
|
toggleHeader() {
|
||||||
@@ -161,7 +169,10 @@ class EncryptedVideoScroller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const newVideos = await response.json();
|
const newVideos = await response.json();
|
||||||
this.videos = newVideos;
|
this.sequentialVideos = newVideos;
|
||||||
|
this.videos = [...newVideos];
|
||||||
|
this.randomMode = false;
|
||||||
|
this.updateRandomButton();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error loading videos:', error);
|
console.error('Error loading videos:', error);
|
||||||
this.showLoadingError();
|
this.showLoadingError();
|
||||||
@@ -388,6 +399,26 @@ class EncryptedVideoScroller {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toggleRandomMode() {
|
||||||
|
this.randomMode = !this.randomMode;
|
||||||
|
if (this.randomMode) {
|
||||||
|
// Shuffle videos array using Fisher-Yates shuffle
|
||||||
|
this.videos = [...this.videos].sort(() => Math.random() - 0.5);
|
||||||
|
} else {
|
||||||
|
// Restore original order
|
||||||
|
this.videos = [...this.sequentialVideos];
|
||||||
|
}
|
||||||
|
this.currentIndex = 0;
|
||||||
|
this.renderVideos();
|
||||||
|
this.updateRandomButton();
|
||||||
|
}
|
||||||
|
|
||||||
|
updateRandomButton() {
|
||||||
|
if (this.randomBtn) {
|
||||||
|
this.randomBtn.textContent = this.randomMode ? 'Random ▼' : 'Sequential ▼';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
showLoading() {
|
showLoading() {
|
||||||
this.isLoading = true;
|
this.isLoading = true;
|
||||||
this.loadingEl.classList.add('show');
|
this.loadingEl.classList.add('show');
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
<div class="app-header">
|
<div class="app-header">
|
||||||
<h2>Private Videos</h2>
|
<h2>Private Videos</h2>
|
||||||
<div class="header-buttons">
|
<div class="header-buttons">
|
||||||
|
<button id="randomBtn" class="btn-small">Sequential ▼</button>
|
||||||
<button id="uploadBtn" class="btn-small">+ Upload</button>
|
<button id="uploadBtn" class="btn-small">+ Upload</button>
|
||||||
<button id="logoutBtn" class="btn-small">Logout</button>
|
<button id="logoutBtn" class="btn-small">Logout</button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user