diff options
author | Vitaly Takmazov | 2022-07-08 02:11:03 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2022-07-08 02:11:03 +0300 |
commit | 9f169dea843c13dc234d554bef51b3c98131587b (patch) | |
tree | 18241da7fbc81257256639e6841acb4900610282 /src | |
parent | 63e106b762b201fb7b8ddd1c1c5640c521774e60 (diff) |
Embed tweets without broken widgets.js
Diffstat (limited to 'src')
-rw-r--r-- | src/main/assets/embed.js | 23 |
1 files changed, 5 insertions, 18 deletions
diff --git a/src/main/assets/embed.js b/src/main/assets/embed.js index 0022ae82..5e5d1fee 100644 --- a/src/main/assets/embed.js +++ b/src/main/assets/embed.js @@ -1,4 +1,3 @@ - function insertAfter(newNode, referenceNode) { referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling); } @@ -250,23 +249,11 @@ function getEmbeddableLinkTypes() { ctsDefault: false, re: /^(?:https?:)?\/\/(?:www\.)?(?:mobile\.)?twitter\.com\/([\w-]+)\/status(?:es)?\/([\d]+)/i, makeNode: function(aNode, reResult, div) { - let [url, userId, postId] = reResult; - url = url.replace('mobile.', ''); - - div.innerHTML = `<blockquote class="twitter-tweet" data-lang="en"><a href="${url}"></a></blockquote>`; - - if (window['twttr']) { - // this will only happen if you embed another set of twitter posts after the twitter script loads (likely never) - // https://developer.twitter.com/en/docs/twitter-for-websites/javascript-api/guides/scripting-loading-and-initialization - window['twttr'].widgets.load(div); - } else if (!document.head.querySelector ('[src="https://platform.twitter.com/widgets.js\"]')) { - // innerHTML cannot insert scripts, so... - let script = document.createElement('script'); - script.src = 'https://platform.twitter.com/widgets.js'; - script.charset = 'utf-8'; - document.head.appendChild(script); - } - + fetch('https://juick.com/srv/oembed?url=' + reResult[0]) + .then(response => response.json()) + .then(json => { + div.innerHTML = json.html; + }); return div; } }, |