···
window.attachEvent("onmessage", saveCaller);
111
-
function onload() {
112
-
if (arguments.callee.done)
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;
117
-
clearInterval(_timer);
119
+
/* give up after a while to save cpu */
120
+
if (window.performance &&
121
+
(window.performance.now() - loadedTime > (10 * 1000)))
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))
124
+
window.requestAnimationFrame(checkHeight);
133
-
window.onload = onload;
126
+
window.requestAnimationFrame(checkHeight);
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);
129
+
if (caller.data.query == "height")
130
+
caller.source.postMessage({ element: caller.data.element,
131
+
height: document.body.scrollHeight + 20 }, caller.origin);