2023-07-27 08:31:52 +03:00
|
|
|
<!--
|
2024-02-13 17:59:27 +02:00
|
|
|
SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 08:31:52 +03:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2022-09-22 02:20:31 +03:00
|
|
|
<template>
|
2023-05-19 07:58:09 +03:00
|
|
|
<MkWindow :initialWidth="640" :initialHeight="402" :canResize="true" :closeButton="true">
|
2022-09-22 02:20:31 +03:00
|
|
|
<template #header>
|
2023-10-01 01:46:42 +03:00
|
|
|
<i class="icon ph-youtube-logo ph-bold ph-lg" style="margin-right: 0.5em;"></i>
|
2022-12-20 08:11:20 +02:00
|
|
|
<span>{{ title ?? 'YouTube' }}</span>
|
2022-09-22 02:20:31 +03:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<div class="poamfof">
|
2023-04-01 07:42:40 +03:00
|
|
|
<Transition :name="defaultStore.state.animation ? 'fade' : ''" mode="out-in">
|
2023-02-04 07:20:07 +02:00
|
|
|
<div v-if="player.url && (player.url.startsWith('http://') || player.url.startsWith('https://'))" class="player">
|
2022-09-22 02:20:31 +03: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 07:20:07 +02:00
|
|
|
<span v-else>invalid url</span>
|
2022-12-30 06:37:14 +02:00
|
|
|
</Transition>
|
2022-09-22 02:20:31 +03:00
|
|
|
<MkLoading v-if="fetching"/>
|
|
|
|
<MkError v-else-if="!player.url" @retry="ytFetch()"/>
|
|
|
|
</div>
|
2023-01-06 02:59:17 +02:00
|
|
|
</MkWindow>
|
2022-09-22 02:20:31 +03:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2023-12-07 07:42:09 +02:00
|
|
|
import { ref } from 'vue';
|
2023-01-06 02:59:17 +02:00
|
|
|
import MkWindow from '@/components/MkWindow.vue';
|
2023-09-19 10:37:43 +03:00
|
|
|
import { versatileLang } from '@/scripts/intl-const.js';
|
|
|
|
import { defaultStore } from '@/store.js';
|
2022-09-22 02:20:31 +03:00
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
url: string;
|
|
|
|
}>();
|
|
|
|
|
|
|
|
const requestUrl = new URL(props.url);
|
2023-02-04 02:10:01 +02:00
|
|
|
if (!['http:', 'https:'].includes(requestUrl.protocol)) throw new Error('invalid url');
|
2022-09-22 02:20:31 +03:00
|
|
|
|
2023-12-07 07:42:09 +02:00
|
|
|
const fetching = ref(true);
|
|
|
|
const title = ref<string | null>(null);
|
|
|
|
const player = ref({
|
2024-01-30 12:53:53 +02:00
|
|
|
url: null as string | null,
|
2022-09-22 02:20:31 +03:00
|
|
|
width: null,
|
|
|
|
height: null,
|
|
|
|
});
|
|
|
|
|
|
|
|
const ytFetch = (): void => {
|
2023-12-07 07:42:09 +02:00
|
|
|
fetching.value = true;
|
2023-01-01 10:11:33 +02:00
|
|
|
window.fetch(`/url?url=${encodeURIComponent(requestUrl.href)}&lang=${versatileLang}`).then(res => {
|
2022-09-22 02:20:31 +03:00
|
|
|
res.json().then(info => {
|
|
|
|
if (info.url == null) return;
|
2023-12-07 07:42:09 +02:00
|
|
|
title.value = info.title;
|
|
|
|
fetching.value = false;
|
|
|
|
player.value = info.player;
|
2022-09-22 02:20:31 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
ytFetch();
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
.poamfof {
|
|
|
|
position: relative;
|
|
|
|
overflow: hidden;
|
|
|
|
height: 100%;
|
|
|
|
|
|
|
|
.player {
|
|
|
|
position: absolute;
|
|
|
|
inset: 0;
|
|
|
|
|
|
|
|
iframe {
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|