On Mon, Dec 13, 2010 at 06:30:30PM +0800, zwz wrote:
> "John J. Foerch" <[email protected]> writes:
> 
> > On Sun, Dec 12, 2010 at 04:13:42PM +0800, zwz wrote:
> >> "John J. Foerch" <[email protected]> writes:
> >> 
> >> > On Sun, Dec 12, 2010 at 03:02:25PM +0800, zwz wrote:
> >> >> Hi,
> >> >> I want to write a hook that is triggered when finishing downloading
> >> >> something, and record the link and target location into a file (by
> >> >> emacs).
> >> >> 
> >> >> The problem here is how to write js code to get the link and target
> >> >> location of the thing I am downloading.
> >> >> 
> >> >> btw, it seems "~" is the default target dir for downloading, but is
> >> >> there a separable variable for that?
> >> >> 
> >> >> Best regards,
> >> >> zwz
> >> >
> >> >
> >> > Something like this:
> >> >
> >> >   function foo (info) {
> >> >      // info.source is an nsIURI of the url that was downloaded.
> >> >      var url = info.source.spec;
> >> >
> >> >      // info.target_file is an nsIFile/nsILocalFile of the target.
> >> >      var pathstr = info.target_file.path;
> >> >   }
> >> >   add_hook('download_finished_hook', foo);
> >> >
> >> >
> >> > The variable cwd holds the default download directory. Must be set
> > to an
> >> > nsILocalFile object (which is the return type of 'make_file') not a
> >> > string.
> >> 
> >> Thanks a lot.
> >> So can I write code as follows in rc-file
> >> cwd=make_file("d:/downloads");
> >> 
> >> And can I close the download buffer in the function foo?
> >> 
> >
> >
> > Automatically killing the download buffer is a little trickier.  The
> > download-info object doesn't have a references to buffers displaying its
> > information. (You can have more than one download buffer monitoring a
> > single download.)
> >
> > So, thinking this through, you would need a hook that runs any time a
> > download-buffer is created, which plants a kill callback in the buffer's
> > download-info.  Something like this:
> >
> >   function install_download_buffer_closer (b) {
> >       if (b instanceof download_buffer) {
> >           add_hook.call(b.info, "download_finished_hook",
> >                         function () {
> >                             kill_buffer(b);
> >                         });
> >       }
> >   }
> >   add_hook('create_buffer_hook', install_download_buffer_closer);
> Nice solution. Thanks.
> But does it also work if I 
> remove_hook("download_added_hook", open_download_buffer_automatically)
> which makes the download buffer not open at all, while the hook foo is
> still called?
> 
> p.s. foo is added by add_hook('download_finished_hook', foo);
> 


yes, it should.

-- 
John Foerch
_______________________________________________
Conkeror mailing list
[email protected]
https://www.mozdev.org/mailman/listinfo/conkeror

Reply via email to