mirror of
https://github.com/zedeus/nitter
synced 2026-09-05 14:49:32 +00:00
Clean up embedResize.js
This commit is contained in:
parent
1d61f8cf07
commit
756beab8a6
1 changed files with 14 additions and 23 deletions
|
|
@ -1,43 +1,34 @@
|
||||||
(function () {
|
(function () {
|
||||||
var embedElement = document.querySelector(
|
var embed = document.querySelector(".embed-wrapper, .embed-video");
|
||||||
".embed-wrapper, .tweet-embed, .embed-video",
|
if (!embed) return;
|
||||||
);
|
|
||||||
if (!embedElement) return;
|
|
||||||
|
|
||||||
// Video play state for overlay (hidden while playing, visible on hover/pause)
|
var video = embed.querySelector("video");
|
||||||
var video = embedElement.querySelector("video");
|
|
||||||
if (video) {
|
if (video) {
|
||||||
video.onplay = function () {
|
video.onplay = function () {
|
||||||
embedElement.classList.add("video-playing");
|
embed.classList.add("video-playing");
|
||||||
};
|
};
|
||||||
video.onpause = video.onended = function () {
|
video.onpause = video.onended = function () {
|
||||||
embedElement.classList.remove("video-playing");
|
embed.classList.remove("video-playing");
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
var lastHeight = 0;
|
var lastHeight = 0;
|
||||||
|
|
||||||
function sendHeight() {
|
function sendHeight() {
|
||||||
var currentHeight = embedElement.offsetHeight;
|
var h = embed.offsetHeight;
|
||||||
if (currentHeight !== lastHeight && currentHeight > 0) {
|
if (h !== lastHeight && h > 0) {
|
||||||
lastHeight = currentHeight;
|
lastHeight = h;
|
||||||
window.parent.postMessage(
|
window.parent.postMessage(["resizeIframe", { h: h }], "*");
|
||||||
["resizeIframe", { h: currentHeight, url: location.href }],
|
|
||||||
"*",
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Respond to height requests from parent via MessageChannel
|
// MessageChannel height request (used by oEmbed)
|
||||||
window.addEventListener("message", function (event) {
|
window.addEventListener("message", function (e) {
|
||||||
if (event.source === window.parent && event.ports && event.ports[0]) {
|
if (e.source === window.parent && e.ports && e.ports[0]) {
|
||||||
event.ports[0].postMessage(embedElement.offsetHeight);
|
e.ports[0].postMessage(embed.offsetHeight);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
window.addEventListener("load", sendHeight);
|
window.addEventListener("load", sendHeight);
|
||||||
new ResizeObserver(sendHeight).observe(embedElement);
|
new ResizeObserver(sendHeight).observe(embed);
|
||||||
|
|
||||||
// Expose for embedTweet.js
|
|
||||||
window._nitterSendHeight = sendHeight;
|
|
||||||
})();
|
})();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue