Skip to content

Commit

Permalink
fix: trailer on website
Browse files Browse the repository at this point in the history
  • Loading branch information
ThaUnknown committed Aug 20, 2024
1 parent de6a09c commit 3a4a2fd
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions web/src/lib/components/PreviewCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
}
const playButtonText = getPlayButtonText(media)
function volume (video) {
video.volume = 0.1
}
let muted = true
function toggleMute () {
muted = !muted
Expand All @@ -31,19 +28,19 @@
function play () {
open('miru://anime/' + media.id)
}
function lazyload (video) {
function lazyload (iframe) {
if ('IntersectionObserver' in window) {
const lazyVideoObserver = new IntersectionObserver(entries => {
for (const { target, isIntersecting } of entries) {
if (isIntersecting) {
video.src = video.dataset.src
iframe.src = iframe.dataset.src
lazyVideoObserver.unobserve(target)
}
}
})
lazyVideoObserver.observe(video.parentNode)
lazyVideoObserver.observe(iframe.parentNode)
} else {
video.src = video.dataset.src
iframe.src = iframe.dataset.src
}
}
</script>
Expand All @@ -55,18 +52,15 @@
<div class='material-symbols-outlined filled position-absolute z-10 top-0 right-0 p-15 font-size-22' class:d-none={hide} use:click={toggleMute}>{muted ? 'volume_off' : 'volume_up'}</div>
<!-- for now we use some invidious instance, would be nice to somehow get these links outselves, this redirects straight to some google endpoint -->
<!-- eslint-disable-next-line svelte/valid-compile -->
<video data-src={`https://inv.tux.pizza/latest_version?id=${media.trailer.id}&itag=18`}
class='w-full h-full position-absolute left-0'
<iframe
class='w-full border-0 position-absolute left-0'
class:d-none={hide}
playsinline
preload='none'
loading='lazy'
title={media.title.userPreferred}
allow='autoplay'
use:lazyload
loop
use:volume
bind:muted
on:loadeddata={() => { hide = false }}
autoplay />
on:load={() => { hide = false }}
data-src={`https://www.youtube-nocookie.com/embed/${media.trailer?.id}?autoplay=1&controls=0&mute=${muted ? 1 : 0}&disablekb=1&loop=1&vq=medium&playlist=${media.trailer?.id}&cc_lang_pref=ja`}
/>
{/if}
</div>
<div class='w-full px-20'>
Expand Down

0 comments on commit 3a4a2fd

Please sign in to comment.