如何捕捉GMail自动刷新

发布于 2024-08-24 16:11:05 字数 225 浏览 10 评论 0原文

我编写了一个 用户脚本 来突出显示 GMail 中的当前行(由箭头指示)。不幸的是,突出显示只会保留到 GMail 收件箱自动刷新(这种情况经常发生)。有没有办法捕获该事件,以便我可以重新应用突出显示?我不想在超时时这样做。还有另一个用户脚本可以执行此操作并加载 CPU。

I wrote a userscript to highlight the current row in GMail (indicated by the arrow). Unfortunately the highlight will only stay until GMail Inbox is auto-refreshed, which happens quite often. Is there a way to catch that event so I could reapply the highlighting? I don't want to do it on timeout. There is another userscript that does that and it loads up CPU.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

挖鼻大婶 2024-08-31 16:11:05

在我看来,您可能需要查看此文档,它是 Gmail 的文档gmonkey API,这是google为greasemonkey脚本提供的API。

此页面描述了一个监视视图更改的用户脚本,这应该是与您需要的非常相似。

我想你会想要类似的东西:

window.addEventListener('load', function() {
  if (unsafeWindow.gmonkey) {
    unsafeWindow.gmonkey.load('1.0', function(gmail) {
      function changedViewType() {
        // Threadlist
        if(gmail.getActiveViewType()== "tl"){
          // code to highlight the current row here...
        }
      }
      gmail.registerViewChangeCallback(changedViewType);
      changedViewType();
    });
  }
}, true);

It sounds to me like you will want to review this document which is documentation for the Gmail gmonkey API, which is an API that google provides for greasemonkey scripts.

This page describes a userscript which monitors view changes, and this should be very similar to what you need.

I assume you will want something like:

window.addEventListener('load', function() {
  if (unsafeWindow.gmonkey) {
    unsafeWindow.gmonkey.load('1.0', function(gmail) {
      function changedViewType() {
        // Threadlist
        if(gmail.getActiveViewType()== "tl"){
          // code to highlight the current row here...
        }
      }
      gmail.registerViewChangeCallback(changedViewType);
      changedViewType();
    });
  }
}, true);
错々过的事 2024-08-31 16:11:05

如果添加一个计时器并查看突出显示元素何时消失?或者如果父对象更改其地址(使用 ===)。

If you add a timer and look when your highlight element disappear? or if a parent object change its address (with ===).

你列表最软的妹 2024-08-31 16:11:05

考虑使用 CSS 用户样式 (http://userstyles.org/ ) 而不是用户脚本。您可以使用 Firefox 的 DOM 检查器来查看所选行中的 HTMl 元素和类,然后编写一个仅选择该行的 CSS 选择器应该非常简单。

consider a CSS userstyle (http://userstyles.org/ ) instead of a userscript. You can use Firefox's DOM inspector to look at the HTMl elements and classes in the selected row, and then it should be pretty straightforward to write a CSS selector that select just that row.

北城半夏 2024-08-31 16:11:05

从今天开始,以下代码确实适用于当前的 gmail UI,积分请转到 https://cleverinsert.com/来自他们的 gmail 插件。每次刷新收件箱时都会触发回调。您必须在文档完全加载后创建 MutationSummary。你可以在chrome中安装并调试他们的插件来查看一下。

您必须包含 mutation-summary.js

new MutationSummary({
  callback: render,
  rootNode: document.querySelector('.AO'),
  observeOwnChanges: false,
  oldPreviousSibling: true,
  queries: [
      { element: 'td.xW' }
  ]});

function render(a) {
  console.log("callback triggered");           
}

The following code does work with the current gmail UI as of today, credits go to https://cleverinsert.com/ taken from their gmail plugin. The callback is fired everytime the inbox is refreshed. You have to create the MutationSummary after the document has loaded completely. You can install and debug their plugin in chrome to check it out.

You have to include the mutation-summary.js

new MutationSummary({
  callback: render,
  rootNode: document.querySelector('.AO'),
  observeOwnChanges: false,
  oldPreviousSibling: true,
  queries: [
      { element: 'td.xW' }
  ]});

function render(a) {
  console.log("callback triggered");           
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文