linkedin message delete
/**
* UI changed - process to manage messages
* Select the ... button that open sub menu for managing messages
* Open sub menu
* Wait for the LinkedIn UI to catch up
* Find "link" that toggles manage messages
* Click the "link" to manage messages
*/
const manageMessages = async () => {
const openMessageMenu = document.querySelector(
".msg-conversations-container__title-row button"
);
console.log('Attempting to open messaging menu');
openMessageMenu.click();
setTimeout(() => {
const manageConversations = document.querySelector(
".msg-conversations-container__dropdown-container ul div"
);
console.log('Attempting to enable message management');
manageConversations.click();
}, 1000);
};
const delMsgs = async () => {
await manageMessages();
const container = document.querySelector(
".msg-conversations-container__conversations-list"
);
if (!container) {
console.log("no messages - are you on the messages page?");
return;
}
const loadAllMessages = async () => {
return await new Promise((resolve) => {
let height = 0;
let attempts = 0;
if (container) {
console.log("loading messages...");
const interval = setInterval(() => {
const { scrollHeight } = container;
if (scrollHeight > 20000) {
console.log("limited to around 200 messages...");
clearInterval(interval);
resolve();
}
if (scrollHeight === height) {
if (attempts >= 3) {
console.log("messages loaded...");
clearInterval(interval);
resolve();
} else {
console.log("...");
attempts++;
}
}
height = scrollHeight;
container.scrollTop = scrollHeight;
}, 1000);
} else {
console.log("no messages");
}
});
};
await loadAllMessages();
console.log("attempting to select all messages");
const labels = container.getElementsByTagName("label");
for (let i = 0; i < labels.length; i++) {
if (labels[i]) {
labels[i].click();
}
}
console.log("Click the trash can icon at the top to delete all messages.");
console.log('type "delMsgs()" below this and then hit enter to run again.');
};
delMsgs();