Embed Tweets in an iframe - https://tf.rita.moe

Fix x.com support, add `cards` and `lang` params

Changed files
+24 -5
+10
index.html
···
<tt style="color: green;">conversation</tt>
- Disable showing previous Tweet in a thread when set to <tt>none</tt>
</li>
+
+
<li>
+
<tt style="color: green;">cards</tt>
+
- Disable showing media previews when set to <tt>hidden</tt>
+
</li>
+
+
<li>
+
<tt style="color: green;">lang</tt>
+
- Language code for the interface (such as <tt>en</tt>)
+
</li>
</ul>
</p>
+14 -5
show.html
···
<p>
<span id="tweet"></span>
</p>
-
<a id="date"></a>
+
<a id="date" target="_blank"></a>
</blockquote>
<script>
const params = {}
···
params[key] = value.replace(/\+/g, ' ')
}
-
const url = params['url'] || ''
+
const url = params['url']?.replace('x.com', 'twitter.com') || ''
const datetime = (params['datetime'] || 0)
const tweet = (params['tweet'] ? params['tweet'] : 'Loading tweet...')
const authorName = (params['author_name'] ? params['author_name'] : '')
-
let authorUsername = (params['author_username'] ? params['author_username'] : '')
const align = params['align']
const linkColor = params['link_color']
const theme = params['theme']
+
const conversation = params['conversation']
+
const cards = params['cards']
+
const lang = params['lang']
+
+
let authorUsername = (params['author_username'] ? params['author_username'] : '')
let formattedDate = 'Unknown date'
-
const conversation = params['conversation']
-
const m = url.match(/^(?:https?:)?\/\/(?:www\.)?(?:twitter|x)\.com\/([^/]+)\//)
+
const m = url.match(/^(?:https?:)?\/\/(?:www\.)?twitter\.com\/([^/]+)\//)
if (m && !authorUsername) {
authorUsername = m[1]
}
···
}
if (conversation) {
t.setAttribute('data-conversation', conversation)
+
}
+
if (cards) {
+
t.setAttribute('data-cards', cards)
+
}
+
if (lang) {
+
t.setAttribute('data-lang', lang)
}
if (authorName) {