mirror of
https://github.com/zedeus/nitter
synced 2026-09-05 22:59:31 +00:00
Add tweet embed and oEmbed API support
This commit is contained in:
parent
06c52473ab
commit
9be0b8f826
10 changed files with 389 additions and 31 deletions
26
public/js/embedResize.js
Normal file
26
public/js/embedResize.js
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
(function() {
|
||||
var embedElement = document.querySelector('.tweet-embed, .embed-video');
|
||||
if (!embedElement) return;
|
||||
|
||||
var lastHeight = 0;
|
||||
|
||||
function sendHeight() {
|
||||
var currentHeight = embedElement.offsetHeight;
|
||||
if (currentHeight !== lastHeight) {
|
||||
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);
|
||||
|
||||
return sendHeight;
|
||||
})()
|
||||
Loading…
Reference in a new issue