Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip starred messages when bulk archiving #84

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/components/BulkArchiveButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
* Create bulk archive button for archiving the given messages, which should be in the same bundle.
*/
function create(messages) {
return _create(() => _selectMessages(messages));
return _create(() => _selectUnstarredMessages(messages));
}

function _create(selectMessagesFunction) {
Expand Down Expand Up @@ -72,17 +72,23 @@ function _archiveMessages(selectMessagesFunction) {
}

/**
* Select all given messages.
* Select only messages without any stars assigned to them.
*/
function _selectMessages(messages) {
function _selectUnstarredMessages(messages) {
for (let i = messages.length - 1; i >= 0; i--) {
const checkboxNode = messages[i].querySelector(Selectors.MESSAGE_CHECKBOX);
if (!DomUtils.isChecked(checkboxNode)) {
const starred = _isStarred(messages[i]);
const checked = DomUtils.isChecked(checkboxNode);
if (starred && checked || !starred && !checked) {
checkboxNode.click();
}
}
}

function _isStarred(message) {
return !message.querySelector(Selectors.UNSTARRED);
}

function _isClickable(button) {
return getComputedStyle(button.parentNode).display !== 'none' &&
button.getAttribute('aria-disabled') !== 'true';
Expand Down
2 changes: 2 additions & 0 deletions src/util/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const GmailClasses = {
SUBJECT_CELL: 'a4W',
UNREAD: 'zE',
UNREAD_SENDER: 'zF',
UNSTARRED: 'aXw',
};

const InboxyClasses = {
Expand Down Expand Up @@ -88,6 +89,7 @@ const Selectors = {
SCROLLABLE_CONTAINER: '.Tm.aeJ',
SIDEPANE_TEXT: '.TO .nU',
STARRED: `.T-KT.${GmailClasses.STARRED}`,
UNSTARRED: `.T-KT.${GmailClasses.UNSTARRED}`,
TAB: `${MAIN} [role="tab"]`,
TABPANELS: `${MAIN} [role="tabpanel"]`,
TABLE_BODY: `.F tbody`,
Expand Down