From 642b5755d28d34dbddf5c9d4e7130a03c4138284 Mon Sep 17 00:00:00 2001
From: Daniel Carl <danielcarl@gmx.de>
Date: Mon, 8 Apr 2013 21:47:00 +0200
Subject: [PATCH] Added command to run javascript from input box.

---
 doc/vimb.1.txt |  4 ++++
 src/command.c  | 20 ++++++++++++++++++++
 src/command.h  |  1 +
 3 files changed, 25 insertions(+)

diff --git a/doc/vimb.1.txt b/doc/vimb.1.txt
index 82cc4a0..5a3efff 100644
--- a/doc/vimb.1.txt
+++ b/doc/vimb.1.txt
@@ -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
diff --git a/src/command.c b/src/command.c
index b666157..82a891c 100644
--- a/src/command.c
+++ b/src/command.c
@@ -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;
+}
diff --git a/src/command.h b/src/command.h
index f75d99d..8b81d17 100644
--- a/src/command.h
+++ b/src/command.h
@@ -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 */
-- 
2.20.1