diff --git a/common/content/events.js b/common/content/events.js index 38e0e03e..6f1dfda0 100644 --- a/common/content/events.js +++ b/common/content/events.js @@ -87,6 +87,8 @@ function AutoCommands() //{{{ { if (args.bang) autocommands.remove(event, regex); + if (args["-javascript"]) + cmd = eval("(function(args) { with(args) {" + cmd + "} })"); autocommands.add(events, regex, cmd); } else @@ -107,7 +109,8 @@ function AutoCommands() //{{{ { bang: true, completer: function (context) completion.autocmdEvent(context), - literal: 2 + literal: 2, + options: [[["-javascript", "-js"], commands.OPTION_NOARG]] }); // TODO: expand target to all buffers diff --git a/vimperator/NEWS b/vimperator/NEWS index bbb9cb14..f0f9db11 100644 --- a/vimperator/NEWS +++ b/vimperator/NEWS @@ -13,7 +13,9 @@ { arg: true, count: true, motion: true, route: true }); * IMPORTANT: shifted key notation now matches Vim's behaviour. E.g. and are equivalent, to map the uppercase character use . - Is this still true, or going to be true? --djk - * add 'private' - enter private browsing mode + * add '-javascript' flag to :autocommand + * add 'private' - enter private browsing mode, matching 'PrivateMode' + autocommand * add -description option to :command * command-line options are now supported via the host application's -liberator option diff --git a/vimperator/content/config.js b/vimperator/content/config.js index b8227f42..a8972197 100644 --- a/vimperator/content/config.js +++ b/vimperator/content/config.js @@ -55,6 +55,7 @@ const config = { //{{{ ["LocationChange", "Triggered when changing tabs or when navigation to a new location"], ["PageLoadPre", "Triggered after a page load is initiated"], ["PageLoad", "Triggered when a page gets (re)loaded/opened"], + ["PrivateMode", "Triggered private mode is activated or deactivated"], ["ShellCmdPost", "Triggered after executing a shell command with :!cmd"], ["VimperatorEnter", "Triggered after Firefox starts"], ["VimperatorLeavePre", "Triggered before exiting Firefox, just before destroying each module"], @@ -485,17 +486,11 @@ const config = { //{{{ "Set the 'private browsing' option", "boolean", false, { - setter: function (value) - { - return services.get("privateBrowsing").privateBrowsingEnabled = value; - }, - getter: function () - { - return services.get("privateBrowsing").privateBrowsingEnabled; - } + setter: function (value) services.get("privateBrowsing").privateBrowsingEnabled = value, + getter: function () services.get("privateBrowsing").privateBrowsingEnabled, }); let services = modules.services; // Storage objects are global to all windows, 'modules' isn't. - storage.newObject("private-mode-observer", function () { + storage.newObject("private-mode", function () { ({ init: function () { services.get("observer").addObserver(this, "private-browsing", false); @@ -508,6 +503,7 @@ const config = { //{{{ storage.privateMode = true; else if (data == "exit") storage.privateMode = false; + storage.fireEvent("private-mode", "change", storage.privateMode); } else if (topic == "quit-application") { services.get("observer").removeObserver(this, "quit-application"); services.get("observer").removeObserver(this, "private-browsing"); @@ -515,6 +511,10 @@ const config = { //{{{ }, }).init(); }, false); + storage.addObserver("private-mode", + function (key, event, value) { + autocommands.trigger("PrivateMode", { state: value }); + }, window); } // TODO: merge with Vimperator version and add Muttator version diff --git a/vimperator/locale/en-US/autocommands.txt b/vimperator/locale/en-US/autocommands.txt index a2bed93c..c8b97e9f 100644 --- a/vimperator/locale/en-US/autocommands.txt +++ b/vimperator/locale/en-US/autocommands.txt @@ -10,6 +10,9 @@ Execute commands automatically on events. [c]:au[tocmd][c] {event} {pat} {cmd} +If the *-javascript* (short name *-js*) option is specified, {cmd} is executed +as JavaScript code, with any supplied arguments available as variables. + Add {cmd} to the list of commands Vimperator will execute on {event} for a URL matching {pat}: * [c]:autocmd[!][c] {events} {pat}: list/remove autocommands filtered by {events} and {pat} @@ -28,6 +31,7 @@ Available {events}: *LocationChange* Triggered when changing tabs or when navigating to a new location *PageLoadPre* Triggered after a page load is initiated *PageLoad* Triggered when a page gets (re)loaded/opened +*PrivateMode* Triggered private mode is activated or deactivated *ShellCmdPost* Triggered after executing a shell command with [c]:![c]#{cmd} *VimperatorEnter* Triggered after Firefox starts *VimperatorLeavePre* Triggered before exiting Firefox, just before destroying each module @@ -49,7 +53,7 @@ The following keywords are available where relevant: ** The icon associated with . Only for *BookmarkAdd*. ** The size of a downloaded file. Only for *DownloadPost*. ** The target destination of a download. Only for *DownloadPost*. -** The new fullscreen state. Only for *Fullscreen*. +** The new state. Only for *Fullscreen* and *PrivateMode*. ** The color scheme name. Only for *ColorScheme*. -------------------------------------------------------------- diff --git a/xulmus/locale/en-US/autocommands.txt b/xulmus/locale/en-US/autocommands.txt index b5cdeb05..875b84d9 100644 --- a/xulmus/locale/en-US/autocommands.txt +++ b/xulmus/locale/en-US/autocommands.txt @@ -12,6 +12,9 @@ Execute commands automatically on events. Add {cmd} to the list of commands Xulmus will execute on {event} for a URL matching {pat}: +If the *-javascript* (short name *-js*) option is specified, {cmd} is executed +as JavaScript code, with any supplied arguments available as variables. + * [c]:autocmd[!][c] {events} {pat}: list/remove autocommands filtered by {events} and {pat} * [c]:autocmd[!][c] {events}: list/remove autocommands matching {events} * [c]:autocmd[!][c] * {pat}: list/remove autocommands matching {pat}