diff options
author | Vitaly Takmazov | 2023-06-19 23:23:47 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2023-06-20 01:04:07 +0300 |
commit | 6ec610fbdceaeadbbc184fb02e22a9c4dd13d0a9 (patch) | |
tree | 859d2060c2cd320ae957512a6f5f98c2e4789fe5 | |
parent | 3908fc8bbe5144bd5caa966789b7e4c9c521f6b2 (diff) |
embed: back to client-side Twitter embeds
-rw-r--r-- | vnext/src/utils/embed.js | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/vnext/src/utils/embed.js b/vnext/src/utils/embed.js index 75985582..b5b4d505 100644 --- a/vnext/src/utils/embed.js +++ b/vnext/src/utils/embed.js @@ -268,13 +268,25 @@ function getEmbeddableLinkTypes() { name: 'Twitter', id: 'embed_twitter_status', className: 'twi compact', + ctsDefault: false, re: /^(?:https?:)?\/\/(?:www\.)?(?:mobile\.)?twitter\.com\/([\w-]+)\/status(?:es)?\/([\d]+)/i, makeNode: function(aNode, reResult, div) { - fetch('https://beta.juick.com/api/oembed?url=' + reResult[0]) - .then(response => response.json()) - .then(json => { - div.innerHTML = json.html - }).catch(console.log) + let [url, , ] = reResult + url = url.replace('mobile.','') + + div.innerHTML = `<blockquote class="twitter-tweet" data-lang="en"><a href="${url}"></a></blockquote>` + + if (window.twttr) { + // https://developer.twitter.com/en/docs/twitter-for-websites/javascript-api/guides/scripting-loading-and-initialization + window.twttr.widgets.load(div) + } else { + // innerHTML cannot insert scripts, so... + let script = document.createElement('script') + script.src = 'https://platform.twitter.com/widgets.js' + script.charset = 'utf-8' + div.appendChild(script) + } + return div } }, |