mirror of
https://github.com/zedeus/nitter
synced 2026-09-05 14:49:32 +00:00
27 lines
887 B
JavaScript
27 lines
887 B
JavaScript
(function() {
|
|
var embedElement = document.querySelector('.embed-wrapper, .tweet-embed, .embed-video');
|
|
if (!embedElement) return;
|
|
|
|
var lastHeight = 0;
|
|
|
|
function sendHeight() {
|
|
var currentHeight = embedElement.offsetHeight;
|
|
if (currentHeight !== lastHeight && currentHeight > 0) {
|
|
lastHeight = currentHeight;
|
|
window.parent.postMessage(['resizeIframe', { h: currentHeight, url: location.href }], '*');
|
|
}
|
|
}
|
|
|
|
// Respond to height requests from parent via MessageChannel
|
|
window.addEventListener('message', function(event) {
|
|
if (event.source === window.parent && event.ports && event.ports[0]) {
|
|
event.ports[0].postMessage(embedElement.offsetHeight);
|
|
}
|
|
});
|
|
|
|
window.addEventListener('load', sendHeight);
|
|
new ResizeObserver(sendHeight).observe(embedElement);
|
|
|
|
// Expose for embedTweet.js
|
|
window._nitterSendHeight = sendHeight;
|
|
})();
|