mirror of
https://github.com/TeamPiped/Piped.git
synced 2024-08-14 23:57:27 +00:00
Merge d3a075ed56
into d82a93fd0b
This commit is contained in:
commit
29b752dd4f
1 changed files with 42 additions and 19 deletions
|
@ -31,6 +31,9 @@ export default {
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
currentVideoCount: 0,
|
||||||
|
videoStep: 100,
|
||||||
|
videosStore: [],
|
||||||
videos: [],
|
videos: [],
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
@ -40,11 +43,12 @@ export default {
|
||||||
var tx = window.db.transaction("watch_history", "readonly");
|
var tx = window.db.transaction("watch_history", "readonly");
|
||||||
var store = tx.objectStore("watch_history");
|
var store = tx.objectStore("watch_history");
|
||||||
const cursorRequest = store.index("watchedAt").openCursor(null, "prev");
|
const cursorRequest = store.index("watchedAt").openCursor(null, "prev");
|
||||||
|
const cursorPromise = new Promise(resolve => {
|
||||||
cursorRequest.onsuccess = e => {
|
cursorRequest.onsuccess = e => {
|
||||||
const cursor = e.target.result;
|
const cursor = e.target.result;
|
||||||
if (cursor) {
|
if (cursor) {
|
||||||
const video = cursor.value;
|
const video = cursor.value;
|
||||||
this.videos.push({
|
this.videosStore.push({
|
||||||
url: "/watch?v=" + video.videoId,
|
url: "/watch?v=" + video.videoId,
|
||||||
title: video.title,
|
title: video.title,
|
||||||
uploaderName: video.uploaderName,
|
uploaderName: video.uploaderName,
|
||||||
|
@ -55,14 +59,23 @@ export default {
|
||||||
watched: true,
|
watched: true,
|
||||||
currentTime: video.currentTime,
|
currentTime: video.currentTime,
|
||||||
});
|
});
|
||||||
if (this.videos.length < 1000) cursor.continue();
|
if (this.videosStore.length < 1000) cursor.continue();
|
||||||
}
|
else resolve();
|
||||||
|
} else resolve();
|
||||||
};
|
};
|
||||||
|
});
|
||||||
|
await cursorPromise;
|
||||||
}
|
}
|
||||||
})();
|
})().then(() => {
|
||||||
|
this.loadMoreVideos();
|
||||||
|
});
|
||||||
},
|
},
|
||||||
activated() {
|
activated() {
|
||||||
document.title = "Watch History - Piped";
|
document.title = "Watch History - Piped";
|
||||||
|
window.addEventListener("scroll", this.handleScroll);
|
||||||
|
},
|
||||||
|
deactivated() {
|
||||||
|
window.removeEventListener("scroll", this.handleScroll);
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
clearHistory() {
|
clearHistory() {
|
||||||
|
@ -89,6 +102,16 @@ export default {
|
||||||
};
|
};
|
||||||
this.download(JSON.stringify(json), `piped_history_${dateStr}.json`, "application/json");
|
this.download(JSON.stringify(json), `piped_history_${dateStr}.json`, "application/json");
|
||||||
},
|
},
|
||||||
|
loadMoreVideos() {
|
||||||
|
this.currentVideoCount = Math.min(this.currentVideoCount + this.videoStep, this.videosStore.length);
|
||||||
|
if (this.videos.length != this.videosStore.length)
|
||||||
|
this.videos = this.videosStore.slice(0, this.currentVideoCount);
|
||||||
|
},
|
||||||
|
handleScroll() {
|
||||||
|
if (window.innerHeight + window.scrollY >= document.body.offsetHeight - window.innerHeight) {
|
||||||
|
this.loadMoreVideos();
|
||||||
|
}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue