texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]


From: Gavin D. Smith
Date: Sun, 20 Mar 2022 04:55:29 -0400 (EDT)

branch: master
commit ff58508e30fb070b5f8f86abc0df3c6234b47c21
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Mon Oct 19 16:47:30 2020 +0100

    inject js and re-write URLs
---
 js/infog/extension.c | 38 ++++++++++++++++++++++++++++++++++++--
 js/infog/main.c      |  4 ++--
 2 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/js/infog/extension.c b/js/infog/extension.c
index 994d9b08b6..8d92feeb69 100644
--- a/js/infog/extension.c
+++ b/js/infog/extension.c
@@ -131,9 +131,11 @@ request_callback (WebKitWebPage     *web_page,
       return FALSE;
     }
 
-  if (!memcmp (uri, "file:", 5))
+  /* Links to other Texinfo manuals are rewritten to have the "private"
+     URI scheme. */
+  if (!memcmp (uri, "file:", 5)
+      || !memcmp (uri, "private:", 8))
     {
-
       char *manual, *node;
       /* The links in the HTML files should be relative links like
          "../MANUAL/NODE.html" but by the time this function is called
@@ -158,6 +160,9 @@ request_callback (WebKitWebPage     *web_page,
       g_string_append (s, node);
       send_datagram (s);
       g_string_free (s, TRUE);
+
+      if (!memcmp (uri, "private:", 8))
+        return TRUE;
     }
 
   return FALSE;
@@ -427,6 +432,24 @@ send_pointer (WebKitDOMElement *link_elt,
   free (link);
 }
 
+/* Script to run in newly loaded files.  End each line with a backslash.
+   Avoid // or /* comments outside of strings. */
+#define INJECTED_JAVASCRIPTZ                                  \
+  var x = document.getElementsByClassName("texi-manual");     \
+  for (var i = 0; i < x.length; i++) {                        \
+      if (x[i].href) {                                        \
+        var re = new RegExp('^http://|^https://');            \
+        x[i].href = x[i].href.replace(re, 'private:');        \
+      }                                                       \
+  };                                                          \
+  ;
+
+
+/* Use variadic macro to allow for commas in argument */
+#define stringize(...) #__VA_ARGS__
+#define dostringize(a) stringize(a)
+#define INJECTED_JAVASCRIPT dostringize(INJECTED_JAVASCRIPTZ)
+
 
 void
 document_loaded_callback (WebKitWebPage *web_page,
@@ -466,6 +489,17 @@ document_loaded_callback (WebKitWebPage *web_page,
       return;
     }
 
+#if 1
+  WebKitFrame *frame = webkit_web_page_get_main_frame (web_page);
+  if (!frame)
+    return;
+  JSCContext *jsc = webkit_frame_get_js_context (frame);
+  if (!jsc)
+    return;
+  (void) jsc_context_evaluate (jsc, INJECTED_JAVASCRIPT, -1);
+  debug (1, "INJECT |%s|\n", INJECTED_JAVASCRIPT);
+#endif
+
   WebKitDOMElement *link_elt;
 
   const char *current_uri = webkit_web_page_get_uri (web_page);
diff --git a/js/infog/main.c b/js/infog/main.c
index a8e6977cdb..a18899acce 100644
--- a/js/infog/main.c
+++ b/js/infog/main.c
@@ -522,7 +522,7 @@ socket_cb (GSocket *socket,
       if (!p)
         break;
       *p = 0;
-      debug (1, "received message of type |%s|\n", buffer);
+      //debug (1, "received message of type |%s|\n", buffer);
 
       char **save_where = 0;
       if (!strcmp (buffer, "next"))
@@ -992,7 +992,7 @@ main (int argc, char *argv[])
     /* Create a web view to parse index files.  */
     hiddenWebView = WEBKIT_WEB_VIEW(webkit_web_view_new());
 
-#define FIRST_MANUAL "hello"
+#define FIRST_MANUAL "texinfo"
 
     load_manual (FIRST_MANUAL);
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]