Embed Tweets in an iframe - https://tf.rita.moe
1<!doctype html> 2<html lang="en"> 3<head> 4<style type="text/css"> 5 #author_name { 6 font-weight: bold; 7 } 8 body { 9 padding-top: 1px; 10 } 11 #brand { 12 background-color: #fbfbfb; 13 color: #bbb; 14 font-family: helvetica neue, arial, sans-serif; 15 font-size: 8pt; 16 left: 0px; 17 padding-left: 0.5em; 18 padding-right: 0.5em; 19 position: absolute; 20 top: 0px; 21 } 22 #brand a { 23 color: #aaa; 24 text-decoration: none; 25 } 26</style> 27</head> 28<body> 29 <span id="brand"> 30 <a href="https://twitframe.com/?ref=t" target="_blank">Twitframe</a> 31 </span> 32 <blockquote class="twitter-tweet" id="t"> 33 <span id="author_name"></span> 34 <span id="author_username"></span> 35 <p> 36 <span id="tweet"></span> 37 </p> 38 <a id="date"></a> 39 </blockquote> 40</body> 41<script> 42 43var params = {}; 44location.search.substr(1).split("&").forEach(function(part) { 45 var item = part.split("="); 46 params[item[0]] = decodeURIComponent(item[1]).replace(/\+/g, " "); 47}); 48 49var url = params["url"] || ""; 50var datetime = (params["datetime"] || 0); 51var tweet = (params["tweet"] ? params["tweet"] : "Loading tweet..."); 52var author_name = (params["author_name"] ? params["author_name"] : ""); 53var author_username = (params["author_username"] ? params["author_username"] : ""); 54var align = params["align"]; 55var link_color = params["link_color"]; 56var theme = params["theme"]; 57var formatted_date = "Unknown date"; 58 59var m; 60if (m = url.match(/^(https?:)?\/\/(www\.)?twitter\.com\/([^\/]+)\//)) { 61 if (!author_username) 62 author_username = m[3]; 63} 64 65if (author_username && author_username.substr(0, 1) != "@") 66 author_username = "@" + author_username; 67 68if (datetime) { 69 var d = new Date(datetime * 1000); 70 formatted_date = d.toDateString(); 71} 72 73var t = document.getElementById("t"); 74if (align) 75 t.align = align; 76if (link_color) 77 t.data["link-color"] = link_color; 78if (theme) 79 t.data["theme"] = theme; 80 81var h = ""; 82if (author_name) 83 document.getElementById("author_name").innerText = author_name; 84if (author_username) 85 document.getElementById("author_username").innerText = author_username; 86 87document.getElementById("tweet").innerText = tweet; 88 89document.getElementById("date").href = url; 90document.getElementById("date").innerText = formatted_date; 91 92if (!params["force_fail"]) { 93 var s = document.createElement("script"); 94 s.src = "https://platform.twitter.com/widgets.js"; 95 document.body.appendChild(s); 96} 97 98var caller, _timer, loaded = false; 99var saveCaller = function(e) { 100 if (e.data.element) { 101 caller = e; 102 if (loaded) 103 sendResponse(); 104 } 105}; 106if (window.addEventListener) 107 window.addEventListener("message", saveCaller, false); 108else 109 window.attachEvent("onmessage", saveCaller); 110 111var lastHeight = 0; 112var loadedTime = window.performance ? window.performance.now() : 0; 113function checkHeight() { 114 if (document.body.scrollHeight != lastHeight && caller) { 115 lastHeight = document.body.scrollHeight; 116 sendResponse(); 117 } 118 119 /* give up after a while to save cpu */ 120 if (window.performance && 121 (window.performance.now() - loadedTime > (10 * 1000))) 122 return; 123 124 window.requestAnimationFrame(checkHeight); 125} 126window.requestAnimationFrame(checkHeight); 127 128function sendResponse() { 129 if (caller.data.query == "height") 130 caller.source.postMessage({ element: caller.data.element, 131 height: document.body.scrollHeight + 20 }, caller.origin); 132}; 133</script> 134</html>