Last active
February 22, 2022 15:21
-
-
Save vict0rsch/365b3e2b1aee8b634579d4001aaf103c to your computer and use it in GitHub Desktop.
Protonmail bulk "mark as read" and "move to trash" workarounds
This file contains hidden or 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
| /** | |
| * | |
| * @param {string} testId The string id for the element to find, | |
| * matchec against elements' `data-testid` attribute. | |
| * @returns HTML element | |
| */ | |
| const getFromTestId = (testId) => { | |
| return Array.from(document.getElementsByTagName("button")).filter( | |
| (element) => element.getAttribute("data-testid") === testId | |
| )[0]; | |
| }; | |
| /** | |
| * Get the element to select all the emails on this page. | |
| * @returns HTML element | |
| */ | |
| const all = () => document.getElementById("idSelectAll"); | |
| /** | |
| * Get the element to mark all the emails on this page as "read". | |
| * @returns HTML element | |
| */ | |
| const read = () => getFromTestId("toolbar:read"); | |
| /** | |
| * Get the element to go to the next page. | |
| * @returns HTML element | |
| */ | |
| const next = () => getFromTestId("pagination-row:go-to-next-page"); | |
| /** | |
| * Perform 1 iteration of selectAll-markAsRead-goToNextPage. | |
| * @param {number} clickTime The time to wait between button clicks. | |
| * @param {number} interval The interval id to clear if there's no next page. | |
| */ | |
| const allAsReadAndNext = (clickTime, interval) => () => { | |
| all().click(); | |
| setTimeout(() => { | |
| read().click(); | |
| setTimeout(() => { | |
| const nextElement = next(); | |
| nextElement ? nextElement.click() : clearInterval(interval); | |
| }, clickTime); | |
| }, clickTime); | |
| }; | |
| /** | |
| * | |
| * @param {number} clickTime The time to wait between button clicks. | |
| * @param {number} loadingTime The time to wait for a single page to load, i.e. | |
| * the time between calls to allAsReadAndNext() | |
| * @returns interval id | |
| */ | |
| const start = (clickTime, loadingTime) => { | |
| var interval = null; | |
| interval = setInterval(allAsReadAndNext(clickTime, interval), loadingTime); | |
| return interval; | |
| }; | |
| // The time to wait between button clicks. | |
| const clickTime = 200; | |
| // The time to wait for a single page to load, i.e. the time between calls to allAsReadAndNext() | |
| const loadingTime = 4000; | |
| // Start the bulk mark as read process. | |
| const intervalId = start(clickTime, loadingTime); | |
| // clearInterval(intervalId); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to use
ctrl/cmd+i)Execution logic
action)loadingTime)Stopping
clearInterval(interval)in the consoleCustomization
loadingTimeis the time the code will wait after clicking the "Next" button. Increase if your internet is sloweractionis the action to perform: it can be either"markAsRead"or"moveToTrash"