Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jun 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Modify HTML via Bookmarklet

    Hey guys, I'm looking to modify any arbitrary page via a JS bookmarklet.

    The goal here is to do a client side JS based PGP decryption that works regardless of the site.

    I'm having some success, but I'm finding I can't actually parse any of the data I extract.


    This totally works when summoned via bookmarklet:
    Code:
    function htmlreplace(a, b, element) {    
        if (!element) element = document.body;    
        var nodes = element.childNodes;
        for (var n=0; n<nodes.length; n++) {
            if (nodes[n].nodeType == Node.TEXT_NODE) {
                var r = new RegExp(a, 'gi');
                nodes[n].textContent = nodes[n].textContent.replace(r, b);
            } else {
                htmlreplace(a, b, nodes[n]);
            }
        }
    }
    
    htmlreplace('a', 'X');
    This totally doesn't work:
    Code:
    function htmlreplace(a, b, element) {    
        if (!element) element = document.body;    
        var nodes = element.childNodes;
        for (var n=0; n<nodes.length; n++) {
            
            // THE FOLLOWING ERRORS OUT
            if (nodes[n].indexOf("BEGIN") >= 0) {
                console.log(nodes[n]);
            }
        }
    }
    
    htmlreplace('a', 'X');
    Anyone have any ideas how I can parse the content? specifically I want to make a string variable that contains everything between:
    "BEGINS" and
    "ENDS"
    and then programatically modify that string and then plonk the string back to where it once was. (for any number of BEGINS/ENDS that may exist on the page)

    Anyone have any ideas?

  • #2
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    From your own first example, you should know that you can't call indexOf directly on a node.

  • #3
    New to the CF scene
    Join Date
    Jun 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    DOH!

    thanks... so for the official record, nodes[n].nodeValue


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •