2018-02-05 14:25:19 +09:00
|
|
|
<template>
|
2018-03-19 02:56:35 +09:00
|
|
|
<iframe v-if="youtubeId" type="text/html" height="250"
|
2018-03-19 03:46:13 +09:00
|
|
|
:src="`https://www.youtube.com/embed/${youtubeId}?origin=${misskeyUrl}`"
|
2018-03-19 02:56:35 +09:00
|
|
|
frameborder="0"/>
|
2018-08-09 03:32:09 +09:00
|
|
|
<iframe v-else-if="spotifyId"
|
|
|
|
:src="`https://open.spotify.com/embed/track/${spotifyId}`"
|
|
|
|
frameborder="0" allowtransparency="true" allow="encrypted-media" />
|
2018-08-09 04:05:28 +09:00
|
|
|
<iframe v-else-if="nicovideoId"
|
|
|
|
:src="`https://embed.nicovideo.jp/watch/${nicovideoId}?oldScript=1&referer=${misskeyUrl}&from=${position || '0'}&allowProgrammaticFullScreen=1`"
|
|
|
|
frameborder="0" allow="autoplay; encrypted-media" allowfullscreen />
|
2018-07-26 04:55:39 +09: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 19:33:06 +09:00
|
|
|
<div v-else class="mk-url-preview">
|
|
|
|
<a :href="url" target="_blank" :title="url" v-if="!fetching">
|
2018-03-19 02:56:35 +09:00
|
|
|
<div class="thumbnail" v-if="thumbnail" :style="`background-image: url(${thumbnail})`"></div>
|
|
|
|
<article>
|
|
|
|
<header>
|
|
|
|
<h1>{{ title }}</h1>
|
|
|
|
</header>
|
|
|
|
<p>{{ description }}</p>
|
|
|
|
<footer>
|
|
|
|
<img class="icon" v-if="icon" :src="icon"/>
|
|
|
|
<p>{{ sitename }}</p>
|
|
|
|
</footer>
|
|
|
|
</article>
|
|
|
|
</a>
|
|
|
|
</div>
|
2018-02-05 14:25:19 +09:00
|
|
|
</template>
|
|
|
|
|
2018-02-11 23:35:32 +09:00
|
|
|
<script lang="ts">
|
|
|
|
import Vue from 'vue';
|
2018-03-19 03:20:10 +09:00
|
|
|
import { url as misskeyUrl } from '../../../config';
|
2018-02-11 23:35:32 +09:00
|
|
|
|
|
|
|
export default Vue.extend({
|
2018-07-26 04:55:39 +09:00
|
|
|
props: {
|
|
|
|
url: {
|
|
|
|
type: String,
|
|
|
|
require: true
|
|
|
|
},
|
|
|
|
detail: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false
|
|
|
|
}
|
|
|
|
},
|
2018-02-11 23:35:32 +09:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
fetching: true,
|
|
|
|
title: null,
|
|
|
|
description: null,
|
|
|
|
thumbnail: null,
|
|
|
|
icon: null,
|
2018-03-19 02:56:35 +09:00
|
|
|
sitename: null,
|
2018-03-19 03:20:10 +09:00
|
|
|
youtubeId: null,
|
2018-08-09 04:05:28 +09:00
|
|
|
spotifyId: null,
|
|
|
|
nicovideoId: null,
|
|
|
|
position: null,
|
2018-07-26 00:03:32 +09:00
|
|
|
tweetUrl: null,
|
2018-03-19 03:20:10 +09:00
|
|
|
misskeyUrl
|
2018-02-11 23:35:32 +09:00
|
|
|
};
|
|
|
|
},
|
|
|
|
created() {
|
2018-03-19 02:56:35 +09:00
|
|
|
const url = new URL(this.url);
|
|
|
|
|
|
|
|
if (url.hostname == 'www.youtube.com') {
|
|
|
|
this.youtubeId = url.searchParams.get('v');
|
2018-08-09 04:21:25 +09:00
|
|
|
return;
|
2018-03-19 02:56:35 +09:00
|
|
|
} else if (url.hostname == 'youtu.be') {
|
|
|
|
this.youtubeId = url.pathname;
|
2018-08-09 04:21:25 +09:00
|
|
|
return;
|
2018-08-09 03:32:09 +09:00
|
|
|
} else if (url.hostname == 'open.spotify.com') {
|
|
|
|
this.spotifyId = url.pathname.split('/').reverse().filter(x => x !== '')[0];
|
2018-08-09 04:21:25 +09:00
|
|
|
return;
|
2018-08-09 04:05:28 +09:00
|
|
|
} else if (['nicovideo.jp', 'www.nicovideo.jp', 'nico.ms'].includes(url.hostname)) {
|
2018-08-09 04:21:25 +09:00
|
|
|
const id = url.pathname.split('/').reverse().filter(x => x !== '')[0];
|
|
|
|
if (['sm', 'nm', 'ax', 'ca', 'cd', 'cw', 'fx', 'ig', 'na', 'om', 'sd', 'sk', 'yk', 'yo', 'za', 'zb', 'zc', 'zd', 'ze', 'nl', 'so', ...Array(10).keys()].some(x => id.startsWith(x)) {
|
|
|
|
this.nicovideoId = id;
|
|
|
|
this.position = url.searchParams.get('from');
|
|
|
|
return;
|
|
|
|
}
|
2018-07-26 04:55:39 +09:00
|
|
|
} else if (this.detail && url.hostname == 'twitter.com' && /^\/.+\/status(es)?\/\d+/.test(url.pathname)) {
|
2018-07-26 00:03:32 +09: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-09 04:21:25 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
fetch('/url?url=' + encodeURIComponent(this.url)).then(res => {
|
|
|
|
res.json().then(info => {
|
|
|
|
this.title = info.title;
|
|
|
|
this.description = info.description;
|
|
|
|
this.thumbnail = info.thumbnail;
|
|
|
|
this.icon = info.icon;
|
|
|
|
this.sitename = info.sitename;
|
2018-03-19 02:56:35 +09:00
|
|
|
|
2018-08-09 04:21:25 +09:00
|
|
|
this.fetching = false;
|
2018-02-05 14:25:19 +09:00
|
|
|
});
|
2018-08-09 04:21:25 +09:00
|
|
|
});
|
2018-02-11 23:35:32 +09:00
|
|
|
}
|
|
|
|
});
|
2018-02-05 14:25:19 +09:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="stylus" scoped>
|
2018-03-19 02:56:35 +09:00
|
|
|
iframe
|
|
|
|
width 100%
|
|
|
|
|
2018-04-21 19:05:55 +09:00
|
|
|
root(isDark)
|
2018-04-22 19:33:06 +09:00
|
|
|
> a
|
|
|
|
display block
|
2018-05-28 14:59:55 +09:00
|
|
|
font-size 14px
|
2018-04-22 19:33:06 +09:00
|
|
|
border solid 1px isDark ? #191b1f : #eee
|
|
|
|
border-radius 4px
|
|
|
|
overflow hidden
|
2018-02-11 23:35:32 +09:00
|
|
|
|
2018-04-22 19:33:06 +09:00
|
|
|
&:hover
|
|
|
|
text-decoration none
|
|
|
|
border-color isDark ? #4f5561 : #ddd
|
2018-02-11 23:35:32 +09:00
|
|
|
|
2018-04-22 19:33:06 +09:00
|
|
|
> article > header > h1
|
|
|
|
text-decoration underline
|
2018-02-11 23:35:32 +09:00
|
|
|
|
2018-04-22 19:33:06 +09:00
|
|
|
> .thumbnail
|
|
|
|
position absolute
|
|
|
|
width 100px
|
|
|
|
height 100%
|
|
|
|
background-position center
|
|
|
|
background-size cover
|
2018-02-11 23:35:32 +09:00
|
|
|
|
2018-04-22 19:33:06 +09:00
|
|
|
& + article
|
|
|
|
left 100px
|
|
|
|
width calc(100% - 100px)
|
2018-02-11 23:35:32 +09:00
|
|
|
|
2018-04-22 19:33:06 +09:00
|
|
|
> article
|
|
|
|
padding 16px
|
2018-02-11 23:35:32 +09:00
|
|
|
|
2018-04-22 19:33:06 +09:00
|
|
|
> header
|
|
|
|
margin-bottom 8px
|
2018-02-11 23:35:32 +09:00
|
|
|
|
2018-04-22 19:33:06 +09:00
|
|
|
> h1
|
|
|
|
margin 0
|
|
|
|
font-size 1em
|
|
|
|
color isDark ? #d6dae0 : #555
|
2018-02-11 23:35:32 +09:00
|
|
|
|
|
|
|
> p
|
|
|
|
margin 0
|
2018-04-22 19:33:06 +09:00
|
|
|
color isDark ? #a4aab3 : #777
|
2018-02-11 23:35:32 +09:00
|
|
|
font-size 0.8em
|
|
|
|
|
2018-04-22 19:33:06 +09:00
|
|
|
> footer
|
|
|
|
margin-top 8px
|
|
|
|
height 16px
|
2018-02-11 23:35:32 +09:00
|
|
|
|
2018-04-22 19:33:06 +09:00
|
|
|
> img
|
|
|
|
display inline-block
|
|
|
|
width 16px
|
|
|
|
height 16px
|
|
|
|
margin-right 4px
|
|
|
|
vertical-align top
|
|
|
|
|
|
|
|
> p
|
|
|
|
display inline-block
|
|
|
|
margin 0
|
|
|
|
color isDark ? #b0b4bf : #666
|
|
|
|
font-size 0.8em
|
|
|
|
line-height 16px
|
|
|
|
vertical-align top
|
|
|
|
|
2018-05-17 23:18:24 +09:00
|
|
|
@media (max-width 700px)
|
|
|
|
> .thumbnail
|
|
|
|
position relative
|
|
|
|
width 100%
|
|
|
|
height 100px
|
|
|
|
|
|
|
|
& + article
|
|
|
|
left 0
|
|
|
|
width 100%
|
|
|
|
|
2018-05-28 14:59:55 +09:00
|
|
|
@media (max-width 550px)
|
|
|
|
font-size 12px
|
|
|
|
|
|
|
|
> .thumbnail
|
|
|
|
height 80px
|
|
|
|
|
|
|
|
> article
|
|
|
|
padding 12px
|
|
|
|
|
2018-04-22 19:33:06 +09:00
|
|
|
@media (max-width 500px)
|
2018-05-28 14:59:55 +09:00
|
|
|
font-size 10px
|
2018-04-22 19:33:06 +09:00
|
|
|
|
|
|
|
> .thumbnail
|
2018-05-17 23:18:24 +09:00
|
|
|
height 70px
|
2018-04-22 19:33:06 +09:00
|
|
|
|
|
|
|
> article
|
|
|
|
padding 8px
|
2018-02-05 14:25:19 +09:00
|
|
|
|
2018-05-28 14:59:55 +09:00
|
|
|
> header
|
|
|
|
margin-bottom 4px
|
|
|
|
|
|
|
|
> footer
|
|
|
|
margin-top 4px
|
|
|
|
|
|
|
|
> img
|
|
|
|
width 12px
|
|
|
|
height 12px
|
|
|
|
|
2018-04-21 19:05:55 +09:00
|
|
|
.mk-url-preview[data-darkmode]
|
|
|
|
root(true)
|
|
|
|
|
|
|
|
.mk-url-preview:not([data-darkmode])
|
|
|
|
root(false)
|
|
|
|
|
2018-02-05 14:25:19 +09:00
|
|
|
</style>
|