使用JS替换Gmail邮件正文中的文本
我想为 Google Chrome 编写一个 GnuPG 扩展。到目前为止,一切都按预期进行:如果我检测到 ASCII 装甲加密文本,我会用我的扩展解析它,然后替换它。 (输入密码后)
Gmail 在邮件正文中散布着大量标签,因此我的简单 JS 方法不再起作用。有没有什么东西可以选择一定数量的可见文本,无论其中包含多少个标签,并将其替换为其他文本? (标签不需要生存)。即我想就地解密邮件正文。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你需要的是这样的:
这个正则表达式将删除所有标签,留下纯文本......
只需要替换任何东西...像这样:
...关于选择特定部分,您可以使用子字符串,我猜!
what do you need is something like this:
this regexp will remove all tags, an leave plain text...
just gotta replace for nothing... something like this:
...and about selecting an specific part you can use substring, I guess!
我真正需要做的是有点不同:
扩展我的正则表达式,这样它就不关心标签:
var re = /-----[\s\S]+?-----[\s\S]+?-----[\s\S]+?- ---/gm;
使用 gibatronic 提供的正则表达式删除标签,然后使用 gpg 进一步处理清理后的文本
使用
use
body.innerHTML.replace()
将 1) 中的匹配项替换为 3) 中处理后的文本它现在可以工作,唯一的问题是它会破坏 Gmail。网站布局保持不变,但所有按钮和链接都失效了。唯一的解决办法是重新加载页面。必须解决这个问题:S
What I really needed to do was a little different:
expand my regex so it didn't care about tags:
var re = /-----[\s\S]+?-----[\s\S]+?-----[\s\S]+?-----/gm;
store all the matches, with tags
use the regex provided by gibatronic to remove tags and then further process the cleaned text using gpg
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