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