Make timestamps in comments seek instead of reload

This commit is contained in:
Tyrritt 2023-01-18 16:56:21 +01:00
parent 86e9bd069e
commit 95a0e4cbc8
2 changed files with 17 additions and 0 deletions

View file

@ -71,6 +71,7 @@ export default {
uploader: { type: String, default: null },
videoId: { type: String, default: null },
},
emits: ["seek"],
data() {
return {
loadingReplies: false,
@ -79,6 +80,21 @@ export default {
nextpage: null,
};
},
mounted() {
const thisComment = this;
this.$el.querySelectorAll("a").forEach(elem => {
if (elem.innerText.match(/(?:[\d]{1,2}:)?(?:[\d]{1,2}):(?:[\d]{1,2})/)) {
elem.addEventListener("click", function (event) {
if (!event || !event.target) return;
if (!event.target.getAttribute("href").match(/(?<=t=)\d{1,}/)) return;
const time = parseInt(event.target.getAttribute("href").match(/(?<=t=)\d{1,}/)[0]);
thisComment.$emit("seek", time);
event.preventDefault();
});
}
});
},
methods: {
async loadReplies() {
if (!this.showingReplies && this.loadingReplies) {

View file

@ -186,6 +186,7 @@
:comment="comment"
:uploader="video.uploader"
:video-id="getVideoId()"
@seek="navigate"
/>
</div>