Skip to content

Instantly share code, notes, and snippets.

@evaera
Last active April 22, 2024 22:01
Show Gist options
  • Save evaera/27892a020df7c6b35a56f91cdafc1a71 to your computer and use it in GitHub Desktop.
Save evaera/27892a020df7c6b35a56f91cdafc1a71 to your computer and use it in GitHub Desktop.
Tampermonkey script that automatically selects the next email in ProtonMail after archiving, deleting or spamming the current one.
// ==UserScript==
// @name Select next mail
// @namespace http://tampermonkey.net/
// @version 2024-04-22
// @description Automatically selects the next email in ProtonMail after archiving, deleting or spamming the current one.
// @author evaera
// @match *://mail.proton.me/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=proton.me
// @grant none
// ==/UserScript==
(function() {
'use strict';
const pattern = new RegExp("https://mail.proton.me/u/\\d+/[a-z]+/?$");
function selectNextItem() {
// Make sure something is still not selected, this function called be called multiple times on a delay
if (!pattern.test(location.href)) {
return
}
console.log("Select next item");
const parentContainer = document.querySelector(".items-column-list-container");
if (!parentContainer) {
setTimeout(() => {
selectNextItem()
}, 300);
return
};
const firstItem = parentContainer.querySelector('.item-container-wrapper');
if (firstItem) {
triggerEnterKey(firstItem);
}
}
function triggerEnterKey(element) {
const enterKeyEvent = new KeyboardEvent('keydown', {
key: 'Enter',
bubbles: true,
cancelable: true
});
element.dispatchEvent(enterKeyEvent);
}
let lastUrl;
new MutationObserver(() => {
const url = location.href;
if (url !== lastUrl) {
lastUrl = url;
if (pattern.test(url)) {
selectNextItem();
}
}
}).observe(document, {subtree: true, childList: true});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment