2023-07-27 05:31:52 +00:00
|
|
|
<!--
|
|
|
|
SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2020-01-29 19:37:25 +00:00
|
|
|
<template>
|
2023-03-19 07:59:31 +00:00
|
|
|
<template v-if="player.url && playerEnabled">
|
|
|
|
<div
|
|
|
|
:class="$style.player"
|
|
|
|
:style="player.width ? `padding: ${(player.height || 0) / player.width * 100}% 0 0` : `padding: ${(player.height || 0)}px 0 0`"
|
|
|
|
>
|
|
|
|
<iframe
|
2023-11-03 10:44:17 +00:00
|
|
|
v-if="player.url?.startsWith('http://') || player.url?.startsWith('https://')"
|
2023-03-19 07:59:31 +00:00
|
|
|
sandbox="allow-popups allow-scripts allow-storage-access-by-user-activation allow-same-origin"
|
|
|
|
scrolling="no"
|
|
|
|
:allow="player.allow.join(';')"
|
|
|
|
:class="$style.playerIframe"
|
|
|
|
:src="player.url + (player.url.match(/\?/) ? '&autoplay=1&auto_play=1' : '?autoplay=1&auto_play=1')"
|
|
|
|
:style="{ border: 0 }"
|
|
|
|
></iframe>
|
2023-02-24 05:38:47 +00:00
|
|
|
<span v-else>invalid url</span>
|
|
|
|
</div>
|
|
|
|
<div :class="$style.action">
|
|
|
|
<MkButton :small="true" inline @click="playerEnabled = false">
|
|
|
|
<i class="ti ti-x"></i> {{ i18n.ts.disablePlayer }}
|
|
|
|
</MkButton>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<template v-else-if="tweetId && tweetExpanded">
|
2023-06-01 08:19:46 +00:00
|
|
|
<div ref="twitter">
|
2023-08-13 03:29:13 +00:00
|
|
|
<iframe
|
|
|
|
ref="tweet"
|
|
|
|
allow="fullscreen;web-share"
|
|
|
|
sandbox="allow-popups allow-scripts allow-same-origin"
|
|
|
|
scrolling="no"
|
|
|
|
:style="{ position: 'relative', width: '100%', height: `${tweetHeight}px`, border: 0 }"
|
|
|
|
:src="`https://platform.twitter.com/embed/index.html?embedId=${embedId}&hideCard=false&hideThread=false&lang=en&theme=${defaultStore.state.darkMode ? 'dark' : 'light'}&id=${tweetId}`"
|
|
|
|
></iframe>
|
2023-02-24 05:38:47 +00:00
|
|
|
</div>
|
|
|
|
<div :class="$style.action">
|
|
|
|
<MkButton :small="true" inline @click="tweetExpanded = false">
|
|
|
|
<i class="ti ti-x"></i> {{ i18n.ts.close }}
|
|
|
|
</MkButton>
|
|
|
|
</div>
|
|
|
|
</template>
|
2023-06-01 08:19:46 +00:00
|
|
|
<div v-else>
|
2023-07-13 22:59:54 +00:00
|
|
|
<component :is="self ? 'MkA' : 'a'" :class="[$style.link, { [$style.compact]: compact }]" :[attr]="self ? url.substring(local.length) : url" rel="nofollow noopener" :target="target" :title="url">
|
2023-09-10 09:40:20 +00:00
|
|
|
<div v-if="thumbnail" :class="$style.thumbnail" :style="defaultStore.state.enableDataSaverMode ? '' : `background-image: url('${thumbnail}')`">
|
2022-12-30 05:24:00 +00:00
|
|
|
</div>
|
2023-01-14 02:59:08 +00:00
|
|
|
<article :class="$style.body">
|
|
|
|
<header :class="$style.header">
|
|
|
|
<h1 v-if="unknownUrl" :class="$style.title">{{ url }}</h1>
|
|
|
|
<h1 v-else-if="fetching" :class="$style.title"><MkEllipsis/></h1>
|
2023-03-19 07:59:31 +00:00
|
|
|
<h1 v-else :class="$style.title" :title="title ?? undefined">{{ title }}</h1>
|
2022-12-30 05:24:00 +00:00
|
|
|
</header>
|
2023-05-17 20:00:28 +00:00
|
|
|
<p v-if="unknownUrl" :class="$style.text">{{ i18n.ts.failedToPreviewUrl }}</p>
|
2023-01-14 02:59:08 +00:00
|
|
|
<p v-else-if="fetching" :class="$style.text"><MkEllipsis/></p>
|
|
|
|
<p v-else-if="description" :class="$style.text" :title="description">{{ description.length > 85 ? description.slice(0, 85) + '…' : description }}</p>
|
|
|
|
<footer :class="$style.footer">
|
|
|
|
<img v-if="icon" :class="$style.siteIcon" :src="icon"/>
|
2023-05-17 20:00:28 +00:00
|
|
|
<p v-if="unknownUrl" :class="$style.siteName">{{ requestUrl.host }}</p>
|
2023-01-14 02:59:08 +00:00
|
|
|
<p v-else-if="fetching" :class="$style.siteName"><MkEllipsis/></p>
|
2023-05-17 20:00:28 +00:00
|
|
|
<p v-else :class="$style.siteName" :title="sitename ?? requestUrl.host">{{ sitename ?? requestUrl.host }}</p>
|
2022-12-30 05:24:00 +00:00
|
|
|
</footer>
|
|
|
|
</article>
|
|
|
|
</component>
|
2023-07-21 00:57:21 +00:00
|
|
|
<template v-if="showActions">
|
|
|
|
<div v-if="tweetId" :class="$style.action">
|
|
|
|
<MkButton :small="true" inline @click="tweetExpanded = true">
|
2023-07-31 08:05:40 +00:00
|
|
|
<i class="ti ti-brand-x"></i> {{ i18n.ts.expandTweet }}
|
2023-07-21 00:57:21 +00:00
|
|
|
</MkButton>
|
|
|
|
</div>
|
|
|
|
<div v-if="!playerEnabled && player.url" :class="$style.action">
|
|
|
|
<MkButton :small="true" inline @click="playerEnabled = true">
|
|
|
|
<i class="ti ti-player-play"></i> {{ i18n.ts.enablePlayer }}
|
|
|
|
</MkButton>
|
|
|
|
<MkButton v-if="!isMobile" :small="true" inline @click="openPlayer()">
|
|
|
|
<i class="ti ti-picture-in-picture"></i> {{ i18n.ts.openInWindow }}
|
|
|
|
</MkButton>
|
|
|
|
</div>
|
|
|
|
</template>
|
2020-01-29 19:37:25 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2022-01-15 23:24:53 +00:00
|
|
|
<script lang="ts" setup>
|
2023-02-16 14:09:41 +00:00
|
|
|
import { defineAsyncComponent, onUnmounted } from 'vue';
|
2023-03-19 07:59:31 +00:00
|
|
|
import type { summaly } from 'summaly';
|
2023-09-19 07:37:43 +00:00
|
|
|
import { url as local } from '@/config.js';
|
|
|
|
import { i18n } from '@/i18n.js';
|
|
|
|
import * as os from '@/os.js';
|
|
|
|
import { deviceKind } from '@/scripts/device-kind.js';
|
2022-12-28 09:22:46 +00:00
|
|
|
import MkButton from '@/components/MkButton.vue';
|
2023-09-19 07:37:43 +00:00
|
|
|
import { versatileLang } from '@/scripts/intl-const.js';
|
|
|
|
import { defaultStore } from '@/store.js';
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2023-03-19 07:59:31 +00:00
|
|
|
type SummalyResult = Awaited<ReturnType<typeof summaly>>;
|
|
|
|
|
2022-01-15 23:24:53 +00:00
|
|
|
const props = withDefaults(defineProps<{
|
|
|
|
url: string;
|
|
|
|
detail?: boolean;
|
|
|
|
compact?: boolean;
|
2023-07-21 00:57:21 +00:00
|
|
|
showActions?: boolean;
|
2022-01-15 23:24:53 +00:00
|
|
|
}>(), {
|
|
|
|
detail: false,
|
|
|
|
compact: false,
|
2023-07-21 00:57:21 +00:00
|
|
|
showActions: true,
|
2022-01-15 23:24:53 +00:00
|
|
|
});
|
|
|
|
|
2022-09-21 23:20:31 +00:00
|
|
|
const MOBILE_THRESHOLD = 500;
|
|
|
|
const isMobile = $ref(deviceKind === 'smartphone' || window.innerWidth <= MOBILE_THRESHOLD);
|
|
|
|
|
2022-01-15 23:24:53 +00:00
|
|
|
const self = props.url.startsWith(local);
|
|
|
|
const attr = self ? 'to' : 'href';
|
|
|
|
const target = self ? null : '_blank';
|
|
|
|
let fetching = $ref(true);
|
|
|
|
let title = $ref<string | null>(null);
|
|
|
|
let description = $ref<string | null>(null);
|
|
|
|
let thumbnail = $ref<string | null>(null);
|
|
|
|
let icon = $ref<string | null>(null);
|
|
|
|
let sitename = $ref<string | null>(null);
|
2023-11-03 10:44:17 +00:00
|
|
|
let player = $ref<SummalyResult['player']>({
|
2022-01-15 23:24:53 +00:00
|
|
|
url: null,
|
|
|
|
width: null,
|
2022-07-05 14:13:28 +00:00
|
|
|
height: null,
|
2023-11-03 10:44:17 +00:00
|
|
|
allow: [],
|
|
|
|
});
|
2022-01-15 23:24:53 +00:00
|
|
|
let playerEnabled = $ref(false);
|
|
|
|
let tweetId = $ref<string | null>(null);
|
|
|
|
let tweetExpanded = $ref(props.detail);
|
2022-12-03 10:42:05 +00:00
|
|
|
const embedId = `embed${Math.random().toString().replace(/\D/, '')}`;
|
2022-01-15 23:24:53 +00:00
|
|
|
let tweetHeight = $ref(150);
|
2022-12-30 05:24:00 +00:00
|
|
|
let unknownUrl = $ref(false);
|
2022-01-15 23:24:53 +00:00
|
|
|
|
|
|
|
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-01-15 23:24:53 +00:00
|
|
|
|
2023-08-22 06:56:36 +00:00
|
|
|
if (requestUrl.hostname === 'twitter.com' || requestUrl.hostname === 'mobile.twitter.com' || requestUrl.hostname === 'x.com' || requestUrl.hostname === 'mobile.x.com') {
|
2022-01-15 23:24:53 +00:00
|
|
|
const m = requestUrl.pathname.match(/^\/.+\/status(?:es)?\/(\d+)/);
|
|
|
|
if (m) tweetId = m[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (requestUrl.hostname === 'music.youtube.com' && requestUrl.pathname.match('^/(?:watch|channel)')) {
|
|
|
|
requestUrl.hostname = 'www.youtube.com';
|
|
|
|
}
|
|
|
|
|
|
|
|
requestUrl.hash = '';
|
|
|
|
|
2023-05-17 20:00:28 +00:00
|
|
|
window.fetch(`/url?url=${encodeURIComponent(requestUrl.href)}&lang=${versatileLang}`)
|
|
|
|
.then(res => {
|
|
|
|
if (!res.ok) {
|
|
|
|
fetching = false;
|
|
|
|
unknownUrl = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res.json();
|
|
|
|
})
|
|
|
|
.then((info: SummalyResult) => {
|
|
|
|
if (info.url == null) {
|
|
|
|
fetching = false;
|
|
|
|
unknownUrl = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fetching = false;
|
|
|
|
unknownUrl = false;
|
|
|
|
|
2022-01-15 23:24:53 +00:00
|
|
|
title = info.title;
|
|
|
|
description = info.description;
|
|
|
|
thumbnail = info.thumbnail;
|
|
|
|
icon = info.icon;
|
|
|
|
sitename = info.sitename;
|
|
|
|
player = info.player;
|
2022-06-10 05:36:55 +00:00
|
|
|
});
|
2022-01-15 23:24:53 +00:00
|
|
|
|
|
|
|
function adjustTweetHeight(message: any) {
|
|
|
|
if (message.origin !== 'https://platform.twitter.com') return;
|
|
|
|
const embed = message.data?.['twttr.embed'];
|
|
|
|
if (embed?.method !== 'twttr.private.resize') return;
|
|
|
|
if (embed?.id !== embedId) return;
|
|
|
|
const height = embed?.params[0]?.height;
|
|
|
|
if (height) tweetHeight = height;
|
|
|
|
}
|
|
|
|
|
2022-09-21 23:20:31 +00:00
|
|
|
const openPlayer = (): void => {
|
2023-04-04 00:38:34 +00:00
|
|
|
os.popup(defineAsyncComponent(() => import('@/components/MkYouTubePlayer.vue')), {
|
2022-09-21 23:20:31 +00:00
|
|
|
url: requestUrl.href,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-01-15 23:24:53 +00:00
|
|
|
(window as any).addEventListener('message', adjustTweetHeight);
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2022-01-15 23:24:53 +00:00
|
|
|
onUnmounted(() => {
|
|
|
|
(window as any).removeEventListener('message', adjustTweetHeight);
|
2020-01-29 19:37:25 +00:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2023-01-14 02:59:08 +00:00
|
|
|
<style lang="scss" module>
|
2022-12-27 09:29:39 +00:00
|
|
|
.player {
|
2020-01-29 19:37:25 +00:00
|
|
|
position: relative;
|
|
|
|
width: 100%;
|
2023-01-14 02:59:08 +00:00
|
|
|
}
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2023-01-14 02:59:08 +00:00
|
|
|
.disablePlayer {
|
|
|
|
position: absolute;
|
|
|
|
top: -1.5em;
|
|
|
|
right: 0;
|
|
|
|
font-size: 1em;
|
|
|
|
width: 1.5em;
|
|
|
|
height: 1.5em;
|
|
|
|
padding: 0;
|
|
|
|
margin: 0;
|
|
|
|
color: var(--fg);
|
|
|
|
background: rgba(128, 128, 128, 0.2);
|
|
|
|
opacity: 0.7;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
opacity: 0.9;
|
2020-01-29 19:37:25 +00:00
|
|
|
}
|
2023-01-14 02:59:08 +00:00
|
|
|
}
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2023-01-14 02:59:08 +00:00
|
|
|
.playerIframe {
|
|
|
|
height: 100%;
|
|
|
|
left: 0;
|
|
|
|
position: absolute;
|
|
|
|
top: 0;
|
|
|
|
width: 100%;
|
2020-01-29 19:37:25 +00:00
|
|
|
}
|
|
|
|
|
2023-01-14 02:59:08 +00:00
|
|
|
.link {
|
|
|
|
position: relative;
|
|
|
|
display: block;
|
|
|
|
font-size: 14px;
|
|
|
|
box-shadow: 0 0 0 1px var(--divider);
|
|
|
|
border-radius: 8px;
|
|
|
|
overflow: clip;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
text-decoration: none;
|
|
|
|
border-color: rgba(0, 0, 0, 0.2);
|
|
|
|
|
|
|
|
> .body > .header > .title {
|
|
|
|
text-decoration: underline;
|
2020-01-29 19:37:25 +00:00
|
|
|
}
|
2023-01-14 02:59:08 +00:00
|
|
|
}
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2023-01-14 02:59:08 +00:00
|
|
|
&.compact {
|
|
|
|
> .body {
|
|
|
|
> .header .title, .text, .footer {
|
|
|
|
overflow: hidden;
|
|
|
|
white-space: nowrap;
|
|
|
|
text-overflow: ellipsis;
|
2020-01-29 19:37:25 +00:00
|
|
|
}
|
|
|
|
}
|
2023-01-14 02:59:08 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2023-01-14 02:59:08 +00:00
|
|
|
.thumbnail {
|
|
|
|
position: absolute;
|
|
|
|
width: 100px;
|
|
|
|
height: 100%;
|
|
|
|
background-position: center;
|
|
|
|
background-size: cover;
|
2023-09-10 09:40:20 +00:00
|
|
|
background-color: var(--bg);
|
2023-01-14 02:59:08 +00:00
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
|
|
|
|
|
|
|
& + .body {
|
|
|
|
left: 100px;
|
|
|
|
width: calc(100% - 100px);
|
|
|
|
}
|
|
|
|
}
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2023-01-14 02:59:08 +00:00
|
|
|
.body {
|
|
|
|
position: relative;
|
|
|
|
box-sizing: border-box;
|
|
|
|
padding: 16px;
|
|
|
|
}
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2023-01-14 02:59:08 +00:00
|
|
|
.header {
|
|
|
|
margin-bottom: 8px;
|
|
|
|
}
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2023-01-14 02:59:08 +00:00
|
|
|
.title {
|
|
|
|
margin: 0;
|
|
|
|
font-size: 1em;
|
|
|
|
}
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2023-01-14 02:59:08 +00:00
|
|
|
.text {
|
|
|
|
margin: 0;
|
|
|
|
font-size: 0.8em;
|
|
|
|
}
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2023-01-14 02:59:08 +00:00
|
|
|
.footer {
|
|
|
|
margin-top: 8px;
|
|
|
|
height: 16px;
|
|
|
|
}
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2023-01-14 02:59:08 +00:00
|
|
|
.siteIcon {
|
|
|
|
display: inline-block;
|
|
|
|
width: 16px;
|
|
|
|
height: 16px;
|
|
|
|
margin-right: 4px;
|
|
|
|
vertical-align: top;
|
|
|
|
}
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2023-01-14 02:59:08 +00:00
|
|
|
.siteName {
|
|
|
|
display: inline-block;
|
|
|
|
margin: 0;
|
|
|
|
color: var(--urlPreviewInfo);
|
|
|
|
font-size: 0.8em;
|
|
|
|
line-height: 16px;
|
|
|
|
vertical-align: top;
|
|
|
|
}
|
2022-12-28 09:22:46 +00:00
|
|
|
|
2023-01-14 02:59:08 +00:00
|
|
|
.action {
|
|
|
|
display: flex;
|
|
|
|
gap: 6px;
|
|
|
|
flex-wrap: wrap;
|
|
|
|
margin-top: 6px;
|
2020-01-29 19:37:25 +00:00
|
|
|
}
|
2022-12-25 23:40:13 +00:00
|
|
|
|
|
|
|
@container (max-width: 400px) {
|
2023-01-14 02:59:08 +00:00
|
|
|
.link {
|
|
|
|
font-size: 12px;
|
|
|
|
}
|
2022-12-25 23:40:13 +00:00
|
|
|
|
2023-01-14 02:59:08 +00:00
|
|
|
.thumbnail {
|
|
|
|
height: 80px;
|
|
|
|
}
|
2022-12-25 23:40:13 +00:00
|
|
|
|
2023-01-14 02:59:08 +00:00
|
|
|
.body {
|
|
|
|
padding: 12px;
|
2022-12-25 23:40:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@container (max-width: 350px) {
|
2023-01-14 02:59:08 +00:00
|
|
|
.link {
|
|
|
|
font-size: 10px;
|
2022-12-25 23:40:13 +00:00
|
|
|
|
2023-01-14 02:59:08 +00:00
|
|
|
&.compact {
|
2022-12-25 23:40:13 +00:00
|
|
|
> .thumbnail {
|
2023-01-14 02:59:08 +00:00
|
|
|
position: absolute;
|
|
|
|
width: 56px;
|
|
|
|
height: 100%;
|
2022-12-25 23:40:13 +00:00
|
|
|
}
|
|
|
|
|
2023-01-14 02:59:08 +00:00
|
|
|
> .body {
|
|
|
|
left: 56px;
|
|
|
|
width: calc(100% - 56px);
|
|
|
|
padding: 4px;
|
2022-12-25 23:40:13 +00:00
|
|
|
|
2023-01-14 02:59:08 +00:00
|
|
|
> .header {
|
|
|
|
margin-bottom: 2px;
|
2022-12-25 23:40:13 +00:00
|
|
|
}
|
|
|
|
|
2023-01-14 02:59:08 +00:00
|
|
|
> .footer {
|
|
|
|
margin-top: 2px;
|
2022-12-25 23:40:13 +00:00
|
|
|
}
|
|
|
|
}
|
2023-01-14 02:59:08 +00:00
|
|
|
}
|
|
|
|
}
|
2022-12-25 23:40:13 +00:00
|
|
|
|
2023-01-14 02:59:08 +00:00
|
|
|
.thumbnail {
|
|
|
|
height: 70px;
|
|
|
|
}
|
2022-12-25 23:40:13 +00:00
|
|
|
|
2023-01-14 02:59:08 +00:00
|
|
|
.body {
|
|
|
|
padding: 8px;
|
|
|
|
}
|
2022-12-25 23:40:13 +00:00
|
|
|
|
2023-01-14 02:59:08 +00:00
|
|
|
.header {
|
|
|
|
margin-bottom: 4px;
|
|
|
|
}
|
2022-12-25 23:40:13 +00:00
|
|
|
|
2023-01-14 02:59:08 +00:00
|
|
|
.footer {
|
|
|
|
margin-top: 4px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.siteIcon {
|
|
|
|
width: 12px;
|
|
|
|
height: 12px;
|
2022-12-25 23:40:13 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-29 19:37:25 +00:00
|
|
|
</style>
|