开发者

Use JS to replace text in Gmail message body

I want to write an GnuPG extension for Goo开发者_高级运维gle 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.


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!


What I really needed to do was a little different:

  1. expand my regex so it didn't care about tags:

    var re = /-----[\s\S]+?-----[\s\S]+?-----[\s\S]+?-----/gm;

  2. store all the matches, with tags

  3. use the regex provided by gibatronic to remove tags and then further process the cleaned text using gpg

  4. use body.innerHTML.replace() to replace the matches from 1) with the processed text from 3)

It works now, the only problem is it breaks Gmail. Site layout stays intact, but all buttons and links become defunct. Only solution is to reload the page. Gotta fix this :S

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜