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

show: keep sending our scrollHeight if it changes, for 10 seconds

should fix #1

+16 -26
+16 -26
show.html
··· 108 108 else 109 109 window.attachEvent("onmessage", saveCaller); 110 110 111 - function onload() { 112 - if (arguments.callee.done) 113 - return; 114 - arguments.callee.done = true; 111 + var lastHeight = 0; 112 + var loadedTime = window.performance ? window.performance.now() : 0; 113 + function checkHeight() { 114 + if (document.body.scrollHeight != lastHeight && caller) { 115 + lastHeight = document.body.scrollHeight; 116 + sendResponse(); 117 + } 115 118 116 - if (_timer) 117 - clearInterval(_timer); 118 - 119 - loaded = true; 120 - if (caller) 121 - sendResponse(); 122 - } 119 + /* give up after a while to save cpu */ 120 + if (window.performance && 121 + (window.performance.now() - loadedTime > (10 * 1000))) 122 + return; 123 123 124 - if (document.addEventListener) 125 - document.addEventListener("DOMContentLoaded", onload, false); 126 - else if (/WebKit/i.test(navigator.userAgent)) { 127 - _timer = setInterval(function() { 128 - if (/loaded|complete/.test(document.readyState)) 129 - onload(); 130 - }, 10); 124 + window.requestAnimationFrame(checkHeight); 131 125 } 132 - else 133 - window.onload = onload; 126 + window.requestAnimationFrame(checkHeight); 134 127 135 128 function sendResponse() { 136 - if (caller.data.query == "height") { 137 - setTimeout(function() { 138 - caller.source.postMessage({ element: caller.data.element, 139 - height: document.body.scrollHeight + 20 }, caller.origin); 140 - }, 500); 141 - } 129 + if (caller.data.query == "height") 130 + caller.source.postMessage({ element: caller.data.element, 131 + height: document.body.scrollHeight + 20 }, caller.origin); 142 132 }; 143 133 </script> 144 134 </html>