Created
December 1, 2021 21:31
-
-
Save nummi/3d836ba05508a1e84e5c1779036e411d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;(function () { | |
const on = window.addEventListener | |
let parent = null | |
const _post = function () { | |
parent.postMessage( | |
{ | |
type: 'FRAME_HEIGHT', | |
height: document.documentElement.scrollHeight, | |
}, | |
'*' | |
) | |
} | |
const post = function () { | |
let timer = null | |
clearTimeout(timer) | |
if (parent) { | |
timer = setTimeout(_post, 250) | |
} | |
} | |
on('message', function (event) { | |
parent = event.source | |
post() | |
}) | |
on('resize', post) | |
on('load', post) | |
new MutationObserver(function () { | |
post() | |
}).observe(document.querySelector('body'), { | |
childList: true, | |
attributes: true, | |
characterData: true, | |
subtree: true, | |
attributeOldValue: true, | |
characterDataOldValue: true, | |
}) | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment