Bläddra i källkod

Clean up embed JS and add Tweet.html compatibility

Zed 1 månad sedan
förälder
incheckning
3bfbb7b3fd
4 ändrade filer med 13 tillägg och 10 borttagningar
  1. 1 1
      public/js/embedResize.js
  2. 9 7
      public/js/embedTweet.js
  3. 2 2
      src/nitter.nim
  4. 1 0
      src/views/oembed.nimf

+ 1 - 1
public/js/embedResize.js

@@ -24,4 +24,4 @@
 
 
   // Expose for embedTweet.js
   // Expose for embedTweet.js
   window._nitterSendHeight = sendHeight;
   window._nitterSendHeight = sendHeight;
-})()
+})();

+ 9 - 7
public/js/embedTweet.js

@@ -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
-  var allImages = document.querySelectorAll('img');
-  for (var i = 0; i < allImages.length; i++) {
-    var img = allImages[i];
-    if (!img.complete) {
-      img.addEventListener('load', sendHeight);
+  // Update height when images finish loading (only if sendHeight available)
+  if (sendHeight) {
+    var allImages = document.querySelectorAll('img');
+    for (var i = 0; i < allImages.length; i++) {
+      var img = allImages[i];
+      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';
   }
   }
+
 })();
 })();

+ 2 - 2
src/nitter.nim

@@ -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
-    cond "." notin request.path
+    # skip all file URLs (except Twitter widget compatibility)
+    cond "." notin request.path or request.path == "/embed/Tweet.html"
     applyUrlPrefs()
     applyUrlPrefs()
 
 
   get "/":
   get "/":

+ 1 - 0
src/views/oembed.nimf

@@ -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