获取带有chrome扩展名的打开邮件的gmail邮件正文 [英] Get gmail message body of an open mail with a chrome extension
问题描述
对于一个项目,我需要获取当前打开的消息的正文,并将该消息传递给Web服务,以便处理和存储它的一些数据。
For a project I need to get the body of the currently open message and pass that message to a webservice for processing and storing some data of it.
I thaught最好的方法是使用扩展来获取邮件正文(以及一些其他信息),然后将其作为webrequest发送到服务以插入数据库。
I thaught the best way to do it is to use an extension to grab the message body (and some additional information) and then send that as a webrequest to a service for insertion into the database.
但我不知道应该如何应对。我按照一些教程让我开始使用chrome插件,但是我找不到如何获取消息的正文。
But I have no idea how I should handle this. I followed some tutorials to get me started on chrome plugins but I can't find how to get the body of the message.
我发现你需要内容脚本,但即便如此,我也不知道。
I have found that you need content scripts for it, but even then I have no clue.
可以有人给我一个开头吗?
Can anyone give me a headstart on this?
推荐答案
如果我必须这样做,我会试着找出它的ID包含GMAIL客户端主体的DIV ...
使用jQuery抓取DIV的HTML或文本内容非常简单...看看: http://api.jquery.com/html/
If I had to do this, I would try and find out the ID of the DIV that contains the body on the GMAIL client... Using jQuery to grab the HTML or text contents of a DIV is real simple... take a look: http://api.jquery.com/html/
一个简单的jQuery选择器看起来像什么像这样:
A simple jQuery selector would look something like this:
$("#gmailsBodyDivID").html()
如果jQuery不是一个选项,你可以使用JavaScript的 getElementByID
获取DIV(http:// www.w3schools.com/jsref/met_doc_getelementbyid.asp)
If jQuery is not an option, you can get the DIV using JavaScript's getElementByID
(http://www.w3schools.com/jsref/met_doc_getelementbyid.asp)
最后,如DudeOnRock所述,您应该对您的Web服务使用Ajax请求。
Finally, as mentioned by DudeOnRock, you should use an Ajax request to your webservice.
困难的部分是知道Gmail如何命名你的DIV正在寻找...我只是快速看一下,在我的,有一些奇怪的命名...
The hard part is to know how Gmail names the DIV you're looking for... I just took a quick look and on mine, there was some weird naming...
<div id=":w1" class="ii gt adP adO"><div id=":w2">
我不确定:w1或:w2代表什么,也不知道如何使用它们与jQuery选择器...也许更有知识的人可能会在那里发光。
I'm not sure what the ":w1" or ":w2" stand for, nor how to use them with a jQuery selector... maybe someone more knowledgeable might shed some light there.
...所以我想你应该首先关注那个...
...so I guess you should focus on that first...
如果ID证明很难,你可能想要按类名使用jQuery选择器......
If IDs prove hard, you might want to use a jQuery selector by class names...
good好运!
这篇关于获取带有chrome扩展名的打开邮件的gmail邮件正文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!