2022-09-21 23:20:31 +00:00
|
|
|
<template>
|
2023-05-19 04:58:09 +00:00
|
|
|
<MkWindow :initialWidth="640" :initialHeight="402" :canResize="true" :closeButton="true">
|
2022-09-21 23:20:31 +00:00
|
|
|
<template #header>
|
2022-12-20 06:11:20 +00:00
|
|
|
<i class="icon ti ti-brand-youtube" style="margin-right: 0.5em;"></i>
|
|
|
|
<span>{{ title ?? 'YouTube' }}</span>
|
2022-09-21 23:20:31 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<div class="poamfof">
|
2023-04-01 04:42:40 +00:00
|
|
|
<Transition :name="defaultStore.state.animation ? 'fade' : ''" mode="out-in">
|
2023-02-04 05:20:07 +00:00
|
|
|
<div v-if="player.url && (player.url.startsWith('http://') || player.url.startsWith('https://'))" class="player">
|
2022-09-21 23:20:31 +00:00
|
|
|
<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>
|
2023-02-04 05:20:07 +00:00
|
|
|
<span v-else>invalid url</span>
|
2022-12-30 04:37:14 +00:00
|
|
|
</Transition>
|
2022-09-21 23:20:31 +00:00
|
|
|
<MkLoading v-if="fetching"/>
|
|
|
|
<MkError v-else-if="!player.url" @retry="ytFetch()"/>
|
|
|
|
</div>
|
2023-01-06 00:59:17 +00:00
|
|
|
</MkWindow>
|
2022-09-21 23:20:31 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2023-01-06 00:59:17 +00:00
|
|
|
import MkWindow from '@/components/MkWindow.vue';
|
2023-01-01 08:11:33 +00:00
|
|
|
import { versatileLang } from '@/scripts/intl-const';
|
2023-04-01 04:42:40 +00:00
|
|
|
import { defaultStore } from '@/store';
|
2022-09-21 23:20:31 +00:00
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
url: string;
|
|
|
|
}>();
|
|
|
|
|
|
|
|
const requestUrl = new URL(props.url);
|
2023-02-04 00:10:01 +00:00
|
|
|
if (!['http:', 'https:'].includes(requestUrl.protocol)) throw new Error('invalid url');
|
2022-09-21 23:20:31 +00:00
|
|
|
|
|
|
|
let fetching = $ref(true);
|
|
|
|
let title = $ref<string | null>(null);
|
|
|
|
let player = $ref({
|
|
|
|
url: null,
|
|
|
|
width: null,
|
|
|
|
height: null,
|
|
|
|
});
|
|
|
|
|
|
|
|
const ytFetch = (): void => {
|
|
|
|
fetching = true;
|
2023-01-01 08:11:33 +00:00
|
|
|
window.fetch(`/url?url=${encodeURIComponent(requestUrl.href)}&lang=${versatileLang}`).then(res => {
|
2022-09-21 23:20:31 +00: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>
|