diff options
author | portix <none@none> | 2012-03-29 16:00:45 +0200 |
---|---|---|
committer | portix <none@none> | 2012-03-29 16:00:45 +0200 |
commit | a5a1b73dd582d8bc46caafe766f1c911a6fcb0f0 (patch) | |
tree | 95ae3710d4bff6a8db4a9a80bd940829f4e25dc3 | |
parent | 621f3da1f940997e075f03a23e51add9f792041a (diff) | |
download | dwb-a5a1b73dd582d8bc46caafe766f1c911a6fcb0f0.zip |
New command 'dump' and environment variable 'DWB_HTML_CONTENT' for userscripts
-rw-r--r-- | doc/dwb.1 | 3 | ||||
-rw-r--r-- | src/commands.c | 13 | ||||
-rw-r--r-- | src/commands.h | 1 | ||||
-rw-r--r-- | src/config.h | 6 | ||||
-rw-r--r-- | src/dwb.c | 19 | ||||
-rw-r--r-- | src/dwb.h | 2 |
6 files changed, 42 insertions, 2 deletions
@@ -977,6 +977,8 @@ buffers |bu |Show all open tabs cancel_download | |Cancel a download clear_tab |clear |Clear tab close_tab |close |Close tab +dump | |Write html of current website to a + | |file or stdout if no argument is given execute_javascript |exja |Execute a javascript snippet execute_userscript | |Execute userscript find_backward |bfind |Find backward @@ -2013,6 +2015,7 @@ the variables .IR DWB_PROFILE , .IR DWB_NUMMOD , .IR DWB_ARGUMENT , +.IR DWB_HTML_CONTENT , .IR DWB_REFERER , and .I DWB_USER_AGENT diff --git a/src/commands.c b/src/commands.c index f882f45f..eae99baa 100644 --- a/src/commands.c +++ b/src/commands.c @@ -840,4 +840,17 @@ DwbStatus commands_cancel_download(KeyMap *km, Arg *arg) { return download_cancel(dwb.state.nummod); } +DwbStatus +commands_dump(KeyMap *km, Arg *arg) { + char *data = dwb_get_raw_data(dwb.state.fview); + if (data == NULL) + return STATUS_ERROR; + if (arg->p == NULL) + puts(data); + else { + util_set_file_content(arg->p, data); + arg->p = NULL; + } + return STATUS_OK; +} /*}}}*/ diff --git a/src/commands.h b/src/commands.h index df6d591e..1a52a247 100644 --- a/src/commands.h +++ b/src/commands.h @@ -92,5 +92,6 @@ DwbStatus commands_tab_move(KeyMap *, Arg *); DwbStatus commands_clear_tab(KeyMap *, Arg *); DwbStatus commands_cancel_download(KeyMap *, Arg *); DwbStatus commands_normal_mode(KeyMap *, Arg *); +DwbStatus commands_dump(KeyMap *, Arg *); #endif diff --git a/src/config.h b/src/config.h index 8421c6ba..c514fd39 100644 --- a/src/config.h +++ b/src/config.h @@ -173,6 +173,7 @@ static KeyValue KEYS[] = { { "clear_tab", { "gc", 0 }, }, { "cancel_download", { "ad", 0 }, }, { "local_set", { NULL, 0 }, }, + { "dump", { NULL, 0 }, }, }; /* FUNCTION_MAP{{{*/ @@ -190,7 +191,6 @@ static FunctionMap FMAP [] = { { .p = NULL }, EP_NONE, { "clear" }, }, { { "execute_javascript", "Execute a javascript snippet", }, CP_COMMANDLINE, - (Func)commands_execute_javascript, NULL, ALWAYS_SM, { .p = NULL }, EP_NONE, { "exja", NULL }, }, @@ -205,6 +205,10 @@ static FunctionMap FMAP [] = { (Func)commands_set, "Invalid value", POST_SM, { .p = NULL, .n = SET_LOCAL }, EP_NONE, { NULL }, }, + { { "dump", "Write current website to a file or stdout", }, CP_COMMANDLINE, + (Func)commands_dump, NULL, POST_SM, + { .p = NULL }, EP_NONE, { NULL }, }, + { { "toggle_setting", "Toggle a setting", }, CP_COMMANDLINE, (Func)commands_toggle_setting, "Invalid value", POST_SM, { .p = NULL , .n = SET_GLOBAL }, EP_NONE, { "toggle", "tog", NULL }, }, @@ -543,6 +543,19 @@ dwb_update_status_text(GList *gl, GtkAdjustment *a) { /* FUNCTIONS {{{*/ +/* dwb_get_raw_data(GList *){{{*/ +char * +dwb_get_raw_data(GList *gl) { + char *ret = NULL; + WebKitWebFrame *frame = webkit_web_view_get_main_frame(WEBVIEW(gl)); + WebKitWebDataSource *data_source = webkit_web_frame_get_data_source(frame); + GString *data = webkit_web_data_source_get_data(data_source); + if (data != NULL) { + ret = data->str; + } + return ret; +}/*}}}*/ + DwbStatus/*{{{*/ dwb_scheme_handler(GList *gl, WebKitNetworkRequest *request) { const char *handler = GET_CHAR("scheme-handler"); @@ -2455,12 +2468,18 @@ dwb_execute_user_script(KeyMap *km, Arg *a) { list = g_slist_append(list, dwb_navigation_new("DWB_PROFILE", dwb.misc.profile)); list = g_slist_append(list, dwb_navigation_new("DWB_NUMMOD", nummod)); list = g_slist_append(list, dwb_navigation_new("DWB_ARGUMENT", a->p)); + + const char *raw_data = dwb_get_raw_data(dwb.state.fview); + list = g_slist_append(list, dwb_navigation_new("DWB_HTML_CONTENT", raw_data == NULL ? "" : raw_data)); + const char *referer = soup_get_header(dwb.state.fview, "Referer"); if (referer != NULL) list = g_slist_append(list, dwb_navigation_new("DWB_REFERER", referer)); + const char *user_agent = soup_get_header(dwb.state.fview, "User-Agent"); if (user_agent != NULL) list = g_slist_append(list, dwb_navigation_new("DWB_USER_AGENT", user_agent)); + if (km->map->arg.b) { dwb.misc.fifo = util_get_temp_filename("fifo_"); list = g_slist_append(list, dwb_navigation_new("DWB_FIFO", dwb.misc.fifo)); @@ -887,6 +887,6 @@ DwbStatus dwb_scheme_handler(GList *gl, WebKitNetworkRequest *request); GList *dwb_get_simple_list(GList *, const char *filename); gboolean dwb_dom_remove_from_parent(WebKitDOMNode *node, GError **error); - +char * dwb_get_raw_data(GList *gl); #endif |