1
0
mirror of https://github.com/TeamPiped/Piped.git synced 2024-12-17 07:40:27 +05:30
Piped/src/components/HistoryPage.vue

97 lines
3.1 KiB
Vue
Raw Normal View History

<template>
<h1 class="font-bold text-center" v-t="'titles.history'" />
2022-01-12 17:29:50 +05:30
<div class="flex">
<div>
<button class="btn" v-t="'actions.clear_history'" @click="clearHistory" />
<button class="btn mx-3" v-t="'actions.export_to_json'" @click="exportHistory" />
2022-01-12 17:29:50 +05:30
</div>
2022-01-12 17:29:50 +05:30
<div class="right-1">
2022-05-20 02:47:58 +05:30
<SortingSelector by-key="watchedAt" @apply="order => videos.sort(order)" />
2022-01-12 17:29:50 +05:30
</div>
2021-09-04 21:09:04 +05:30
</div>
<hr />
2021-12-27 20:16:22 +05:30
<div class="video-grid">
2022-11-01 17:42:54 +05:30
<VideoItem v-for="video in videos" :key="video.url" :item="video" />
</div>
2021-09-04 21:09:04 +05:30
<br />
</template>
<script>
2022-04-08 21:16:49 +05:30
import VideoItem from "./VideoItem.vue";
2022-05-20 02:47:58 +05:30
import SortingSelector from "./SortingSelector.vue";
export default {
components: {
VideoItem,
2022-05-20 02:47:58 +05:30
SortingSelector,
},
data() {
return {
videos: [],
};
},
mounted() {
(async () => {
if (window.db && this.getPreferenceBoolean("watchHistory", false)) {
var tx = window.db.transaction("watch_history", "readonly");
var store = tx.objectStore("watch_history");
2022-10-20 21:29:22 +05:30
const cursorRequest = store.index("watchedAt").openCursor(null, "prev");
cursorRequest.onsuccess = e => {
const cursor = e.target.result;
if (cursor) {
const video = cursor.value;
this.videos.push({
url: "/watch?v=" + video.videoId,
title: video.title,
uploaderName: video.uploaderName,
uploaderUrl: video.uploaderUrl,
duration: video.duration,
thumbnail: video.thumbnail,
watchedAt: video.watchedAt,
watched: true,
currentTime: video.currentTime,
});
if (this.videos.length < 1000) cursor.continue();
}
};
}
})();
},
activated() {
document.title = "Watch History - Piped";
},
methods: {
clearHistory() {
if (window.db) {
var tx = window.db.transaction("watch_history", "readwrite");
var store = tx.objectStore("watch_history");
store.clear();
}
this.videos = [];
},
exportHistory() {
const dateStr = new Date().toISOString().split(".")[0];
let json = {
format: "Piped",
version: 1,
playlists: [
{
name: `Piped History ${dateStr}`,
type: "history",
visibility: "private",
videos: this.videos.map(video => "https://youtube.com" + video.url),
},
],
};
this.download(JSON.stringify(json), `piped_history_${dateStr}.json`, "application/json");
},
},
};
</script>