Added command to run javascript from input box.
authorDaniel Carl <danielcarl@gmx.de>
Mon, 8 Apr 2013 19:47:00 +0000 (21:47 +0200)
committerDaniel Carl <danielcarl@gmx.de>
Mon, 8 Apr 2013 19:47:00 +0000 (21:47 +0200)
doc/vimb.1.txt
src/command.c
src/command.h

index 82cc4a0..5a3efff 100644 (file)
@@ -347,6 +347,10 @@ Close the browser.
 .TP
 .B source
 Toggle between normal view and source view for the current page.
+.TP
+.BI eval " JAVASCRIPT"
+Runs the given \fIJAVASCRIPT\fP in the current page and display the evaluated
+value.
 .SH FILES
 .I $XDG_CONFIG_HOME/PROJECT/config
 .RS
index b666157..82a891c 100644 (file)
@@ -100,6 +100,7 @@ static CommandInfo cmd_list[] = {
     {"hist-prev",            command_history,              {1}},
     {"run",                  command_run_multi,            {0}},
     {"bookmark-add",         command_bookmark,             {1}},
+    {"eval",                 command_eval,                 {0}},
 };
 
 
@@ -607,3 +608,22 @@ gboolean command_bookmark(const Arg *arg)
     vb_set_mode(VB_MODE_NORMAL, false);
     return true;
 }
+
+gboolean command_eval(const Arg *arg)
+{
+    gboolean success;
+    char *value = NULL;
+
+    success = vb_eval_script(
+        webkit_web_view_get_main_frame(vb.gui.webview), arg->s, NULL, &value
+    );
+    if (success) {
+        vb_echo_force(VB_MSG_NORMAL, false, value);
+    } else {
+        vb_echo_force(VB_MSG_ERROR, true, value);
+    }
+    g_free(value);
+    vb_set_mode(VB_MODE_NORMAL, false);
+
+    return success;
+}
index f75d99d..8b81d17 100644 (file)
@@ -74,5 +74,6 @@ gboolean command_searchengine_default(const Arg *arg);
 gboolean command_zoom(const Arg *arg);
 gboolean command_history(const Arg *arg);
 gboolean command_bookmark(const Arg *arg);
+gboolean command_eval(const Arg *arg);
 
 #endif /* end of include guard: _COMMAND_H */