diff --git a/src/App.vue b/src/App.vue
index 4e74b80b..66a70eb1 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -41,6 +41,23 @@ export default {
default:
break;
}
+
+ if (this.getPreferenceBoolean("watchHistory", false))
+ if ("indexedDB" in window) {
+ const request = indexedDB.open("piped-db", 1);
+ request.onupgradeneeded = function() {
+ const db = request.result;
+ console.log("Upgrading object store.");
+ if (!db.objectStoreNames.contains("watch_history")) {
+ const store = db.createObjectStore("watch_history", { keyPath: "videoId" });
+ store.createIndex("video_id_idx", "videoId", { unique: true });
+ store.createIndex("id_idx", "id", { unique: true, autoIncrement: true });
+ }
+ };
+ request.onsuccess = e => {
+ window.db = e.target.result;
+ };
+ } else console.log("This browser doesn't support IndexedDB");
},
};
diff --git a/src/components/FeedPage.vue b/src/components/FeedPage.vue
index 90d505be..c764f2f2 100644
--- a/src/components/FeedPage.vue
+++ b/src/components/FeedPage.vue
@@ -44,7 +44,28 @@ export default {
};
},
mounted() {
- this.fetchFeed().then(videos => (this.videos = videos));
+ this.fetchFeed().then(videos => {
+ this.videos = videos;
+ (async () => {
+ if (window.db) {
+ var tx = window.db.transaction("watch_history", "readonly");
+ var store = tx.objectStore("watch_history");
+ const cursorRequest = store.openCursor();
+ cursorRequest.onsuccess = e => {
+ const cursor = e.target.result;
+ if (cursor) {
+ const video = this.videos.filter(
+ video => video.url.substr(-11) === cursor.value.videoId,
+ )[0];
+ if (video != null) {
+ video.watched = true;
+ }
+ cursor.continue();
+ }
+ };
+ }
+ })();
+ });
},
activated() {
document.title = "Feed - Piped";
diff --git a/src/components/HistoryPage.vue b/src/components/HistoryPage.vue
new file mode 100644
index 00000000..0a87a796
--- /dev/null
+++ b/src/components/HistoryPage.vue
@@ -0,0 +1,88 @@
+
+ Watch History
+
+
+ Sort by:
+
+
+
+
+
+
+
+
diff --git a/src/components/LoginPage.vue b/src/components/LoginPage.vue
index 60f967cf..66862fb6 100644
--- a/src/components/LoginPage.vue
+++ b/src/components/LoginPage.vue
@@ -50,7 +50,6 @@ export default {
},
methods: {
login() {
- console.log("authToken" + this.hashCode(this.apiUrl()));
this.fetchJson(this.apiUrl() + "/login", null, {
method: "POST",
body: JSON.stringify({
diff --git a/src/components/Navigation.vue b/src/components/Navigation.vue
index 6ff4ca61..7e0a7edb 100644
--- a/src/components/Navigation.vue
+++ b/src/components/Navigation.vue
@@ -6,7 +6,13 @@
>
iped
iped
@@ -31,6 +37,9 @@
Register
+
+ History
+
Feed
@@ -73,6 +82,9 @@ export default {
shouldShowLogin(_this) {
return _this.getAuthToken() == null;
},
+ shouldShowHistory(_this) {
+ return _this.getPreferenceBoolean("watchHistory", false);
+ },
},
methods: {
onKeyUp(e) {
diff --git a/src/components/Preferences.vue b/src/components/Preferences.vue
index 65dae628..7ce37f81 100644
--- a/src/components/Preferences.vue
+++ b/src/components/Preferences.vue
@@ -1,8 +1,8 @@
- Back
+
Preferences
@@ -88,6 +88,10 @@
Minimize Description by default
+
+ Store Watch History
+
+
Instances List
@@ -147,6 +151,7 @@ export default {
defaultHomepage: "trending",
showComments: true,
minimizeDescription: false,
+ watchHistory: false,
};
},
activated() {
@@ -223,6 +228,7 @@ export default {
this.defaultHomepage = this.getPreferenceString("homepage", "trending");
this.showComments = this.getPreferenceBoolean("comments", true);
this.minimizeDescription = this.getPreferenceBoolean("minimizeDescription", false);
+ this.watchHistory = this.getPreferenceBoolean("watchHistory", false);
}
},
methods: {
@@ -230,7 +236,11 @@ export default {
if (localStorage) {
var shouldReload = false;
- if (this.getPreferenceString("theme", "dark") !== this.selectedTheme) shouldReload = true;
+ if (
+ this.getPreferenceString("theme", "dark") !== this.selectedTheme ||
+ this.getPreferenceBoolean("watchHistory", false) != this.watchHistory
+ )
+ shouldReload = true;
localStorage.setItem("instance", this.selectedInstance);
localStorage.setItem("sponsorblock", this.sponsorBlock);
@@ -254,6 +264,7 @@ export default {
localStorage.setItem("homepage", this.defaultHomepage);
localStorage.setItem("comments", this.showComments);
localStorage.setItem("minimizeDescription", this.minimizeDescription);
+ localStorage.setItem("watchHistory", this.watchHistory);
if (shouldReload) window.location.reload();
}
diff --git a/src/components/VideoItem.vue b/src/components/VideoItem.vue
index 76d36972..540669ba 100644
--- a/src/components/VideoItem.vue
+++ b/src/components/VideoItem.vue
@@ -16,6 +16,12 @@
style="bottom: 5px; right: 5px; background: rgba(0, 0, 0, .75); color: white; padding: 0 5px;"
>{{ timeFormat(video.duration) }}
+ Watched
{{ video.title }}
diff --git a/src/components/WatchVideo.vue b/src/components/WatchVideo.vue
index b467434c..0fd059a5 100644
--- a/src/components/WatchVideo.vue
+++ b/src/components/WatchVideo.vue
@@ -144,6 +144,22 @@ export default {
},
mounted() {
this.getVideoData().then(() => {
+ (async () => {
+ if (window.db) {
+ var tx = window.db.transaction("watch_history", "readwrite");
+ var store = tx.objectStore("watch_history");
+ var video = {
+ videoId: this.getVideoId(),
+ title: this.video.title,
+ duration: this.video.duration,
+ thumbnail: this.video.thumbnailUrl,
+ uploaderUrl: this.video.uploaderUrl,
+ uploaderName: this.video.uploader,
+ watchedAt: Date.now(),
+ };
+ store.add(video);
+ }
+ })();
if (this.active) this.$refs.videoPlayer.loadVideo();
});
this.getSponsors();
@@ -163,13 +179,6 @@ export default {
this.active = false;
window.removeEventListener("scroll", this.handleScroll);
},
- watch: {
- "$route.query.v": function(v) {
- if (v) {
- window.scrollTo(0, 0);
- }
- },
- },
methods: {
fetchVideo() {
return this.fetchJson(this.apiUrl() + "/streams/" + this.getVideoId());
diff --git a/src/router/router.js b/src/router/router.js
index ca0a805f..d38300eb 100644
--- a/src/router/router.js
+++ b/src/router/router.js
@@ -60,6 +60,11 @@ const routes = [
name: "Subscriptions",
component: () => import("../components/SubscriptionsPage.vue"),
},
+ {
+ path: "/history",
+ name: "Watch History",
+ component: () => import("../components/HistoryPage.vue"),
+ },
];
const router = createRouter({