mirror of
https://github.com/zedeus/nitter
synced 2026-09-05 14:49:32 +00:00
Clean up embed JS and add Tweet.html compatibility
This commit is contained in:
parent
dc66bd6375
commit
3bfbb7b3fd
4 changed files with 13 additions and 10 deletions
|
|
@ -24,4 +24,4 @@
|
||||||
|
|
||||||
// Expose for embedTweet.js
|
// Expose for embedTweet.js
|
||||||
window._nitterSendHeight = sendHeight;
|
window._nitterSendHeight = sendHeight;
|
||||||
})()
|
})();
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
// This runs after embedResize.js sets up the sendHeight function
|
// This runs after embedResize.js sets up the sendHeight function
|
||||||
(function() {
|
(function() {
|
||||||
var sendHeight = window._nitterSendHeight;
|
var sendHeight = window._nitterSendHeight;
|
||||||
if (!sendHeight) return;
|
|
||||||
|
|
||||||
// Make images load eagerly so height updates correctly
|
// Make images load eagerly so height updates correctly
|
||||||
var lazyImages = document.querySelectorAll('img[loading="lazy"]');
|
var lazyImages = document.querySelectorAll('img[loading="lazy"]');
|
||||||
|
|
@ -9,12 +8,14 @@
|
||||||
lazyImages[i].loading = 'eager';
|
lazyImages[i].loading = 'eager';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update height when images finish loading
|
// Update height when images finish loading (only if sendHeight available)
|
||||||
var allImages = document.querySelectorAll('img');
|
if (sendHeight) {
|
||||||
for (var i = 0; i < allImages.length; i++) {
|
var allImages = document.querySelectorAll('img');
|
||||||
var img = allImages[i];
|
for (var i = 0; i < allImages.length; i++) {
|
||||||
if (!img.complete) {
|
var img = allImages[i];
|
||||||
img.addEventListener('load', sendHeight);
|
if (!img.complete) {
|
||||||
|
img.addEventListener('load', sendHeight);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -23,4 +24,5 @@
|
||||||
for (var i = 0; i < allLinks.length; i++) {
|
for (var i = 0; i < allLinks.length; i++) {
|
||||||
allLinks[i].target = '_blank';
|
allLinks[i].target = '_blank';
|
||||||
}
|
}
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
|
||||||
|
|
@ -81,8 +81,8 @@ routes:
|
||||||
if request.path.len == 0 or request.path[0] != '/':
|
if request.path.len == 0 or request.path[0] != '/':
|
||||||
halt Http400
|
halt Http400
|
||||||
|
|
||||||
# skip all file URLs
|
# skip all file URLs (except Twitter widget compatibility)
|
||||||
cond "." notin request.path
|
cond "." notin request.path or request.path == "/embed/Tweet.html"
|
||||||
applyUrlPrefs()
|
applyUrlPrefs()
|
||||||
|
|
||||||
get "/":
|
get "/":
|
||||||
|
|
|
||||||
|
|
@ -3,4 +3,5 @@
|
||||||
#proc renderOembedIframe*(embedUrl: string): string =
|
#proc renderOembedIframe*(embedUrl: string): string =
|
||||||
# result = ""
|
# result = ""
|
||||||
<iframe src="$embedUrl" style="width:100%;max-width:550px;height:250px;border:none" scrolling="no" loading="lazy" onload="let c=new MessageChannel;c.port1.onmessage=e=>this.style.height=e.data+'px';this.contentWindow.postMessage('','*',[c.port2])"></iframe>
|
<iframe src="$embedUrl" style="width:100%;max-width:550px;height:250px;border:none" scrolling="no" loading="lazy" onload="let c=new MessageChannel;c.port1.onmessage=e=>this.style.height=e.data+'px';this.contentWindow.postMessage('','*',[c.port2])"></iframe>
|
||||||
|
# result = result.strip()
|
||||||
#end proc
|
#end proc
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue