librelist archives

« back to archive

'delete-all-but' functionality

'delete-all-but' functionality

From:
Marco Wahl
Date:
2015-05-20 @ 12:28
Hi,

I discovered the command 'delete' in conkeror which deletes a dom-node
(and which is bound to key 'd').  Is there already the inverse function
which deletes all but one dom-node?


Best regards,  Marco
-- 
GPG: 0x49010A040A3AE6F2

Re: [conkeror] 'delete-all-but' functionality

From:
Sean McAfee
Date:
2015-05-20 @ 17:42
On Wed, May 20, 2015 at 5:28 AM, Marco Wahl <marcowahlsoft@gmail.com> wrote:

> I discovered the command 'delete' in conkeror which deletes a dom-node
> (and which is bound to key 'd').  Is there already the inverse function
> which deletes all but one dom-node?
>

I doubt it, but it's easy to write such a function by tweaking "delete":

interactive("delete-all-but",
    "Delete all body elements except for a given DOM node.",
    function (I) {
        var elem = yield read_browser_object(I);
        if (! (elem instanceof Ci.nsIDOMNode))
            throw interactive_error("Cannot delete item");
        var body = I.buffer.document.getElementsByTagName("BODY")[0];
        while (body.firstChild) body.removeChild(body.firstChild);
        body.appendChild(elem);
    },
    $browser_object = browser_object_dom_node);

Re: 'delete-all-but' functionality

From:
Marco Wahl
Date:
2015-05-20 @ 18:03
Sean McAfee <eefacm@gmail.com> writes:

> On Wed, May 20, 2015 at 5:28 AM, Marco Wahl <marcowahlsoft@gmail.com> wrote:
>
>> I discovered the command 'delete' in conkeror which deletes a dom-node
>> (and which is bound to key 'd').  Is there already the inverse function
>> which deletes all but one dom-node?
>>
>
> I doubt it, but it's easy to write such a function by tweaking "delete":
>
> interactive("delete-all-but",
>     "Delete all body elements except for a given DOM node.",
>     function (I) {
>         var elem = yield read_browser_object(I);
>         if (! (elem instanceof Ci.nsIDOMNode))
>             throw interactive_error("Cannot delete item");
>         var body = I.buffer.document.getElementsByTagName("BODY")[0];
>         while (body.firstChild) body.removeChild(body.firstChild);
>         body.appendChild(elem);
>     },
>     $browser_object = browser_object_dom_node);

Wow!  This is it!  And awesome!


Thanks,  Marco
-- 
GPG: 0x49010A040A3AE6F2