Search code examples
javascriptregexgnupg

Use JS to replace text in Gmail message body


I want to write an GnuPG extension for Google Chrome. So far, everything works as expected: If I detect ASCII armored crypt-text, I parse it with my extension and then replace it. (after password has been entered)

Gmail however litters the message body with an insane amount of tags, so my simple JS approach doesn't work anymore. Is there something which can select an certain amount of visible text, no matter how many tags are contained in it, and replace it with some other text? (the tags don't need to survive). ie I want to unencrypt the mailbody in place.


Solution

  • what do you need is something like this:

    /<[^>]+>/g
    

    this regexp will remove all tags, an leave plain text... just gotta replace for nothing... something like this:

    "<p>text <b>full</b> of <i>junk</i> and <u>unwanted</u> tags</p>".replace(/<[^>]+>/g, "");
    

    ...and about selecting an specific part you can use substring, I guess!