2021-08-22 10:27:09 +00:00
|
|
|
<template>
|
2023-07-17 08:40:19 +00:00
|
|
|
<h1 class="font-bold text-center mb-3" v-t="'titles.history'" />
|
2021-08-22 10:27:09 +00:00
|
|
|
|
2023-07-17 08:40:19 +00:00
|
|
|
<div class="flex">
|
|
|
|
<div class="flex md:items-center gap-2 flex-col md:flex-row">
|
|
|
|
<button class="btn" v-t="'actions.clear_history'" @click="clearHistory" />
|
2023-01-27 16:27:40 +00:00
|
|
|
|
2023-07-17 08:40:19 +00:00
|
|
|
<button class="btn" v-t="'actions.export_to_json'" @click="exportHistory" />
|
2021-10-31 18:36:21 +00:00
|
|
|
|
2023-07-17 08:40:19 +00:00
|
|
|
<div class="ml-auto flex gap-1 items-center">
|
|
|
|
<SortingSelector by-key="watchedAt" @apply="order => videos.sort(order)" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="flex ml-4 items-center">
|
|
|
|
<input id="autoDelete" type="checkbox" v-model="autoDeleteHistory" @change="onChange" />
|
|
|
|
<label class="ml-2" for="autoDelete" v-t="'actions.delete_automatically'" />
|
|
|
|
<select class="pl-3 ml-3 select" v-model="autoDeleteDelayHours" @change="onChange">
|
|
|
|
<option value="1" v-t="{ path: 'info.hours', args: { amount: '1' } }" />
|
|
|
|
<option value="3" v-t="{ path: 'info.hours', args: { amount: '3' } }" />
|
|
|
|
<option value="6" v-t="{ path: 'info.hours', args: { amount: '6' } }" />
|
|
|
|
<option value="12" v-t="{ path: 'info.hours', args: { amount: '12' } }" />
|
|
|
|
<option value="24" v-t="{ path: 'info.days', args: { amount: '1' } }" />
|
|
|
|
<option value="72" v-t="{ path: 'info.days', args: { amount: '3' } }" />
|
|
|
|
<option value="168" v-t="{ path: 'info.weeks', args: { amount: '1' } }" />
|
|
|
|
<option value="336" v-t="{ path: 'info.weeks', args: { amount: '3' } }" />
|
|
|
|
<option value="672" v-t="{ path: 'info.months', args: { amount: '1' } }" />
|
|
|
|
<option value="1344" v-t="{ path: 'info.months', args: { amount: '2' } }" />
|
|
|
|
</select>
|
2022-01-12 11:59:50 +00:00
|
|
|
</div>
|
2021-09-04 15:39:04 +00:00
|
|
|
</div>
|
2021-08-22 10:27:09 +00:00
|
|
|
|
|
|
|
<hr />
|
|
|
|
|
2021-12-27 14:46:22 +00:00
|
|
|
<div class="video-grid">
|
2022-11-01 12:12:54 +00:00
|
|
|
<VideoItem v-for="video in videos" :key="video.url" :item="video" />
|
2021-08-22 10:27:09 +00:00
|
|
|
</div>
|
2021-09-04 15:39:04 +00:00
|
|
|
|
|
|
|
<br />
|
2021-08-22 10:27:09 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2022-04-08 15:46:49 +00:00
|
|
|
import VideoItem from "./VideoItem.vue";
|
2022-05-19 21:17:58 +00:00
|
|
|
import SortingSelector from "./SortingSelector.vue";
|
2021-08-22 10:27:09 +00:00
|
|
|
|
|
|
|
export default {
|
2021-10-08 18:52:51 +00:00
|
|
|
components: {
|
|
|
|
VideoItem,
|
2022-05-19 21:17:58 +00:00
|
|
|
SortingSelector,
|
2021-10-08 18:52:51 +00:00
|
|
|
},
|
2021-08-22 10:27:09 +00:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
videos: [],
|
2023-07-17 08:40:19 +00:00
|
|
|
autoDeleteHistory: false,
|
|
|
|
autoDeleteDelayHours: "24",
|
2021-08-22 10:27:09 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
mounted() {
|
2023-07-17 08:40:19 +00:00
|
|
|
this.autoDeleteHistory = this.getPreferenceBoolean("autoDeleteWatchHistory", false);
|
|
|
|
this.autoDeleteDelayHours = this.getPreferenceString("autoDeleteWatchHistoryDelayHours", "24");
|
|
|
|
|
2021-08-22 10:27:09 +00:00
|
|
|
(async () => {
|
2023-01-13 13:40:12 +00:00
|
|
|
if (window.db && this.getPreferenceBoolean("watchHistory", false)) {
|
2023-07-17 08:40:19 +00:00
|
|
|
var tx = window.db.transaction("watch_history", "readwrite");
|
2021-08-22 10:27:09 +00:00
|
|
|
var store = tx.objectStore("watch_history");
|
2022-10-20 15:59:22 +00:00
|
|
|
const cursorRequest = store.index("watchedAt").openCursor(null, "prev");
|
2021-08-22 10:27:09 +00:00
|
|
|
cursorRequest.onsuccess = e => {
|
|
|
|
const cursor = e.target.result;
|
|
|
|
if (cursor) {
|
|
|
|
const video = cursor.value;
|
|
|
|
if (this.videos.length < 1000) cursor.continue();
|
2023-07-17 08:40:19 +00:00
|
|
|
if (!this.shouldRemoveVideo(video)) {
|
|
|
|
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,
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
store.delete(video.videoId);
|
|
|
|
}
|
2021-08-22 10:27:09 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
},
|
|
|
|
activated() {
|
|
|
|
document.title = "Watch History - Piped";
|
|
|
|
},
|
|
|
|
methods: {
|
2021-10-31 18:36:21 +00:00
|
|
|
clearHistory() {
|
|
|
|
if (window.db) {
|
|
|
|
var tx = window.db.transaction("watch_history", "readwrite");
|
|
|
|
var store = tx.objectStore("watch_history");
|
|
|
|
store.clear();
|
|
|
|
}
|
|
|
|
this.videos = [];
|
|
|
|
},
|
2023-01-27 16:27:40 +00:00
|
|
|
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");
|
|
|
|
},
|
2023-07-17 08:40:19 +00:00
|
|
|
onChange() {
|
|
|
|
this.setPreference("autoDeleteWatchHistory", this.autoDeleteHistory);
|
|
|
|
this.setPreference("autoDeleteWatchHistoryDelayHours", this.autoDeleteDelayHours);
|
|
|
|
},
|
|
|
|
shouldRemoveVideo(video) {
|
|
|
|
if (!this.autoDeleteHistory) return false;
|
|
|
|
// convert from hours to milliseconds
|
|
|
|
let maximumTimeDiff = Number(this.autoDeleteDelayHours) * 60 * 60 * 1000;
|
|
|
|
return Date.now() - video.watchedAt > maximumTimeDiff;
|
|
|
|
},
|
2021-08-22 10:27:09 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|