2022-09-22 08:20:31 +09:00
|
|
|
<template>
|
|
|
|
<XWindow :initial-width="640" :initial-height="402" :can-resize="true" :close-button="true">
|
|
|
|
<template #header>
|
2022-12-20 15:11:20 +09:00
|
|
|
<i class="icon ti ti-brand-youtube" style="margin-right: 0.5em;"></i>
|
|
|
|
<span>{{ title ?? 'YouTube' }}</span>
|
2022-09-22 08:20:31 +09:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<div class="poamfof">
|
2022-12-30 13:37:14 +09:00
|
|
|
<Transition :name="$store.state.animation ? 'fade' : ''" mode="out-in">
|
2022-09-22 08:20:31 +09:00
|
|
|
<div v-if="player.url" class="player">
|
|
|
|
<iframe v-if="!fetching" :src="player.url + (player.url.match(/\?/) ? '&autoplay=1&auto_play=1' : '?autoplay=1&auto_play=1')" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen/>
|
|
|
|
</div>
|
2022-12-30 13:37:14 +09:00
|
|
|
</Transition>
|
2022-09-22 08:20:31 +09:00
|
|
|
<MkLoading v-if="fetching"/>
|
|
|
|
<MkError v-else-if="!player.url" @retry="ytFetch()"/>
|
|
|
|
</div>
|
|
|
|
</XWindow>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
|
import XWindow from '@/components/MkWindow.vue';
|
|
|
|
import { lang } from '@/config';
|
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
url: string;
|
|
|
|
}>();
|
|
|
|
|
|
|
|
const requestUrl = new URL(props.url);
|
|
|
|
|
|
|
|
let fetching = $ref(true);
|
|
|
|
let title = $ref<string | null>(null);
|
|
|
|
let player = $ref({
|
|
|
|
url: null,
|
|
|
|
width: null,
|
|
|
|
height: null,
|
|
|
|
});
|
|
|
|
|
|
|
|
const requestLang = (lang ?? 'ja-JP').replace('ja-KS', 'ja-JP');
|
|
|
|
|
|
|
|
const ytFetch = (): void => {
|
|
|
|
fetching = true;
|
2022-12-03 19:42:05 +09:00
|
|
|
window.fetch(`/url?url=${encodeURIComponent(requestUrl.href)}&lang=${requestLang}`).then(res => {
|
2022-09-22 08:20:31 +09:00
|
|
|
res.json().then(info => {
|
|
|
|
if (info.url == null) return;
|
|
|
|
title = info.title;
|
|
|
|
fetching = false;
|
|
|
|
player = info.player;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
ytFetch();
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
.poamfof {
|
|
|
|
position: relative;
|
|
|
|
overflow: hidden;
|
|
|
|
height: 100%;
|
|
|
|
|
|
|
|
.player {
|
|
|
|
position: absolute;
|
|
|
|
inset: 0;
|
|
|
|
|
|
|
|
iframe {
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|