0
0
Fork 0
mirror of https://github.com/VueTubeApp/VueTube synced 2024-11-19 09:45:14 +00:00
VueTube/NUXT/components/Player/sponsorblock.vue
2022-06-07 13:16:26 -04:00

119 lines
2.4 KiB
Vue

<template>
<div>
<v-progress-linear
v-for="block in blocks"
:key="block.UUID"
:buffer-value="(block.segment[1] / video.duration) * 100"
:value="(block.segment[0] / video.duration) * 100"
style="
z-index: 3;
position: absolute;
pointer-events: none;
background: transparent;
transform: translateY(50%);
"
:class="!fullscreen || controls ? '' : 'invisible'"
background-color="white"
background-opacity="1"
color="transparent"
:height="seeking ? 4 : 2"
:style="
fullscreen
? 'width: calc(100% - 2rem); left: 1rem; bottom: 3.25rem;'
: 'width: 100%; left: 0; bottom: 1px;'
"
/>
</div>
</template>
<script>
export default {
props: {
video: {
type: Object,
required: true,
},
seeking: {
type: Boolean,
required: true,
},
videoid: {
type: String,
required: true,
},
fullscreen: {
type: Boolean,
required: true,
},
controls: {
type: Boolean,
required: true,
},
},
data: () => ({
blocks: [],
}),
mounted() {
let vid = this.video;
let id = this.videoid;
vid.addEventListener("loadeddata", (e) => {
if (vid.readyState >= 3) {
this.$youtube.getSponsorBlock(id, (data) => {
console.log("sbreturn", data);
if (Array.isArray(data)) {
this.blocks = data;
// iterate over data.segments array
vid.addEventListener("timeupdate", () => {
// console.log("sb check", data);
data.forEach((sponsor) => {
let vidTime = vid.currentTime;
if (
vidTime >= sponsor.segment[0] &&
vidTime <= sponsor.segment[1]
) {
console.log("Skipping the sponsor");
this.$youtube.showToast("Skipped sponsor");
vid.currentTime = sponsor.segment[1] + 1;
}
});
});
}
});
}
});
},
};
</script>
<style>
.sponsor {
color: green;
}
.selfpromo {
color: yellow;
}
.exclusive_access {
color: orange;
}
.interaction {
color: blue;
}
.intro {
color: purple;
}
.outro {
color: purple;
}
.music_offtopic {
color: red;
}
.poi_highlight {
color: #ff00ff;
}
.filler {
color: blue;
}
</style>