|
|
@@ -9,6 +9,7 @@ document.addEventListener("alpine:init", () => {
|
|
|
// - consider separating context menu items (rather than having a sub-menu)
|
|
|
Alpine.data("playlistManager", () => ({
|
|
|
playlists: {},
|
|
|
+ currentIndices: {},
|
|
|
|
|
|
init() {
|
|
|
this.loadPlaylists();
|
|
|
@@ -19,6 +20,24 @@ document.addEventListener("alpine:init", () => {
|
|
|
const result = await browser.storage.local.get("playlists");
|
|
|
console.log("LOAD RESULT", result.playlists);
|
|
|
this.playlists = result.playlists || {};
|
|
|
+ if (result.playlists) {
|
|
|
+ this.currentIndices = Object.keys(result.playlists).reduce(
|
|
|
+ (acc, pln) => {
|
|
|
+ const ind = result.playlists[pln].findIndex(
|
|
|
+ (v) => v.status !== "done",
|
|
|
+ );
|
|
|
+ if (ind === -1) {
|
|
|
+ acc[pln] = result.playlists[pln].length;
|
|
|
+ } else {
|
|
|
+ acc[pln] = ind;
|
|
|
+ }
|
|
|
+ return acc;
|
|
|
+ },
|
|
|
+ {},
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ this.currentIndices = {};
|
|
|
+ }
|
|
|
} catch (error) {
|
|
|
console.error("Error loading playlists:", error);
|
|
|
}
|
|
|
@@ -171,29 +190,14 @@ document.addEventListener("alpine:init", () => {
|
|
|
},
|
|
|
},
|
|
|
|
|
|
- getCurrentVideoIndex(playlistName) {
|
|
|
- const playlist = this.playlists[playlistName];
|
|
|
- if (!playlist || !Array.isArray(playlist)) return -1;
|
|
|
-
|
|
|
- // Find the index of the first video that is not "done"
|
|
|
- return playlist.findIndex((video) => {
|
|
|
- // Consider a video as not done if:
|
|
|
- // 1. It has no status property, or
|
|
|
- // 2. The status is not "done" (could be a number for partially watched)
|
|
|
- return !video.status || video.status !== "done";
|
|
|
- });
|
|
|
- },
|
|
|
-
|
|
|
isCurrentVideo(playlistName, index) {
|
|
|
- const currentIndex = this.getCurrentVideoIndex(playlistName);
|
|
|
- return currentIndex === index && currentIndex !== -1;
|
|
|
+ const currentIndex = this.currentIndices[playlistName];
|
|
|
+ return currentIndex === index;
|
|
|
},
|
|
|
|
|
|
isDoneVideo(playlistName, index) {
|
|
|
- const currentIndex = this.getCurrentVideoIndex(playlistName);
|
|
|
- // If there is no current video, or this video's index is less than current,
|
|
|
- // and this video is marked as done, then it's a consecutive done video
|
|
|
- return currentIndex === -1 || index < currentIndex;
|
|
|
+ const currentIndex = this.currentIndices[playlistName];
|
|
|
+ return index < currentIndex;
|
|
|
},
|
|
|
|
|
|
videoItemClass: {
|