|
|
@@ -607,6 +607,69 @@ document.addEventListener("alpine:init", () => {
|
|
|
}
|
|
|
},
|
|
|
|
|
|
+ async moveVideoToTop(playlistName, index) {
|
|
|
+ const playlists = JSON.parse(JSON.stringify(this.playlists));
|
|
|
+ const playlist = [...playlists[playlistName]];
|
|
|
+
|
|
|
+ const topPosition = this.findTopPosition(playlistName);
|
|
|
+
|
|
|
+ if (index === topPosition) return;
|
|
|
+
|
|
|
+ const video = playlist.splice(index, 1)[0];
|
|
|
+ playlist.splice(topPosition, 0, video);
|
|
|
+
|
|
|
+ const updatedPlaylists = {
|
|
|
+ ...playlists,
|
|
|
+ [playlistName]: playlist,
|
|
|
+ };
|
|
|
+
|
|
|
+ try {
|
|
|
+ await browser.storage.local.set({ playlists: updatedPlaylists });
|
|
|
+ this.playlists = updatedPlaylists;
|
|
|
+ this.updatePlaylistsForDisplay();
|
|
|
+ this.updateCurrentPlaylistVideos();
|
|
|
+ } catch (error) {
|
|
|
+ console.error("Error moving video to top:", error);
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ async moveVideoToBottom(playlistName, index) {
|
|
|
+ const playlists = JSON.parse(JSON.stringify(this.playlists));
|
|
|
+ const playlist = [...playlists[playlistName]];
|
|
|
+
|
|
|
+ if (index === playlist.length - 1) return;
|
|
|
+
|
|
|
+ const video = playlist.splice(index, 1)[0];
|
|
|
+ playlist.push(video);
|
|
|
+
|
|
|
+ const updatedPlaylists = {
|
|
|
+ ...playlists,
|
|
|
+ [playlistName]: playlist,
|
|
|
+ };
|
|
|
+
|
|
|
+ try {
|
|
|
+ await browser.storage.local.set({ playlists: updatedPlaylists });
|
|
|
+ this.playlists = updatedPlaylists;
|
|
|
+ this.updatePlaylistsForDisplay();
|
|
|
+ this.updateCurrentPlaylistVideos();
|
|
|
+ } catch (error) {
|
|
|
+ console.error("Error moving video to bottom:", error);
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ findTopPosition(playlistName) {
|
|
|
+ const playlist = this.playlists[playlistName];
|
|
|
+ if (!playlist) return 0;
|
|
|
+
|
|
|
+ for (let i = 0; i < playlist.length; i++) {
|
|
|
+ if (playlist[i].status !== "done") {
|
|
|
+ return i;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return playlist.length;
|
|
|
+ },
|
|
|
+
|
|
|
async toggleVideoDoneStatus(playlistName, index) {
|
|
|
const playlists = JSON.parse(JSON.stringify(this.playlists));
|
|
|
const playlist = [...playlists[playlistName]];
|
|
|
@@ -847,6 +910,38 @@ document.addEventListener("alpine:init", () => {
|
|
|
},
|
|
|
},
|
|
|
|
|
|
+ moveToTopButton: {
|
|
|
+ ["@click"]() {
|
|
|
+ this.moveVideoToTop(
|
|
|
+ this.$el.dataset.playlistName,
|
|
|
+ parseInt(this.$el.dataset.playlistIndex),
|
|
|
+ );
|
|
|
+ this.closeAllMenus();
|
|
|
+ },
|
|
|
+ [":disabled"]() {
|
|
|
+ const index = parseInt(this.$el.dataset.playlistIndex);
|
|
|
+ const playlistName = this.$el.dataset.playlistName;
|
|
|
+ const topPosition = this.findTopPosition(playlistName);
|
|
|
+ return index === topPosition;
|
|
|
+ },
|
|
|
+ },
|
|
|
+
|
|
|
+ moveToBottomButton: {
|
|
|
+ ["@click"]() {
|
|
|
+ this.moveVideoToBottom(
|
|
|
+ this.$el.dataset.playlistName,
|
|
|
+ parseInt(this.$el.dataset.playlistIndex),
|
|
|
+ );
|
|
|
+ this.closeAllMenus();
|
|
|
+ },
|
|
|
+ [":disabled"]() {
|
|
|
+ return (
|
|
|
+ parseInt(this.$el.dataset.playlistIndex) ===
|
|
|
+ this.playlists[this.$el.dataset.playlistName].length - 1
|
|
|
+ );
|
|
|
+ },
|
|
|
+ },
|
|
|
+
|
|
|
exportButton: {
|
|
|
["@click"]() {
|
|
|
this.exportPlaylists();
|