Skip to content

Instantly share code, notes, and snippets.

@yenson-lau
Last active May 26, 2023 03:08
Show Gist options
  • Save yenson-lau/3903603c2e534237b94e348d2c7c92d1 to your computer and use it in GitHub Desktop.
Save yenson-lau/3903603c2e534237b94e348d2c7c92d1 to your computer and use it in GitHub Desktop.
Send all mails in a ProtonMail search query to any folder of your choosing
function waitForElm(selector) {
return new Promise(resolve => {
if (document.querySelector(selector)) {
return resolve(document.querySelector(selector));
}
const observer = new MutationObserver(mutations => {
if ((document.querySelector(selector) !== undefined) &&
(document.querySelector(selector) !== null)) {
resolve(document.querySelector(selector));
observer.disconnect();
}
});
observer.observe(document.body, {
childList: true,
subtree: true
});
});
}
const folderPage = async function(folder) {
(await waitForElm(".item-container:not(.item-is-loading)")); // wait for messages to show up
(await waitForElm('#idSelectAll')).click();
(await waitForElm('[data-testid="toolbar:moveto"]')).click();
(await waitForElm('[data-testid="folder-dropdown:folder-'+folder+'"]')).click();
}
const folderEmails = async function (folder) {
await folderPage(folder);
var nextpage = await waitForElm('[data-testid="pagination-row:go-to-next-page"]');
while (!nextpage.disabled) {
nextpage.click();
await folderPage(folder);
nextpage = await waitForElm('[data-testid="pagination-row:go-to-next-page"]')
}
};
await folderEmails("Trash");
@yenson-lau
Copy link
Author

yenson-lau commented Aug 26, 2022

This is great. Can you figure out how to delete all my labels, too? :)

How many labels do you have? I don't have that many so I would probably just do it by hand.
But the key to this script is using waitForElm. If you want to delete all your labels you can just go the folders folder, keep calling waitForElm to get the next label, and delete it until all your labels are gone.

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