Skip to content

Instantly share code, notes, and snippets.

@apazzy
Forked from lyndsysimon/protonmail_archiver.js
Last active January 11, 2023 20:39
Show Gist options
  • Save apazzy/33af2c32e066ae8e6c0a9c224ebdf72b to your computer and use it in GitHub Desktop.
Save apazzy/33af2c32e066ae8e6c0a9c224ebdf72b to your computer and use it in GitHub Desktop.
Protonmail inbox cleaner
/* Protonmail cleanup scripts
* Works with ProtonMail v4.0.14 as of 2022-01-23
*
* Based on Lyndsy's Protonmail mass archiver:
* https://gist.github.com/lyndsysimon/e6a4a1becaddf09fe02c503793b545d6
*
* Usage:
* - Navigate to your inbox (or another folder/label, presumably)
* - Open your browser's developer tools' Javascript console
* - Paste in this script
* - Paste one of the below commented 'setInterval' commands
* based on need to start the script
* - Wait until the script finishes, it will run forever until
* the page is closed/refreshed
*
*
* setInterval(removeLabelMarkReadAndArchive, 4400);
* Remove the label selected in the navigation pane from all emails,
* mark the emails as read, and archive them.
*
* setInterval(markAsReadAndArchive, 2500);
* Mark all emails in a folder/label as read and then archive them.
*
* setInterval(markAllAsRead, 2500);
* Mark all Unread emails as read
*
*/
let viewAll = function() { $('button[data-testid="filter-dropdown:show-all"]').click() };
let viewUnread = function() { $('button[data-testid="filter-dropdown:show-unread"]').click() };
let viewRead = function() { $('button[data-testid="filter-dropdown:show-read"]').click() };
let markAsRead = function() { $('button[aria-describedby="tooltip-11"]').click() };
let selectAll = function() { $('span[aria-describedby="tooltip-8"] > label > input').click() };
let buttonArchive = function() { $('button[aria-describedby="tooltip-14"]').click() };
let viewLabelsMenu = function() {$('button[aria-describedby="tooltip-19"]').click() };
let labelMenuArchive = function() { $('input[data-testid="label-dropdown:also-archive"]').click() };
let applyLabel = function() { $("#dropdown-18 > div > form > div.m1:not(div.mb0) > button").click() };
let removeActiveLabel = function() {
var activeLabel = $(".navigation-item > .active").title
var labelCheckbox = `input[data-testid="label-dropdown:label-checkbox-${activeLabel}"]`
if($(labelCheckbox).checked){ // error check in case lable checkbox is not checked.
$(labelCheckbox).click()
}
};
// Only use the below function if removing multiple labels, otherwise use removeActiveLabel
// Replace "_LABEL_" with full label name, copy for as many labels as neede
/*
let removeLabels_LABEL_ = function() {
if($('input[data-testid="label-dropdown:label-checkbox-_LABEL_"]').checked) {
$('input[data-testid="label-dropdown:label-checkbox-_LABEL_:checked').click()
} else {
// If not checked (from filtering in a different view than the active label) check and uncheck to force removal
$('input[data-testid="label-dropdown:label-checkbox-_LABEL_"]:checked').click()
$('input[data-testid="label-dropdown:label-checkbox-_LABEL_"]:checked').click()
}
};
*/
function removeLabelMarkReadAndArchive() {
setTimeout(selectAll,400);
setTimeout(markAsRead,800);
setTimeout(viewLabelsMenu,900);
setTimeout(removeActiveLabel, 1700);
setTimeout(labelMenuArchive,1950);
setTimeout(applyLabel, 2400);
}
function markAsReadAndArchive() {
setTimeout(selectAll,400);
setTimeout(markAsRead, 1000);
setTimeout(buttonArchive, 1200);
}
function markAllAsRead() {
setTimeout(viewUnread,400);
setTimeout(selectAll,1000);
setTimeout(markAsRead, 1200);
setTimeout(viewRead,1700);
setTimeout(viewUnread,1900);
}
@lyndsysimon
Copy link

Thanks for updating this! Unfortunately, Protonmail broke it again...

I've forked your fork and fixed the functionality I needed (select all, mark as read, archive). That fork is here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment