From 9f169dea843c13dc234d554bef51b3c98131587b Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 8 Jul 2022 02:11:03 +0300 Subject: Embed tweets without broken widgets.js --- src/main/assets/embed.js | 23 +++++------------------ 1 file 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 = `
`; - - 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; } }, -- cgit v1.2.3