I want to read the contents of Gmail messages and add some fancyness on links. Here's some code:
我想阅读Gmail邮件的内容,并在链接上添加一些幻想。这是一些代码:
unsafeWindow.gmonkey.load("1.0", function(gmail){
gmail.registerViewChangeCallback(function(){
if (gmail.getActiveViewType && gmail.getActiveViewType() == "cv") {
var viewElement = gmail.getActiveViewElement()
// Do things with viewElement
}
})
})
The actual detection of links in the dom objects for the mails is the easy part. The problem is that the registerViewChangeCallback
only runs when you display a thread. Large threads will have most of it's messages hidden, only to be loaded by a users request. I haven't found a Gmail greasemonkey API method for this particular action (loading a individual message), which is when I need to run my script.
实际检测邮件的dom对象中的链接是很容易的部分。问题是registerViewChangeCallback仅在显示线程时运行。大线程将隐藏大部分消息,仅由用户请求加载。我还没有找到针对此特定操作的Gmail greasemonkey API方法(加载单个邮件),这是我需要运行脚本的时候。
Any suggestions?
2 个解决方案
#1
As you say, the registerViewChangeCallback() function only fires when the user changes their view from e.g. threads to archives, etc.
正如您所说,registerViewChangeCallback()函数仅在用户更改其视图时触发。档案等的线程
What you really need is to add a function that intercepts gmail's post-backs and then changes the links. I have never tried doing it myself, but this answer has some sample code for you. When gmail has retrieved a new message, it will fire a readystatechange
event, which your code can intercept. You can then change the contents of the message in whichever way you wish (although you may have to wait for a moment to allow gmail to insert the message first - not sure about that one).
你真正需要的是添加一个拦截gmail的post-backs然后更改链接的函数。我自己从未尝试过,但这个答案有一些示例代码供您使用。当gmail检索到新消息时,它将触发readystatechange事件,您的代码可以拦截该事件。然后,您可以按照您希望的任何方式更改邮件的内容(尽管您可能需要等待片刻才能允许gmail首先插入邮件 - 不确定该邮件的内容)。
#2
I think you'll find that some messages are loaded when they're listed in the thread; hence your problem.
我想你会发现一些消息在线程中被列出时会被加载;因此你的问题。
Why don't you just use a custom style anyway? UserStyles FF plugin.
你为什么不直接使用自定义风格? UserStyles FF插件。
#1
As you say, the registerViewChangeCallback() function only fires when the user changes their view from e.g. threads to archives, etc.
正如您所说,registerViewChangeCallback()函数仅在用户更改其视图时触发。档案等的线程
What you really need is to add a function that intercepts gmail's post-backs and then changes the links. I have never tried doing it myself, but this answer has some sample code for you. When gmail has retrieved a new message, it will fire a readystatechange
event, which your code can intercept. You can then change the contents of the message in whichever way you wish (although you may have to wait for a moment to allow gmail to insert the message first - not sure about that one).
你真正需要的是添加一个拦截gmail的post-backs然后更改链接的函数。我自己从未尝试过,但这个答案有一些示例代码供您使用。当gmail检索到新消息时,它将触发readystatechange事件,您的代码可以拦截该事件。然后,您可以按照您希望的任何方式更改邮件的内容(尽管您可能需要等待片刻才能允许gmail首先插入邮件 - 不确定该邮件的内容)。
#2
I think you'll find that some messages are loaded when they're listed in the thread; hence your problem.
我想你会发现一些消息在线程中被列出时会被加载;因此你的问题。
Why don't you just use a custom style anyway? UserStyles FF plugin.
你为什么不直接使用自定义风格? UserStyles FF插件。