Improve video embed overlay and proxy behavior

This commit is contained in:
Zed 2026-08-12 01:36:40 +07:00
commit 5fa4eefb9d
5 changed files with 82 additions and 32 deletions

View file

@ -1,25 +1,41 @@
(function() {
var embedElement = document.querySelector('.embed-wrapper, .tweet-embed, .embed-video');
(function () {
var embedElement = document.querySelector(
".embed-wrapper, .tweet-embed, .embed-video",
);
if (!embedElement) return;
// Video play state for overlay (hidden while playing, visible on hover/pause)
var video = embedElement.querySelector("video");
if (video) {
video.onplay = function () {
embedElement.classList.add("video-playing");
};
video.onpause = video.onended = function () {
embedElement.classList.remove("video-playing");
};
}
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 }], '*');
window.parent.postMessage(
["resizeIframe", { h: currentHeight, url: location.href }],
"*",
);
}
}
// Respond to height requests from parent via MessageChannel
window.addEventListener('message', function(event) {
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);
window.addEventListener("load", sendHeight);
new ResizeObserver(sendHeight).observe(embedElement);
// Expose for embedTweet.js