const commentIframes = document.getElementsByClassName('jetpack_remote_comment');
window.addEventListener('message', function(event) {
if (event.origin !== 'https://jetpack.wordpress.com') {
return;
}
if (!event?.data?.iframeUniqueId && !event?.data?.height) {
return;
}
const eventDataUniqueId = event.data.iframeUniqueId;
// Change height for the matching comment iframe
for (let i = 0; i < commentIframes.length; i++) {
const iframe = commentIframes[i];
const url = new URL(iframe.src);
const iframeUniqueIdParam = url.searchParams.get('iframe_unique_id');
if (iframeUniqueIdParam == event.data.iframeUniqueId) {
iframe.style.height = event.data.height + 'px';
return;
}
}
});
})();