summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorportix <none@none>2012-05-14 22:34:26 +0200
committerportix <none@none>2012-05-14 22:34:26 +0200
commit5124855ce8c8a95616009751e38fb802b3082f51 (patch)
treeeb36e7c3d211b69e1f7847e3ed1c6d68597b6f27
parentf8e48594bcffcbceb121c9ca58a145458e4beac6 (diff)
downloaddwb-5124855ce8c8a95616009751e38fb802b3082f51.zip
Remove javascript scripts directory and reload_scripts; change io.fileTest to system.fileTest; implement system.mkdir
--HG-- branch : scripts
-rw-r--r--api/jsapi.txt43
-rw-r--r--doc/dwb.173
-rw-r--r--extensions/userscripts2
-rw-r--r--scripts/lib/extensions.js2
-rw-r--r--src/commands.c9
-rw-r--r--src/commands.h1
-rw-r--r--src/config.h4
-rw-r--r--src/dwb.c38
-rw-r--r--src/dwb.h4
-rw-r--r--src/scripts.c58
-rw-r--r--src/view.c10
11 files changed, 108 insertions, 136 deletions
diff --git a/api/jsapi.txt b/api/jsapi.txt
index 6cf1ada3..e1ef4c39 100644
--- a/api/jsapi.txt
+++ b/api/jsapi.txt
@@ -352,6 +352,21 @@ _path_;; Path to a file that should be read
_returns_;; A string with the file content
****
+
+====
+.Example
+[source,javascript]
+---------------------------------
+var text = io.read("/home/foo/textfile.txt");
+io.print(text);
+--------------------------------
+====
+
+[[system]]
+=== system ===
+
+The +system+ object implements system functions.
+
****
[[fileTest]]
[float]
@@ -359,7 +374,7 @@ _returns_;; A string with the file content
[source,javascript]
----
-Boolean io.fileTest(String path, FileTest flags)
+Boolean system.fileTest(String path, FileTest flags)
----
Checks for <<FileTest>> flags on a file.
@@ -371,20 +386,24 @@ _flags_;; The flags to test
_returns_;; +true+ if any of the test on the flags is true
****
+****
+[[mkdir]]
+[float]
+==== *mkdir()* ====
-====
-.Example
[source,javascript]
----------------------------------
-var text = io.read("/home/foo/textfile.txt");
-io.print(text);
---------------------------------
-====
+----
+Boolean system.mkdir(String path, Number mode)
+----
-[[system]]
-=== system ===
+Creates a directory and all parent directories.
-The +system+ object implements system functions.
+ ::
+
+_path_;; Path to create
+_mode_;; The permissions the directory will get
+_returns_;; +true+ if creation was successful or directory already existed
+****
****
[[spawn]]
@@ -1695,7 +1714,7 @@ Print an error message and call stack to stderr.
::
_name_;; Name of the extension
-_message|e_;; The error message or and Error
+_message|e_;; The error message or an Error
_message_;; If the second parameter is an Error, an optional message can be
specified.
****
diff --git a/doc/dwb.1 b/doc/dwb.1
index 2e222f4b..f3bd7700 100644
--- a/doc/dwb.1
+++ b/doc/dwb.1
@@ -2,12 +2,12 @@
.\" Title: dwb
.\" Author: [FIXME: author] [see http://docbook.sf.net/el/author]
.\" Generator: DocBook XSL Stylesheets v1.76.1 <http://docbook.sf.net/>
-.\" Date: 05/13/2012
+.\" Date: 05/14/2012
.\" Manual: \ \&
.\" Source: \ \&
.\" Language: English
.\"
-.TH "DWB" "1" "05/13/2012" "\ \&" "\ \&"
+.TH "DWB" "1" "05/14/2012" "\ \&" "\ \&"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
@@ -1345,7 +1345,6 @@ lt lt lt
lt lt lt
lt lt lt
lt lt lt
-lt lt lt
lt lt lt.
T{
.sp
@@ -1949,15 +1948,6 @@ Reload without using cached data
T}
T{
.sp
-reload_scripts
-T}:T{
-.sp
-T}:T{
-.sp
-Reload all javascript userscripts
-T}
-T{
-.sp
reload_userscripts
T}:T{
.sp
@@ -3517,41 +3507,12 @@ means that the statusbar won\(cqt be visible\&. Default value:
\fIdtws\fR\&.
.RE
.SH "FILES"
-.SS "Scripts"
-.sp
-Javascript userscripts can be stored in \fI~/\&.config/dwb/scripts\fR\&. The scripts are applied to pages depending on their filename extension, there are 4 possible extensions:
-.sp
-Scripts with extension
-.PP
-\fB\&.js\fR
-.RS 4
-are injected into the page directly after the load of a new page is committed\&.
-.RE
-.PP
-\fB\&.all\&.js\fR
-.RS 4
-Scripts with extension
-\fI\&.all\&.js\fR
-are injected into all frames of a page directly after the load of a new frame is committed\&.
-.RE
-.PP
-\fB\&.onload\&.js\fR
-.RS 4
-Scripts with extension
-\fI\&.onload\&.js\fR
-are injected into the page directly when loading of a page is done\&.
-.RE
-.PP
-\fB\&.onload\&.all\&.js\fR
-.RS 4
-Scripts with extension
-\fI\&.onload\&.all\&.js\fR
-are injected into all frames of a page when the load of a frame is done\&.
-.RE
.SS "Userscripts"
.sp
Userscripts can be stored in \fI~/\&.config/dwb/userscripts\fR\&. The first argument of the script will be the current url, the second argument is the title, the third argument will be the profile name, the fourth argument is the numerical modifier and the fifth argument is a commandline argument\&. Also the variables \fIDWB_URI\fR, \fIDWB_TITLE\fR, \fIDWB_PROFILE\fR, \fIDWB_NUMMOD\fR, \fIDWB_ARGUMENT\fR, \fIDWB_REFERER\fR, and \fIDWB_USER_AGENT\fR are set\&. The keybinding for the script must be defined in the script itself in a commented line of the form \fB<comment symbols> dwb: <keybinding>\fR\&.
.sp
+dwb also provides a small javascript api, scripts that use the api must have the special shebang \fB#!javascript\fR, for details see http://portix\&.bitbucket\&.org/dwb/resources/jsapi\&.html\&.
+.sp
.it 1 an-trap
.nr an-no-space-flag 1
.nr an-break-flag 1
@@ -3589,6 +3550,32 @@ echo "js window\&.alert(\*(AqHello world\*(Aq);" > ${DWB_FIFO}
.if n \{\
.RE
.\}
+.sp
+Block requests from specific sites:
+.sp
+.if n \{\
+.RS 4
+.\}
+.nf
+#!javascript
+
+var block = [ new RegExp("https://example\&.org\&.*"), new RegExp("https://example\&.co\&.uk\&.*") ];
+
+signals\&.connect("resource", function(wv, frame, request) {
+ var i, r;
+ for (i=0; i<block\&.length; i++)
+ {
+ if (block[i]\&.test(request\&.uri))
+ {
+ request\&.uri = "about:blank";
+ return true;
+ }
+ }
+});
+.fi
+.if n \{\
+.RE
+.\}
.RE
.SH "RESOURCES"
.sp
diff --git a/extensions/userscripts b/extensions/userscripts
index 9983447a..b84b173f 100644
--- a/extensions/userscripts
+++ b/extensions/userscripts
@@ -292,7 +292,7 @@ function parseScripts() //{{{
var userscript = null;
var script;
for (i=0; i<scripts.length; i++) {
- if (io.fileTest(scripts[i], FileTest.regular)) {
+ if (system.fileTest(scripts[i], FileTest.regular)) {
script = io.read(scripts[i]);
userscript = parseMetaData(script);
}
diff --git a/scripts/lib/extensions.js b/scripts/lib/extensions.js
index 339803e5..a1f40d7a 100644
--- a/scripts/lib/extensions.js
+++ b/scripts/lib/extensions.js
@@ -4,7 +4,7 @@
function getPlugin(name, filename) {
var ret = null;
try {
- if (io.fileTest(filename, FileTest.exists)) {
+ if (system.fileTest(filename, FileTest.exists)) {
ret = include(filename);
}
}
diff --git a/src/commands.c b/src/commands.c
index 71fdc1ae..9d7e15ee 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -650,15 +650,6 @@ commands_quit(KeyMap *km, Arg *arg) {
return STATUS_END;
}/*}}}*/
-/* commands_reload_scripts {{{*/
-DwbStatus
-commands_reload_scripts(KeyMap *km, Arg *arg) {
- dwb_init_scripts();
- for (GList *l = dwb.state.views; l; l=l->next) {
- webkit_web_view_reload(WEBVIEW(l));
- }
- return STATUS_OK;
-}/*}}}*/
DwbStatus
commands_reload_user_scripts(KeyMap *km, Arg *arg) {
dwb_reload_userscripts();
diff --git a/src/commands.h b/src/commands.h
index c45efeda..5807fe38 100644
--- a/src/commands.h
+++ b/src/commands.h
@@ -74,7 +74,6 @@ DwbStatus commands_set_zoom_level(KeyMap *, Arg *);
DwbStatus commands_toggle_hidden_files(KeyMap *, Arg *);
DwbStatus commands_web_inspector(KeyMap *, Arg *);
DwbStatus commands_quit(KeyMap *, Arg *);
-DwbStatus commands_reload_scripts(KeyMap *, Arg *);
DwbStatus commands_reload_user_scripts(KeyMap *, Arg *);
DwbStatus commands_fullscreen(KeyMap *, Arg *);
DwbStatus commands_open_editor(KeyMap *, Arg *);
diff --git a/src/config.h b/src/config.h
index 579be9dd..f4fdaf05 100644
--- a/src/config.h
+++ b/src/config.h
@@ -99,7 +99,6 @@ static KeyValue KEYS[] = {
{ "zoom", { "=", 0, }, },
{ "zoom_out", { "-", 0, }, },
{ "save_search_field", { "gs", 0, }, },
- { "reload_scripts", { NULL, 0, }, },
{ "reload_userscripts", { NULL, 0, }, },
{ "proxy", { "p" , GDK_CONTROL_MASK, }, },
{ "focus_input", { "gi", 0, }, },
@@ -690,9 +689,6 @@ static FunctionMap FMAP [] = {
(Func)commands_web_inspector, "Enable developer extras for the webinspector", POST_SM,
{ 0 }, EP_NONE, { "inspect", "insp", NULL }, },
- { { "reload_scripts", "Reload scripts", }, CP_COMMANDLINE,
- (Func)commands_reload_scripts, NULL, ALWAYS_SM,
- { 0 }, EP_NONE, { NULL }, },
{ { "reload_userscripts", "Reload userscripts", }, CP_COMMANDLINE,
(Func)commands_reload_user_scripts, NULL, POST_SM,
{ 0 }, EP_NONE, { NULL }, },
diff --git a/src/dwb.c b/src/dwb.c
index de36f2e4..20bf9966 100644
--- a/src/dwb.c
+++ b/src/dwb.c
@@ -3125,35 +3125,9 @@ dwb_init_settings() {
g_strfreev(keys);
}/*}}}*/
-/* dwb_init_scripts{{{*/
-void
-dwb_init_scripts() {
- g_free(dwb.misc.scripts);
- GString *normalbuffer = g_string_new(NULL);
- GString *allbuffer = g_string_new(NULL);
-
- setlocale(LC_NUMERIC, "C");
- /* user scripts */
- util_get_directory_content(allbuffer, dwb.files.scriptdir, "onload.all.js");
- dwb.misc.allscripts_onload = g_strdup(allbuffer->str);
- util_get_directory_content(allbuffer, dwb.files.scriptdir, "onload.js");
- dwb.misc.scripts_onload = g_strdup(allbuffer->str);
- g_string_erase(allbuffer, 0, -1);
-
- util_get_directory_content(normalbuffer, dwb.files.scriptdir, "js");
- util_get_directory_content(allbuffer, dwb.files.scriptdir, "all.js");
-
- /* systemscripts */
- g_string_append(normalbuffer, allbuffer->str);
- dwb.misc.scripts = normalbuffer->str;
- dwb.misc.allscripts = allbuffer->str;
- g_string_free(normalbuffer, false);
- g_string_free(allbuffer, false);
- dwb_init_hints(NULL, NULL);
-}/*}}}*/
-
static DwbStatus
dwb_init_hints(GList *gl, WebSettings *s) {
+ setlocale(LC_NUMERIC, "C");
g_free(dwb.misc.hints);
char *scriptpath = util_get_data_file(HINT_SCRIPT, "scripts");
dwb.misc.hints = util_get_file_content(scriptpath);
@@ -3262,13 +3236,13 @@ dwb_pack(const char *layout, gboolean rebuild) {
}
while (g_ascii_isspace(*layout))
layout++;
- if (strlen(layout) != 4) {
+ if (strlen(layout) != WIDGET_PACK_LENGTH) {
layout = default_layout;
ret = STATUS_ERROR;
}
const char *valid_chars = default_layout;
- char *buf = g_ascii_strdown(layout, 4);
+ char *buf = g_ascii_strdown(layout, WIDGET_PACK_LENGTH);
char *matched;
while (*valid_chars) {
if ((matched = strchr(buf, *valid_chars)) == NULL) {
@@ -3498,7 +3472,7 @@ void
dwb_init_files() {
char *path = util_build_path();
char *profile_path = util_check_directory(g_build_filename(path, dwb.misc.profile, NULL));
- char *userscripts, *scripts, *cachedir;
+ char *userscripts, *cachedir;
dwb.fc.bookmarks = NULL;
dwb.fc.history = NULL;
@@ -3544,8 +3518,6 @@ dwb_init_files() {
dwb.files.custom_keys = g_build_filename(profile_path, "custom_keys", NULL);
dwb_check_create(dwb.files.custom_keys);
- scripts = g_build_filename(path, "scripts", NULL);
- dwb.files.scriptdir = util_check_directory(scripts);
userscripts = g_build_filename(path, "userscripts", NULL);
dwb.files.userscripts = util_check_directory(userscripts);
@@ -3717,7 +3689,7 @@ dwb_init() {
dwb_init_custom_keys(false);
domain_init();
adblock_init();
- dwb_init_scripts();
+ dwb_init_hints(NULL, NULL);
dwb_soup_init();
} /*}}}*/ /*}}}*/
diff --git a/src/dwb.h b/src/dwb.h
index 888c9215..352d480c 100644
--- a/src/dwb.h
+++ b/src/dwb.h
@@ -171,6 +171,7 @@ GTimer *__timer;
#define BPGB 1073741824
#define DEFAULT_WIDGET_PACKING "dtws"
+#define WIDGET_PACK_LENGTH 4
/*}}}*/
@@ -681,8 +682,6 @@ struct _Misc {
char *scripts_onload;
char *hints;
/* applied to all frames */
- char *allscripts;
- char *allscripts_onload;
const char *profile;
const char *default_search;
gint find_delay;
@@ -728,7 +727,6 @@ struct _Files {
const char *keys;
const char *mimetypes;
const char *quickmarks;
- const char *scriptdir;
const char *searchengines;
const char *session;
const char *settings;
diff --git a/src/scripts.c b/src/scripts.c
index 024b55ef..ce8caa54 100644
--- a/src/scripts.c
+++ b/src/scripts.c
@@ -785,6 +785,43 @@ error_out:
g_free(cmdline);
return JSValueMakeNumber(ctx, ret);
}/*}}}*/
+
+/* system_file_test {{{*/
+static JSValueRef
+system_file_test(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc) {
+ if (argc < 2) {
+ js_make_exception(ctx, exc, EXCEPTION("system.fileTest needs an argument."));
+ return JSValueMakeBoolean(ctx, false);
+ }
+ char *path = js_value_to_char(ctx, argv[0], PATH_MAX, exc);
+ if (path == NULL)
+ return JSValueMakeBoolean(ctx, false);
+ double test = JSValueToNumber(ctx, argv[1], exc);
+ if (test == NAN || ! ( (((guint)test) & G_FILE_TEST_VALID) == (guint)test) )
+ return JSValueMakeBoolean(ctx, false);
+ gboolean ret = g_file_test(path, (GFileTest) test);
+ g_free(path);
+ return JSValueMakeBoolean(ctx, ret);
+}/*}}}*/
+
+/* system_mkdir {{{*/
+static JSValueRef
+system_mkdir(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc) {
+ gboolean ret = false;
+ if (argc < 2) {
+ js_make_exception(ctx, exc, EXCEPTION("system.mkdir needs an argument."));
+ return JSValueMakeBoolean(ctx, false);
+ }
+ char *path = js_value_to_char(ctx, argv[0], PATH_MAX, exc);
+ double mode = JSValueToNumber(ctx, argv[1], exc);
+ if (path != NULL && mode != NAN) {
+ ret = g_mkdir_with_parents(path, (gint)mode) == 0;
+ }
+ g_free(path);
+ return JSValueMakeBoolean(ctx, ret);
+
+}/*}}}*/
+
/*}}}*/
/* IO {{{*/
@@ -832,24 +869,6 @@ error_out:
}/*}}}*/
-/* io_file_test {{{*/
-static JSValueRef
-io_file_test(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc) {
- if (argc < 2) {
- js_make_exception(ctx, exc, EXCEPTION("io.read needs an argument."));
- return JSValueMakeBoolean(ctx, false);
- }
- char *path = js_value_to_char(ctx, argv[0], PATH_MAX, exc);
- if (path == NULL)
- return JSValueMakeBoolean(ctx, false);
- double test = JSValueToNumber(ctx, argv[1], exc);
- if (test == NAN || ! ( (((guint)test) & G_FILE_TEST_VALID) == (guint)test) )
- return JSValueMakeBoolean(ctx, false);
- gboolean ret = g_file_test(path, (GFileTest) test);
- g_free(path);
- return JSValueMakeBoolean(ctx, ret);
-}/*}}}*/
-
/* io_notify {{{*/
static JSValueRef
io_notify(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc) {
@@ -1292,7 +1311,6 @@ create_global_object() {
{ "prompt", io_prompt, kJSDefaultAttributes },
{ "read", io_read, kJSDefaultAttributes },
{ "write", io_write, kJSDefaultAttributes },
- { "fileTest", io_file_test, kJSDefaultAttributes },
{ "notify", io_notify, kJSDefaultAttributes },
{ "error", io_error, kJSDefaultAttributes },
{ 0, 0, 0 },
@@ -1304,6 +1322,8 @@ create_global_object() {
JSStaticFunction system_functions[] = {
{ "spawn", system_spawn, kJSDefaultAttributes },
{ "getEnv", system_get_env, kJSDefaultAttributes },
+ { "fileTest", system_file_test, kJSDefaultAttributes },
+ { "mkdir", system_mkdir, kJSDefaultAttributes },
{ 0, 0, 0 },
};
class = create_class("system", system_functions, NULL);
diff --git a/src/view.c b/src/view.c
index 88abdba0..47fa56a2 100644
--- a/src/view.c
+++ b/src/view.c
@@ -230,16 +230,6 @@ view_frame_committed_cb(WebKitWebFrame *frame, GList *gl) {
.objects = { G_OBJECT(frame) }, SCRIPTS_SIG_META(NULL, FRAME_STATUS, 1) };
scripts_emit(&signal);
}
- WebKitLoadStatus status = webkit_web_frame_get_load_status(frame);
- switch (status) {
- case WEBKIT_LOAD_COMMITTED:
- dwb_execute_script(frame, dwb.misc.allscripts, false);
- break;
- case WEBKIT_LOAD_FINISHED:
- dwb_execute_script(frame, dwb.misc.allscripts_onload, false);
- break;
- default: return;
- }
}/*}}}*/
/* view_frame_created_cb {{{*/