This repository has no description
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>twitframe</title> <meta name="description" content="Embed Tweets in an iframe" /> <style> body { font-family: helvetica neue, arial, sans-serif; padding-top: 1px; }
#brand { background-color: #fbfbfb; color: #bbb; font-size: 8pt; left: 0px; opacity: 0.2; padding-left: 0.5rem; padding-right: 0.5rem; position: absolute; top: 0px; }
#brand a { color: #aaa; text-decoration: none; }
blockquote.twitter-tweet { margin: 1rem auto; }
#author_name { font-weight: bold; } </style></head><body> <span id="brand"> <a href="https://tf.rita.moe/?ref=t" target="_blank">twitframe</a> </span> <blockquote class="twitter-tweet" id="t"> <span id="author_name"></span> <span id="author_username"></span> <p> <span id="tweet"></span> </p> <a id="date" target="_blank"></a> </blockquote> <script> const params = {} const searchParams = new URLSearchParams(window.location.search) for (const [key, value] of searchParams.entries()) { params[key] = value.replace(/\+/g, ' ') }
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'] : '') 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 m = url.match(/^(?:https?:)?\/\/(?:www\.)?twitter\.com\/([^/]+)\//) if (m && !authorUsername) { authorUsername = m[1] }
if (authorUsername && authorUsername.substr(0, 1) !== '@') { authorUsername = '@' + authorUsername }
if (datetime) { const d = new Date(datetime * 1000) formattedDate = d.toDateString() }
const t = document.getElementById('t') if (align) { t.align = align } if (linkColor) { t.setAttribute('data-link-color', linkColor) } if (theme) { t.setAttribute('data-theme', theme) } if (conversation) { t.setAttribute('data-conversation', conversation) } if (cards) { t.setAttribute('data-cards', cards) } if (lang) { t.setAttribute('data-lang', lang) }
if (authorName) { document.getElementById('author_name').innerText = authorName } if (authorUsername) { document.getElementById('author_username').innerText = authorUsername }
document.getElementById('tweet').innerText = tweet
document.getElementById('date').href = url document.getElementById('date').innerText = formattedDate
if (!params['force_fail']) { const s = document.createElement('script') s.src = 'https://platform.twitter.com/widgets.js' document.body.appendChild(s) }
let caller const saveCaller = (e) => { if (e.data.element) { caller = e sendResponse() } }
if (window.addEventListener) { window.addEventListener('message', saveCaller, false) } else { window.attachEvent('onmessage', saveCaller) }
let lastHeight = 0 const loadedTime = window.performance ? window.performance.now() : 0 const checkHeight = () => { if (document.body.scrollHeight !== lastHeight && caller) { lastHeight = document.body.scrollHeight sendResponse() }
/* give up after a while to save cpu */ if (window.performance && (window.performance.now() - loadedTime > (10 * 1000))) { return }
window.requestAnimationFrame(checkHeight) } window.requestAnimationFrame(checkHeight)
const sendResponse = () => { if (caller.data.query === 'height') { caller.source.postMessage( { element: caller.data.element, height: document.body.scrollHeight + 20, }, caller.origin, ) } } </script></body></html>