Add player

This commit is contained in:
Acid Chicken (硫酸鶏) 2018-08-09 16:44:34 +09:00
parent 01d3f5f09d
commit 7289d5b401

View file

@ -1,12 +1,6 @@
<template> <template>
<iframe v-if="youtubeId" type="text/html" height="250" <iframe v-if="player"
:src="`https://www.youtube.com/embed/${youtubeId}?origin=${misskeyUrl}`" :src="player"
frameborder="0"/>
<iframe v-else-if="spotifyId"
:src="`https://open.spotify.com/embed/track/${spotifyId}`"
frameborder="0" allowtransparency="true" allow="encrypted-media" />
<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 /> frameborder="0" allow="autoplay; encrypted-media" allowfullscreen />
<div v-else-if="tweetUrl && detail" class="twitter"> <div v-else-if="tweetUrl && detail" class="twitter">
<blockquote ref="tweet" class="twitter-tweet" :data-theme="$store.state.device.darkmode ? 'dark' : null"> <blockquote ref="tweet" class="twitter-tweet" :data-theme="$store.state.device.darkmode ? 'dark' : null">
@ -54,10 +48,7 @@ export default Vue.extend({
thumbnail: null, thumbnail: null,
icon: null, icon: null,
sitename: null, sitename: null,
youtubeId: null, player: null,
spotifyId: null,
nicovideoId: null,
position: null,
tweetUrl: null, tweetUrl: null,
misskeyUrl misskeyUrl
}; };
@ -65,23 +56,7 @@ export default Vue.extend({
created() { created() {
const url = new URL(this.url); const url = new URL(this.url);
if (url.hostname == 'www.youtube.com') { if (this.detail && url.hostname == 'twitter.com' && /^\/.+\/status(es)?\/\d+/.test(url.pathname)) {
this.youtubeId = url.searchParams.get('v');
return;
} else if (url.hostname == 'youtu.be') {
this.youtubeId = url.pathname;
return;
} else if (url.hostname == 'open.spotify.com') {
this.spotifyId = url.pathname.split('/').reverse().filter(x => x !== '')[0];
return;
} else if (['nicovideo.jp', 'www.nicovideo.jp', 'nico.ms'].includes(url.hostname)) {
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;
}
} else if (this.detail && url.hostname == 'twitter.com' && /^\/.+\/status(es)?\/\d+/.test(url.pathname)) {
this.tweetUrl = url; this.tweetUrl = url;
const twttr = (window as any).twttr || {}; const twttr = (window as any).twttr || {};
const loadTweet = () => twttr.widgets.load(this.$refs.tweet); const loadTweet = () => twttr.widgets.load(this.$refs.tweet);
@ -100,13 +75,13 @@ export default Vue.extend({
twttr.ready = loadTweet; twttr.ready = loadTweet;
(window as any).twttr = twttr; (window as any).twttr = twttr;
} }
return; } else {
}
fetch('/url?url=' + encodeURIComponent(this.url)).then(res => { fetch('/url?url=' + encodeURIComponent(this.url)).then(res => {
res.json().then(info => { res.json().then(info => {
this.title = info.title; this.title = info.title;
this.description = info.description; this.description = info.description;
this.thumbnail = info.thumbnail; this.thumbnail = info.thumbnail;
this.player = info.player;
this.icon = info.icon; this.icon = info.icon;
this.sitename = info.sitename; this.sitename = info.sitename;
@ -114,6 +89,7 @@ export default Vue.extend({
}); });
}); });
} }
}
}); });
</script> </script>