Last active
May 26, 2023 03:08
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
This is great. Can you figure out how to delete all my labels, too? :)
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
To use the script do the following:
data-test-id="folder-dropdown:folder-<foldername>"
to get the<foldername>
To delete everything in Trash: go to Trash and click Delete All. (It is hidden under More Options on the control panel.)
Update 2022-08-06: Made the code robust to loading times and can move to any folder.