Hack #61. Warn Before Replying to Multiple Recipients in Gmail

Don't embarrass yourself by sending private replies to everyone.

Using any email program, it's all too easy to accidentally hit the Reply All button and end up saying something to a large group that was meant for just one person. But the problem isn't limited to the Reply All button. If there are multiple people in the To: list, it's even easier to accidentally reply to them all, because the Reply button replies to everyone by default.

The Code

This user script runs in the Compose frame of Gmail, which can be identified by its query string parameter view=cv.

Tip

Use the View Frame Info menu command in the context menu to see the URL of a <frame> or <iframe>.

The script uses the following algorithm to detect a possible reply-all snafu:

  1. Listen for all click events on the page by using document.addEventListener.

  2. If the click event originated from a Send button, check the number of recipients. Recipients are usually separated by a comma followed by a space, but since you can type any amount of space around the comma, this script uses a regular expression.

  3. If there is more than one recipient, warn the user.

  4. If the user decides not to proceed, cancel the form submission. The script accomplishes this by calling the event object's stopPropagation method, which prevents the event from bubbling up to the <form> element where it would submit the form and send the message.

Tip

You can use addEventListener at any level in the document tree. ...

Get Greasemonkey Hacks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.