|
|
@@ -134,7 +134,8 @@ document.addEventListener("alpine:init", () => {
|
|
|
formattedVideoId: `(${videoId})`,
|
|
|
...videoData,
|
|
|
lastInteraction,
|
|
|
- processedEvents
|
|
|
+ processedEvents,
|
|
|
+ tags: videoData.tags || [] // Ensure tags array exists
|
|
|
};
|
|
|
})
|
|
|
.sort((a, b) => b.lastInteraction - a.lastInteraction);
|
|
|
@@ -162,6 +163,44 @@ document.addEventListener("alpine:init", () => {
|
|
|
return `${minutes}:${remainingSeconds.toString().padStart(2, '0')}`;
|
|
|
},
|
|
|
|
|
|
+ async toggleTag(videoId, tag) {
|
|
|
+ // Create a deep copy of history to avoid proxy issues
|
|
|
+ const history = JSON.parse(JSON.stringify(this.history));
|
|
|
+
|
|
|
+ if (!history[videoId]) {
|
|
|
+ console.error(`Video ${videoId} not found in history`);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const videoData = history[videoId];
|
|
|
+ if (!videoData.tags) {
|
|
|
+ videoData.tags = [];
|
|
|
+ }
|
|
|
+
|
|
|
+ const tagIndex = videoData.tags.indexOf(tag);
|
|
|
+ if (tagIndex === -1) {
|
|
|
+ // Add tag
|
|
|
+ videoData.tags.push(tag);
|
|
|
+ } else {
|
|
|
+ // Remove tag
|
|
|
+ videoData.tags.splice(tagIndex, 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Save to storage and update local state
|
|
|
+ try {
|
|
|
+ await browser.storage.local.set({ history: history });
|
|
|
+ this.history = history;
|
|
|
+ this.sortHistoryByRecentInteraction(); // Refresh display
|
|
|
+ } catch (error) {
|
|
|
+ console.error("Error saving tag changes:", error);
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ isTagActive(videoId, tag) {
|
|
|
+ const videoData = this.history[videoId];
|
|
|
+ return videoData && videoData.tags && videoData.tags.includes(tag);
|
|
|
+ },
|
|
|
+
|
|
|
formatActionName(action) {
|
|
|
const actionMap = {
|
|
|
'play': 'Started',
|
|
|
@@ -693,5 +732,21 @@ document.addEventListener("alpine:init", () => {
|
|
|
return this.currentPlaylistVideos.length === 0;
|
|
|
},
|
|
|
},
|
|
|
+
|
|
|
+ // Tag chip bindings for CSP compliance
|
|
|
+ tagChip: {
|
|
|
+ ["@click"]() {
|
|
|
+ const videoId = this.$el.dataset.videoId;
|
|
|
+ const tag = this.$el.dataset.tag;
|
|
|
+ this.toggleTag(videoId, tag);
|
|
|
+ },
|
|
|
+ [":class"]() {
|
|
|
+ const videoId = this.$el.dataset.videoId;
|
|
|
+ const tag = this.$el.dataset.tag;
|
|
|
+ return {
|
|
|
+ 'active': this.isTagActive(videoId, tag)
|
|
|
+ };
|
|
|
+ },
|
|
|
+ },
|
|
|
}));
|
|
|
});
|