2018-02-04 23:25:19 -06:00
|
|
|
<template>
|
2018-08-22 10:34:35 -05:00
|
|
|
<div v-if="player.url" class="player" :style="`padding: ${(player.height || 0) / (player.width || 1) * 100}% 0 0`">
|
2018-08-22 10:40:32 -05:00
|
|
|
<iframe :src="player.url" :width="player.width || '100%'" :heigth="player.height || 250" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen />
|
2018-08-22 10:34:35 -05:00
|
|
|
</div>
|
2018-07-25 14:55:39 -05:00
|
|
|
<div v-else-if="tweetUrl && detail" class="twitter">
|
|
|
|
<blockquote ref="tweet" class="twitter-tweet" :data-theme="$store.state.device.darkmode ? 'dark' : null">
|
|
|
|
<a :href="url"></a>
|
|
|
|
</blockquote>
|
|
|
|
</div>
|
2018-04-22 05:33:06 -05:00
|
|
|
<div v-else class="mk-url-preview">
|
2019-01-05 21:56:13 -06:00
|
|
|
<a :class="{ mini, compact }" :href="url" target="_blank" :title="url" v-if="!fetching">
|
2018-03-18 12:56:35 -05:00
|
|
|
<div class="thumbnail" v-if="thumbnail" :style="`background-image: url(${thumbnail})`"></div>
|
|
|
|
<article>
|
|
|
|
<header>
|
2019-01-05 21:56:13 -06:00
|
|
|
<h1 :title="title">{{ title }}</h1>
|
2018-03-18 12:56:35 -05:00
|
|
|
</header>
|
2019-01-05 21:56:13 -06:00
|
|
|
<p v-if="description" :title="description">{{ description.length > 85 ? description.slice(0, 85) + '…' : description }}</p>
|
2018-03-18 12:56:35 -05:00
|
|
|
<footer>
|
|
|
|
<img class="icon" v-if="icon" :src="icon"/>
|
2019-01-05 21:56:13 -06:00
|
|
|
<p :title="sitename">{{ sitename }}</p>
|
2018-03-18 12:56:35 -05:00
|
|
|
</footer>
|
|
|
|
</article>
|
|
|
|
</a>
|
|
|
|
</div>
|
2018-02-04 23:25:19 -06:00
|
|
|
</template>
|
|
|
|
|
2018-02-11 08:35:32 -06:00
|
|
|
<script lang="ts">
|
|
|
|
import Vue from 'vue';
|
2018-03-18 13:20:10 -05:00
|
|
|
import { url as misskeyUrl } from '../../../config';
|
2018-02-11 08:35:32 -06:00
|
|
|
|
2018-08-29 13:32:42 -05:00
|
|
|
// THIS IS THE WHITELIST FOR THE EMBED PLAYER
|
|
|
|
const whiteList = [
|
|
|
|
'afreecatv.com',
|
|
|
|
'aparat.com',
|
|
|
|
'applemusic.com',
|
|
|
|
'amazon.com',
|
|
|
|
'awa.fm',
|
|
|
|
'bandcamp.com',
|
|
|
|
'bbc.co.uk',
|
|
|
|
'beatport.com',
|
|
|
|
'bilibili.com',
|
|
|
|
'boomstream.com',
|
|
|
|
'breakers.tv',
|
|
|
|
'cam4.com',
|
|
|
|
'cavelis.net',
|
|
|
|
'chaturbate.com',
|
|
|
|
'cnn.com',
|
|
|
|
'cybergame.tv',
|
|
|
|
'dailymotion.com',
|
|
|
|
'deezer.com',
|
|
|
|
'djlive.pl',
|
|
|
|
'e-onkyo.com',
|
|
|
|
'eventials.com',
|
|
|
|
'facebook.com',
|
|
|
|
'fc2.com',
|
|
|
|
'gameplank.tv',
|
|
|
|
'goodgame.ru',
|
|
|
|
'google.com',
|
|
|
|
'hardtunes.com',
|
|
|
|
'instagram.com',
|
|
|
|
'johnnylooch.com',
|
|
|
|
'kexp.org',
|
|
|
|
'lahzenegar.com',
|
|
|
|
'liveedu.tv',
|
|
|
|
'livetube.cc',
|
|
|
|
'livestream.com',
|
|
|
|
'meridix.com',
|
|
|
|
'mixcloud.com',
|
|
|
|
'mixer.com',
|
|
|
|
'mobcrush.com',
|
|
|
|
'mylive.in.th',
|
|
|
|
'myspace.com',
|
|
|
|
'netflix.com',
|
|
|
|
'newretrowave.com',
|
|
|
|
'nhk.or.jp',
|
|
|
|
'nicovideo.jp',
|
|
|
|
'nico.ms',
|
|
|
|
'noisetrade.com',
|
|
|
|
'nood.tv',
|
|
|
|
'npr.org',
|
|
|
|
'openrec.tv',
|
|
|
|
'pandora.com',
|
|
|
|
'pandora.tv',
|
|
|
|
'picarto.tv',
|
|
|
|
'pscp.tv',
|
|
|
|
'restream.io',
|
|
|
|
'reverbnation.com',
|
|
|
|
'sermonaudio.com',
|
|
|
|
'smashcast.tv',
|
|
|
|
'songkick.com',
|
|
|
|
'soundcloud.com',
|
|
|
|
'spinninrecords.com',
|
|
|
|
'spotify.com',
|
|
|
|
'stitcher.com',
|
|
|
|
'stream.me',
|
|
|
|
'switchboard.live',
|
|
|
|
'tunein.com',
|
|
|
|
'twitcasting.tv',
|
|
|
|
'twitch.tv',
|
|
|
|
'twitter.com',
|
|
|
|
'vaughnlive.tv',
|
|
|
|
'veoh.com',
|
|
|
|
'vimeo.com',
|
|
|
|
'watchpeoplecode.com',
|
|
|
|
'web.tv',
|
|
|
|
'youtube.com',
|
|
|
|
'youtu.be'
|
|
|
|
];
|
|
|
|
|
2018-02-11 08:35:32 -06:00
|
|
|
export default Vue.extend({
|
2018-07-25 14:55:39 -05:00
|
|
|
props: {
|
|
|
|
url: {
|
|
|
|
type: String,
|
|
|
|
require: true
|
|
|
|
},
|
2018-08-29 13:32:42 -05:00
|
|
|
|
2018-07-25 14:55:39 -05:00
|
|
|
detail: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false
|
2018-08-31 23:08:43 -05:00
|
|
|
},
|
|
|
|
|
2019-01-05 21:56:13 -06:00
|
|
|
compact: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
|
2018-08-31 23:08:43 -05:00
|
|
|
mini: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false
|
2018-07-25 14:55:39 -05:00
|
|
|
}
|
|
|
|
},
|
2018-08-29 13:32:42 -05:00
|
|
|
|
2018-02-11 08:35:32 -06:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
fetching: true,
|
|
|
|
title: null,
|
|
|
|
description: null,
|
|
|
|
thumbnail: null,
|
|
|
|
icon: null,
|
2018-03-18 12:56:35 -05:00
|
|
|
sitename: null,
|
2018-08-22 10:34:35 -05:00
|
|
|
player: {
|
|
|
|
url: null,
|
|
|
|
width: null,
|
|
|
|
height: null
|
|
|
|
},
|
2018-07-25 10:03:32 -05:00
|
|
|
tweetUrl: null,
|
2018-03-18 13:20:10 -05:00
|
|
|
misskeyUrl
|
2018-02-11 08:35:32 -06:00
|
|
|
};
|
|
|
|
},
|
2018-08-29 13:32:42 -05:00
|
|
|
|
2018-02-11 08:35:32 -06:00
|
|
|
created() {
|
2018-03-18 12:56:35 -05:00
|
|
|
const url = new URL(this.url);
|
|
|
|
|
2018-08-09 02:44:34 -05:00
|
|
|
if (this.detail && url.hostname == 'twitter.com' && /^\/.+\/status(es)?\/\d+/.test(url.pathname)) {
|
2018-07-25 10:03:32 -05:00
|
|
|
this.tweetUrl = url;
|
|
|
|
const twttr = (window as any).twttr || {};
|
|
|
|
const loadTweet = () => twttr.widgets.load(this.$refs.tweet);
|
|
|
|
|
|
|
|
if (twttr.widgets) {
|
|
|
|
Vue.nextTick(loadTweet);
|
|
|
|
} else {
|
|
|
|
const wjsId = 'twitter-wjs';
|
|
|
|
if (!document.getElementById(wjsId)) {
|
|
|
|
const head = document.getElementsByTagName('head')[0];
|
|
|
|
const script = document.createElement('script');
|
|
|
|
script.setAttribute('id', wjsId);
|
|
|
|
script.setAttribute('src', 'https://platform.twitter.com/widgets.js');
|
|
|
|
head.appendChild(script);
|
|
|
|
}
|
|
|
|
twttr.ready = loadTweet;
|
|
|
|
(window as any).twttr = twttr;
|
|
|
|
}
|
2018-08-08 14:21:25 -05:00
|
|
|
return;
|
|
|
|
}
|
2018-08-29 13:32:42 -05:00
|
|
|
|
2018-12-12 06:19:52 -06:00
|
|
|
if (url.hostname === 'music.youtube.com')
|
|
|
|
url.hostname = 'youtube.com';
|
|
|
|
|
2018-09-01 09:12:51 -05:00
|
|
|
fetch(`/url?url=${encodeURIComponent(this.url)}`).then(res => {
|
2018-08-08 14:21:25 -05:00
|
|
|
res.json().then(info => {
|
2018-08-29 13:32:42 -05:00
|
|
|
if (info.url == null) return;
|
|
|
|
this.title = info.title;
|
|
|
|
this.description = info.description;
|
|
|
|
this.thumbnail = info.thumbnail;
|
|
|
|
this.icon = info.icon;
|
|
|
|
this.sitename = info.sitename;
|
|
|
|
this.fetching = false;
|
|
|
|
if (whiteList.some(x => x == url.hostname || url.hostname.endsWith(`.${x}`))) {
|
|
|
|
this.player = info.player;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|
2018-02-11 08:35:32 -06:00
|
|
|
});
|
2018-02-04 23:25:19 -06:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="stylus" scoped>
|
2018-08-23 02:25:36 -05:00
|
|
|
.player
|
2018-08-22 10:34:35 -05:00
|
|
|
position relative
|
2018-03-18 12:56:35 -05:00
|
|
|
width 100%
|
|
|
|
|
2018-08-22 10:34:35 -05:00
|
|
|
> iframe
|
|
|
|
height 100%
|
|
|
|
left 0
|
|
|
|
position absolute
|
|
|
|
top 0
|
|
|
|
width 100%
|
|
|
|
|
2018-09-27 08:50:34 -05:00
|
|
|
.mk-url-preview
|
2018-04-22 05:33:06 -05:00
|
|
|
> a
|
|
|
|
display block
|
2018-05-28 00:59:55 -05:00
|
|
|
font-size 14px
|
2018-12-29 23:00:57 -06:00
|
|
|
border solid var(--lineWidth) var(--urlPreviewBorder)
|
2018-04-22 05:33:06 -05:00
|
|
|
border-radius 4px
|
|
|
|
overflow hidden
|
2018-02-11 08:35:32 -06:00
|
|
|
|
2018-04-22 05:33:06 -05:00
|
|
|
&:hover
|
|
|
|
text-decoration none
|
2018-09-27 08:50:34 -05:00
|
|
|
border-color var(--urlPreviewBorderHover)
|
2018-02-11 08:35:32 -06:00
|
|
|
|
2018-04-22 05:33:06 -05:00
|
|
|
> article > header > h1
|
|
|
|
text-decoration underline
|
2018-02-11 08:35:32 -06:00
|
|
|
|
2018-04-22 05:33:06 -05:00
|
|
|
> .thumbnail
|
|
|
|
position absolute
|
|
|
|
width 100px
|
|
|
|
height 100%
|
|
|
|
background-position center
|
|
|
|
background-size cover
|
2018-02-11 08:35:32 -06:00
|
|
|
|
2018-04-22 05:33:06 -05:00
|
|
|
& + article
|
|
|
|
left 100px
|
|
|
|
width calc(100% - 100px)
|
2018-02-11 08:35:32 -06:00
|
|
|
|
2018-04-22 05:33:06 -05:00
|
|
|
> article
|
|
|
|
padding 16px
|
2018-02-11 08:35:32 -06:00
|
|
|
|
2018-04-22 05:33:06 -05:00
|
|
|
> header
|
|
|
|
margin-bottom 8px
|
2018-02-11 08:35:32 -06:00
|
|
|
|
2018-04-22 05:33:06 -05:00
|
|
|
> h1
|
|
|
|
margin 0
|
|
|
|
font-size 1em
|
2018-09-27 08:50:34 -05:00
|
|
|
color var(--urlPreviewTitle)
|
2018-02-11 08:35:32 -06:00
|
|
|
|
|
|
|
> p
|
|
|
|
margin 0
|
2018-09-27 08:50:34 -05:00
|
|
|
color var(--urlPreviewText)
|
2018-02-11 08:35:32 -06:00
|
|
|
font-size 0.8em
|
|
|
|
|
2018-04-22 05:33:06 -05:00
|
|
|
> footer
|
|
|
|
margin-top 8px
|
|
|
|
height 16px
|
2018-02-11 08:35:32 -06:00
|
|
|
|
2018-04-22 05:33:06 -05:00
|
|
|
> img
|
|
|
|
display inline-block
|
|
|
|
width 16px
|
|
|
|
height 16px
|
|
|
|
margin-right 4px
|
|
|
|
vertical-align top
|
|
|
|
|
|
|
|
> p
|
|
|
|
display inline-block
|
|
|
|
margin 0
|
2018-09-27 08:50:34 -05:00
|
|
|
color var(--urlPreviewInfo)
|
2018-04-22 05:33:06 -05:00
|
|
|
font-size 0.8em
|
|
|
|
line-height 16px
|
|
|
|
vertical-align top
|
|
|
|
|
2018-05-17 09:18:24 -05:00
|
|
|
@media (max-width 700px)
|
|
|
|
> .thumbnail
|
|
|
|
position relative
|
|
|
|
width 100%
|
|
|
|
height 100px
|
|
|
|
|
|
|
|
& + article
|
|
|
|
left 0
|
|
|
|
width 100%
|
|
|
|
|
2018-05-28 00:59:55 -05:00
|
|
|
@media (max-width 550px)
|
|
|
|
font-size 12px
|
|
|
|
|
|
|
|
> .thumbnail
|
|
|
|
height 80px
|
|
|
|
|
|
|
|
> article
|
|
|
|
padding 12px
|
|
|
|
|
2018-04-22 05:33:06 -05:00
|
|
|
@media (max-width 500px)
|
2018-05-28 00:59:55 -05:00
|
|
|
font-size 10px
|
2018-04-22 05:33:06 -05:00
|
|
|
|
|
|
|
> .thumbnail
|
2018-05-17 09:18:24 -05:00
|
|
|
height 70px
|
2018-04-22 05:33:06 -05:00
|
|
|
|
|
|
|
> article
|
|
|
|
padding 8px
|
2018-02-04 23:25:19 -06:00
|
|
|
|
2018-05-28 00:59:55 -05:00
|
|
|
> header
|
|
|
|
margin-bottom 4px
|
|
|
|
|
|
|
|
> footer
|
|
|
|
margin-top 4px
|
|
|
|
|
|
|
|
> img
|
|
|
|
width 12px
|
|
|
|
height 12px
|
|
|
|
|
2019-01-05 21:56:13 -06:00
|
|
|
&.compact
|
|
|
|
> .thumbnail
|
|
|
|
position: absolute
|
|
|
|
width 56px
|
|
|
|
height 100%
|
|
|
|
|
|
|
|
> article
|
|
|
|
left 56px
|
|
|
|
width calc(100% - 56px)
|
|
|
|
padding 4px
|
|
|
|
|
|
|
|
> header
|
|
|
|
margin-bottom 2px
|
|
|
|
|
|
|
|
> footer
|
|
|
|
margin-top 2px
|
|
|
|
|
2018-08-31 23:08:43 -05:00
|
|
|
&.mini
|
|
|
|
font-size 10px
|
|
|
|
|
|
|
|
> .thumbnail
|
|
|
|
position relative
|
|
|
|
width 100%
|
|
|
|
height 60px
|
|
|
|
|
|
|
|
> article
|
|
|
|
left 0
|
|
|
|
width 100%
|
|
|
|
padding 8px
|
|
|
|
|
|
|
|
> header
|
|
|
|
margin-bottom 4px
|
|
|
|
|
|
|
|
> footer
|
|
|
|
margin-top 4px
|
|
|
|
|
|
|
|
> img
|
|
|
|
width 12px
|
|
|
|
height 12px
|
|
|
|
|
2019-01-05 21:56:13 -06:00
|
|
|
&.compact
|
|
|
|
> .thumbnail
|
|
|
|
position: absolute
|
|
|
|
width 56px
|
|
|
|
height 100%
|
|
|
|
|
|
|
|
> article
|
|
|
|
left 56px
|
|
|
|
width calc(100% - 56px)
|
|
|
|
padding 4px
|
|
|
|
|
|
|
|
> header
|
|
|
|
margin-bottom 2px
|
|
|
|
|
|
|
|
> footer
|
|
|
|
margin-top 2px
|
|
|
|
|
|
|
|
&.compact
|
|
|
|
> article
|
|
|
|
> header h1, p, footer
|
|
|
|
overflow: hidden;
|
|
|
|
white-space: nowrap;
|
|
|
|
text-overflow: ellipsis;
|
2018-02-04 23:25:19 -06:00
|
|
|
</style>
|