在Gmail中开发“标记为已读|标记为未读”按钮

时间:2013-12-21 01:09:26

标签: javascript google-chrome-extension gmail

我正在尝试为针对Gmail的Chrome扩展程序开发新功能。我们的想法是使当前的“标记为已读”按钮[1]更加智能,即当检查未读对话时,建议当前“标记为已读”按钮,并且每当检查到对话时,建议新的“标记”作为未读“按钮。

下面提供了JS脚本的摘录(基于jQuery)。

我遇到的问题是按钮的行为,无论是在“标记为未读”还是“标记为已读”状态下都是持久的。更确切地说,一旦加载Gmail并在收件箱中点击未读(读)对话,导航中就会显示“标记为已读”按钮(“标记为未读”)按钮,并且所选对话被标记为“已读” “(”未读“)只要点击后一个按钮,就应该如此。当在收件箱中选择另一个会话时,内容和属性仍然相应地改变,按钮的行为与先前点击的事件保持一致,例如, :

  1. Gmail加载后的第一个会话是读取对话 - >显示标记为未读按钮,单击后一个按钮后,所选对话将变为未读;
  2. 选择的第二个会话是未读的会话 - >标记为读取按钮是 显示(具有正确的“act”属性)但是一旦按钮是 点击,没有任何反应......按钮的“缓存”行为仍然存在 “标记为未读”!!
  3. 反之亦然。
  4. 任何想法/帮助表示赞赏!

    免责声明:请注意,我完全了解右键单击功能,键盘快捷键或“更多”菜单项以便标记读取Gmail中的未读对话。我希望实现此类功能的原因是由于我的Chrome扩展程序的用户提出了一些请求。

    [1]:Gmail实验室创建的按钮“标记为已读”...

    /* load at document_end (manifest.json) 
     * and wait for main Gmail frame to be loaded */
    
    $("#canvas_frame").ready(function() {
    
    // [...]
    
    function UnRead(elem) {
    
       // Select Gmail button "Mark as read"
       var readBtn = $('.Cq .m9.ar7');
    
         /* Change the behavior and content of the button 
          * depending on the state of the conversation selected. 
          * In Gmail, act = 2 : mark as unread | act = 1 : mark as read */
    
         if ( typeof elem !== 'undefined' && elem.match('yO') ) {
           readBtn.empty().attr('act', '2').wrapInner('Mark as unread');
         } else {
           readBtn.empty().attr('act', '1').wrapInner('Mark as read');
         }
    }
    
    /* Detect whether the user clicks on a conversation and call
     * UnRead fn with the class argument of the conversation. 
     * In Gmail, CSS class "zE" denotes an unread email while 
     * class "yO" denotes a read email. */
    
    $('.Cp tr').on('click', function() { UnRead($(this).attr('class')) });
    
    // [...]
    });
    

0 个答案:

没有答案