Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6568001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:24:13+00:00 2026-05-25T14:24:13+00:00

In Gmail, clicking on the checkbox shown below selects all messages and I’m making

  • 0

In Gmail, clicking on the checkbox shown below selects all messages and I’m making a userscript (for personal use and I need it to work in Chrome) that’ll select the unread messages only (only the first 2 messages in the screenie below are unread) instead of the default behavior of that checkbox.

enter image description here

My first idea is to simulate click events and although I could access the “unread” menuitem fine using the code…

var unread_menuitem = document.getElementById('canvas_frame').contentWindow.document.getElementById(':s2');
$(unread_menuitem).css({'border':'thin red solid'});

enter image description here

and dispatch the click event to it using the code…

var clickEvent = document.createEvent('MouseEvents');
clickEvent.initEvent( 'click', true, true );
unread_menuitem.dispatchEvent(clickEvent); // Chrome's console returned 'true'

the unread messages don’t get selected.


My second idea was to brute force the selection by checking the checkbox $('#canvas_frame').contents().find('tr.zE input').prop('checked', true) and apply the css styles that Gmail applies on a manual click event, but while I was able to match the manual click event both visually as well as DOM-wise (afaik)…

enter image description here

Gmail says “No conversations selected” while performing some action, in this case I did a “Mark as Read”. I also want to note that manually clicking on the checkboxes that were put in this state using my brute force method did not “uncheck” them as you’d expect. They needed one additional manual click to get unchecked.

enter image description here

Both my ideas have bombed and I want to know if there are others ways to tackle this, or if there are ways to improve upon my ideas above that can solve the problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T14:24:14+00:00Added an answer on May 25, 2026 at 2:24 pm

    Solved it, easy as pie and now that I think about it, it’s the solution listed in user PirateKitten’s answer – instead of “checking off” the checkboxes besides the unread messages like my second idea, simulate clicks on those checkboxes instead. Works like a charm and here’s the code, which you can run in Chrome’s console while using Gmail (doesn’t need jQuery btw):

    var unreadMessages = document.getElementById('canvas_frame').contentWindow.document.querySelectorAll('tr.zE input');
    var numMessages = unreadMessages.length;
    while ( numMessages-- ) {
        var clickEvent = document.createEvent('MouseEvents');
        clickEvent.initEvent( 'click', true, true );
        unreadMessages[numMessages].dispatchEvent(clickEvent); 
    }
    

    Here’s my full script that you can run inside your Chrome console (or turn it into an extension/userscript) to change the default behavior of the checkbox from selecting ALL messages to just the unread messages only:

    var hasUILoaded = setInterval( function() {
        if( document.getElementById('canvas_frame').contentDocument.getElementsByClassName('J-Zh-I J-J5-Ji J-Pm-I L3') ) {
            clearInterval( hasUILoaded );
            setTimeout( function() {
                var content_frame = document.getElementById('canvas_frame').contentDocument;
                var chkbox = content_frame.getElementsByClassName( 'J-Zh-I J-J5-Ji J-Pm-I L3' );
                var chkbox = chkbox[0].childNodes[0];
                var unreadMessages = content_frame.getElementsByClassName('zE'); // DOM structure: <tr class=zE> <td> <img><input> </td> </tr> so we add ".childNodes[0].childNodes[1]" whenever we want to access the check boxes of each message.
                var allMessages = content_frame.getElementsByClassName('zA');            
    
                chkbox.onclick = function() {
                    if( chkbox.checked ) {
                        var numUnread = unreadMessages.length;;
                        var numAll  = allMessages.length;
                        setTimeout(function () { 
                            if( allMessages[0].childNodes[0].childNodes[1].checked ) { 
                                while ( numAll-- ) {
                                    var clickEvent = document.createEvent('MouseEvents');
                                    clickEvent.initEvent( 'click', true, true ); 
                                allMessages[numAll].childNodes[0].childNodes[1].dispatchEvent(clickEvent);       
                                }
                            }
                        }, 10);
    
                        setTimeout(function (){
                            if(!unreadMessages[0].childNodes[0].childNodes[1].checked) {
                                while ( numUnread-- ) {
                                    var clickEvent = document.createEvent('MouseEvents');
                                    clickEvent.initEvent( 'click', true, true ); 
                    unreadMessages[numUnread].childNodes[0].childNodes[1].dispatchEvent(clickEvent);  
                                }
                            }
                        }, 30);
                    }
                }
            }, 100);
        }
    }, 300);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Gmail, I have a bunch of labeled messages. I'd like to use an
I'm using gmail from work, but I need to enter a password for a
All Gmail users should have already noticed that file upload progress bar has been
If you use Gmail, you'll see URLs in the address bar like: https://mail.google.com/mail/#inbox https://mail.google.com/mail/#starred
I've noticed that Gmail, Hotmail, Yahoo, and Ebay all have their login boxes on
Sniffing gmail's Print all link source code, there's something like this: <script> function Print(){document.body.offsetHeight;window.print()};
my gmail is zjm1126@gmail.com i can only use zjm1126@gmail.com in the sender=.. ,yes ??
I want to intercept clicking over url. For example: In my GMAIL I have
My gmail is getting full... I need a method to find out the biggest
I am wondering what Gmail APIs one would use to read, move or delete

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.