diff options
author | Barrucadu <mike@barrucadu.co.uk> | 2009-05-18 20:08:56 +0100 |
---|---|---|
committer | Barrucadu <mike@barrucadu.co.uk> | 2009-05-18 20:08:56 +0100 |
commit | 1cfdb853c5296f5b510f35a90d5abc449eab6af6 (patch) | |
tree | 09b6cf244c948608d4eccea4393939bec6bff291 | |
parent | 2fd0f561bfa966eb22443c785ad82df9d11ef87b (diff) |
Renamed "script" to "js".
Added "script" command which executes an external JS file.
Moved hinting to an external JS file.
I renamed "script" to "js" because we use "sh" for one-line *sh scripts, so "js" for one-line JS scripts is nice and consistent.
-rw-r--r-- | README | 4 | ||||
-rw-r--r-- | examples/configs/sampleconfig | 6 | ||||
-rw-r--r-- | examples/configs/sampleconfig-dev | 6 | ||||
-rw-r--r-- | examples/scripts/hint.js | 26 | ||||
-rw-r--r-- | uzbl.c | 30 | ||||
-rw-r--r-- | uzbl.h | 3 |
6 files changed, 67 insertions, 8 deletions
@@ -147,9 +147,11 @@ actions follows: * `zoom_in` * `zoom_out` * `uri <address>` -* `script <body>` +* `js <body>` - execute the javascript in `<body>` - remember that the commands, and thus actions, must not contain line breaks +* `script <file>` + - execute the javascript in `<file>` * `toggle_status` * `spawn <executable> <additonal args>` - runs a command; see EXTERNAL SCRIPTS for details diff --git a/examples/configs/sampleconfig b/examples/configs/sampleconfig index bca4314..db4abc2 100644 --- a/examples/configs/sampleconfig +++ b/examples/configs/sampleconfig @@ -91,16 +91,16 @@ bind p = sh "echo act uri `xclip -selection primary -o` > $4" # go to the page in clipboard bind P = sh "echo act uri `xclip -selection clipboard -o` > $4" bind ZZ = exit -bind S = script alert("hi"); +bind S = js alert("hi"); # example showing how to use sh # it sends a command to the fifo, whose path is told via a positional param # if fifo_dir is not set, it'll echo to a file named (null) somewhere >:) remember to delete it bind XS = sh 'echo "act script alert (\"This is sent by the shell via a fifo\")" > "$4"' # Keyboard based link following: work in progress! No C DOM bindings yet, no click() event for hyperlinks so no referrer set..Quite basic but does the job for now... #hit F to toggle the Hints (now in form of link numbering) -bind F= script for (var i=0; i < document.links.length; i++) {var uzblid = 'uzbl_link_hint_';var li = document.links[i];var pre = document.getElementById(uzblid+i);if (pre) {li.removeChild(pre);} else {var hint = document.createElement('div');hint.setAttribute('id',uzblid+i);hint.innerHTML = i;hint.style.display='inline';hint.style.lineHeight='90%';hint.style.backgroundColor='red';hint.style.color='white';hint.style.fontSize='small-xx';hint.style.fontWeight='light';hint.style.margin='0px';hint.style.padding='2px';hint.style.position='absolute';hint.style.textDecoration='none';hint.style.left=li.style.left;hint.style.top=li.style.top;li.insertAdjacentElement('afterBegin',hint);}} +bind F= script /usr/share/uzbl/examples/scripts/hint.js #hit f followed by linknumber and ENTER to follow that link -bind f_ = script window.location = document.links[%s].href; +bind f_ = js window.location = document.links[%s].href; # "home" page if you will set uri = uzbl.org diff --git a/examples/configs/sampleconfig-dev b/examples/configs/sampleconfig-dev index ba916cc..fb240dd 100644 --- a/examples/configs/sampleconfig-dev +++ b/examples/configs/sampleconfig-dev @@ -92,16 +92,16 @@ bind p = sh "echo act uri `xclip -selection primary -o` > $4" # go to the page in clipboard bind P = sh "echo act uri `xclip -selection clipboard -o` > $4" bind ZZ = exit -bind S = script alert("hi"); +bind S = js alert("hi"); # example showing how to use sh # it sends a command to the fifo, whose path is told via a positional param # if fifo_dir is not set, it'll echo to a file named (null) somewhere >:) remember to delete it bind XS = sh 'echo "act script alert (\"This is sent by the shell via a fifo\")" > "$4"' # Keyboard based link following: work in progress! No C DOM bindings yet, no click() event for hyperlinks so no referrer set..Quite basic but does the job for now... #hit F to toggle the Hints (now in form of link numbering) -bind F= script for (var i=0; i < document.links.length; i++) {var uzblid = 'uzbl_link_hint_';var li = document.links[i];var pre = document.getElementById(uzblid+i);if (pre) {li.removeChild(pre);} else {var hint = document.createElement('div');hint.setAttribute('id',uzblid+i);hint.innerHTML = i;hint.style.display='inline';hint.style.lineHeight='90%';hint.style.backgroundColor='red';hint.style.color='white';hint.style.fontSize='small-xx';hint.style.fontWeight='light';hint.style.margin='0px';hint.style.padding='2px';hint.style.position='absolute';hint.style.textDecoration='none';hint.style.left=li.style.left;hint.style.top=li.style.top;li.insertAdjacentElement('afterBegin',hint);}} +bind F= script ./examples/scripts/hint.js #hit f followed by linknumber and ENTER to follow that link -bind f_ = script window.location = document.links[%s].href; +bind f_ = js window.location = document.links[%s].href; # "home" page if you will set uri = uzbl.org diff --git a/examples/scripts/hint.js b/examples/scripts/hint.js new file mode 100644 index 0000000..ec7f1e2 --- /dev/null +++ b/examples/scripts/hint.js @@ -0,0 +1,26 @@ +for (var i=0; i < document.links.length; i++) { + var uzblid = 'uzbl_link_hint_'; + var li = document.links[i]; + var pre = document.getElementById(uzblid+i); + + if (pre) { + li.removeChild(pre); + } else { + var hint = document.createElement('div'); + hint.setAttribute('id',uzblid+i); + hint.innerHTML = i; + hint.style.display='inline'; + hint.style.lineHeight='90%'; + hint.style.backgroundColor='red'; + hint.style.color='white'; + hint.style.fontSize='small-xx'; + hint.style.fontWeight='light'; + hint.style.margin='0px'; + hint.style.padding='2px'; + hint.style.position='absolute'; + hint.style.textDecoration='none'; + hint.style.left=li.style.left; + hint.style.top=li.style.top; + li.insertAdjacentElement('afterBegin',hint); + } +} @@ -429,7 +429,8 @@ static struct {char *name; Command command;} cmdlist[] = { "zoom_in", view_zoom_in, }, //Can crash (when max zoom reached?). { "zoom_out", view_zoom_out, }, { "uri", load_uri }, - { "script", run_js }, + { "js", run_js }, + { "script", run_external_js }, { "toggle_status", toggle_status_cb }, { "spawn", spawn }, { "sh", spawn_sh }, @@ -516,6 +517,33 @@ run_js (WebKitWebView * web_view, const gchar *param) { } static void +run_external_js (WebKitWebView * web_view, const gchar *param) { + if (param) { + FILE* fp = fopen (param, "r"); + gchar* buffer = malloc(512); + gchar* js = NULL; + + if (fp != NULL) { + while (fgets (buffer, 512, fp) != NULL) { + if (js == NULL) { + js = g_strdup ((const gchar*) buffer); + } else { + gchar* newjs = g_strconcat (js, buffer, NULL); + js = newjs; + } + bzero (buffer, strlen (buffer)); + } + webkit_web_view_execute_script (web_view, js); + } else { + fprintf (stderr, "JavaScript file '%s' not be read.\n", param); + } + fclose (fp); + g_free (buffer); + g_free (js); + } +} + +static void search_text (WebKitWebView *page, const char *param, const gboolean forward) { if ((param) && (param[0] != '\0')) { strcpy(uzbl.state.searchtx, param); @@ -360,6 +360,9 @@ search_reverse_text (WebKitWebView *page, const char *param); static void run_js (WebKitWebView * web_view, const gchar *param); +static void +run_external_js (WebKitWebView * web_view, const gchar *param); + static void handle_cookies (SoupSession *session, SoupMessage *msg, gpointer user_data); |