diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2018-07-26 02:31:00 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-07-26 02:31:00 +0900 |
| commit | 8736c9dfe696c06f378375fa693eb86fc7ca7b1d (patch) | |
| tree | 111a43e34b5c14ef0740232f3b82c7aff2be9162 | |
| parent | Fix #1961 (diff) | |
| parent | Embed tweet when tweet url attached (diff) | |
| download | sharkey-8736c9dfe696c06f378375fa693eb86fc7ca7b1d.tar.gz sharkey-8736c9dfe696c06f378375fa693eb86fc7ca7b1d.tar.bz2 sharkey-8736c9dfe696c06f378375fa693eb86fc7ca7b1d.zip | |
Merge pull request #1977 from yarnaimo/embedded-tweet
ツイートの埋め込み
| -rw-r--r-- | src/client/app/common/views/components/url-preview.vue | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/client/app/common/views/components/url-preview.vue b/src/client/app/common/views/components/url-preview.vue index 38979871c1..a630178af1 100644 --- a/src/client/app/common/views/components/url-preview.vue +++ b/src/client/app/common/views/components/url-preview.vue @@ -2,6 +2,9 @@ <iframe v-if="youtubeId" type="text/html" height="250" :src="`https://www.youtube.com/embed/${youtubeId}?origin=${misskeyUrl}`" frameborder="0"/> +<blockquote v-else-if="tweetUrl" class="twitter-tweet" ref="tweet"> + <a :href="url"></a> +</blockquote> <div v-else class="mk-url-preview"> <a :href="url" target="_blank" :title="url" v-if="!fetching"> <div class="thumbnail" v-if="thumbnail" :style="`background-image: url(${thumbnail})`"></div> @@ -34,6 +37,7 @@ export default Vue.extend({ icon: null, sitename: null, youtubeId: null, + tweetUrl: null, misskeyUrl }; }, @@ -44,6 +48,25 @@ export default Vue.extend({ this.youtubeId = url.searchParams.get('v'); } else if (url.hostname == 'youtu.be') { this.youtubeId = url.pathname; + } else if (url.hostname == 'twitter.com' && /^\/.+\/status(es)?\/\d+/.test(url.pathname)) { + 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; + } } else { fetch('/url?url=' + encodeURIComponent(this.url)).then(res => { res.json().then(info => { |