0
0
Fork 0
mirror of https://github.com/VueTubeApp/VueTube synced 2024-11-09 04:55:07 +00:00
VueTube/NUXT/components/Player/sponsorblock.vue

76 lines
1.7 KiB
Vue
Raw Normal View History

2022-06-01 03:40:36 +00:00
<template>
<div>
<!-- <v-progress-linear
v-for="segment in segments"
:key="segment.UUID"
background-opacity="0.5"
style="width: 100%; background: #ffffff22"
:background-color="segment.category"
:buffer-value="(segment.segments[1] / video.duration) * 100"
:value="(segment.segments[0] / video.duration) * 100"
color="red"
height="2"
:style="
fullscreen
? 'width: calc(100% - 2rem); left: 1rem; position: absolute; bottom: 3rem;'
: 'width: 100%; left: 0; position: absolute; bottom: 0;'
"
/> -->
</div>
2022-06-01 03:40:36 +00:00
</template>
<script>
export default {
props: {
video: {
type: Object,
required: true,
},
2022-06-01 04:00:54 +00:00
videoid: {
type: String,
required: true,
},
2022-06-01 03:40:36 +00:00
},
data: () => ({
segments: [],
}),
2022-06-01 03:40:36 +00:00
mounted() {
2022-06-01 06:13:16 +00:00
let vid = this.video;
let id = this.videoid;
2022-06-01 03:40:36 +00:00
2022-06-01 06:13:16 +00:00
vid.addEventListener("loadeddata", (e) => {
if (vid.readyState >= 3) {
this.$youtube.getSponsorBlock(id, (data) => {
console.log("sbreturn", data);
if (Array.isArray(data)) {
this.segments = data;
2022-06-01 03:40:36 +00:00
// iterate over data.segments array
vid.addEventListener("timeupdate", () => {
console.log("sb check", data);
data.forEach((sponsor) => {
2022-06-01 06:13:16 +00:00
let vidTime = vid.currentTime;
2022-06-01 03:40:36 +00:00
if (
vidTime >= sponsor.segment[0] &&
vidTime <= sponsor.segment[1]
) {
2022-06-01 06:13:16 +00:00
console.log("Skipping the sponsor");
vid.currentTime = sponsor.segment[1];
}
});
});
}
});
2022-06-01 03:40:36 +00:00
}
});
2022-06-01 03:40:36 +00:00
},
};
</script>
<style>
.sponsor {
color: green;
}
</style>