aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar makc2019-04-02 21:13:58 +0200
committerGravatar Vitaly Takmazov2019-04-02 23:14:15 +0300
commit5f15bf93d7779396395e1a5ac0f4e14ade9bfea0 (patch)
treefdd2d6d12062f4329e66f02e891e3d5b02d02b30 /src
parenteaa7d242256d45bbd4cd520db02bef679fd11113 (diff)
Embed twitter statuses
Diffstat (limited to 'src')
-rw-r--r--src/main/assets/embed.js26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/main/assets/embed.js b/src/main/assets/embed.js
index 3b8946bf..6a11e5cf 100644
--- a/src/main/assets/embed.js
+++ b/src/main/assets/embed.js
@@ -236,6 +236,32 @@ function getEmbeddableLinkTypes() {
iframe.onload = () => makeResizableToRatio(iframe, 9.0 / 16.0);
return setContent(div, iframe);
}
+ },
+ {
+ 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) {
+ 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) {
+ // https://developer.twitter.com/en/docs/twitter-for-websites/javascript-api/guides/scripting-loading-and-initialization
+ setTimeout(function() { twttr.widgets.load(div); }, 0);
+ } 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;
+ }
}
];
}