skip unread conversation

This commit is contained in:
qcrao
2024-11-13 17:37:28 +08:00
parent d5e6757d9a
commit 3aeb246deb

View File

@@ -1,7 +1,5 @@
console.log("bulkDeleteConversations.js loaded"); console.log("bulkDeleteConversations.js loaded");
console.log("bulkDeleteConversations.js loaded");
async function bulkDeleteConversations() { async function bulkDeleteConversations() {
const selectedConversations = getSelectedConversations(); const selectedConversations = getSelectedConversations();
@@ -14,10 +12,22 @@ async function bulkDeleteConversations() {
console.log("Selected Conversations:", selectedConversations.length); console.log("Selected Conversations:", selectedConversations.length);
// Send analytics event
sendEventAsync("delete", selectedConversations.length); sendEventAsync("delete", selectedConversations.length);
// Track how many conversations were actually processed
let processedCount = 0;
let skippedCount = 0;
for (let i = 0; i < selectedConversations.length; i++) { for (let i = 0; i < selectedConversations.length; i++) {
await deleteConversation(selectedConversations[i]); const result = await deleteConversation(selectedConversations[i]);
if (result) {
processedCount++;
} else {
skippedCount++;
}
// Calculate progress based on total attempts
const progress = Math.round(((i + 1) / selectedConversations.length) * 100); const progress = Math.round(((i + 1) / selectedConversations.length) * 100);
chrome.runtime.sendMessage({ chrome.runtime.sendMessage({
action: "updateProgress", action: "updateProgress",
@@ -26,6 +36,10 @@ async function bulkDeleteConversations() {
}); });
} }
console.log(
`Processed ${processedCount} conversations, skipped ${skippedCount} conversations`
);
chrome.runtime.sendMessage({ chrome.runtime.sendMessage({
action: "operationComplete", action: "operationComplete",
buttonId: "bulk-delete", buttonId: "bulk-delete",
@@ -45,6 +59,18 @@ async function deleteConversation(checkbox) {
await delay(100); await delay(100);
const conversationElement = checkbox.parentElement; const conversationElement = checkbox.parentElement;
console.log("conversationElement", conversationElement);
// Look for hoverable element within the conversation element
const hoverableDiv = conversationElement.querySelector(
"div.can-hover\\:group-hover\\:flex"
);
if (!hoverableDiv) {
console.log("Skipping conversation - no hoverable element found");
return false;
}
const hoverEvent = new MouseEvent("mouseover", { const hoverEvent = new MouseEvent("mouseover", {
view: window, view: window,
bubbles: true, bubbles: true,
@@ -55,36 +81,43 @@ async function deleteConversation(checkbox) {
conversationElement.dispatchEvent(hoverEvent); conversationElement.dispatchEvent(hoverEvent);
await delay(200); await delay(200);
const pointerDownEvent = new PointerEvent("pointerdown", { // Try to find the three dot button
bubbles: true, try {
cancelable: true, const threeDotButton = await waitForElement(
pointerType: "mouse", Selectors.threeDotButton,
}); conversationElement.parentElement,
const threeDotButton = await waitForElement( 1000 // Reduced timeout for non-hoverable items
Selectors.threeDotButton, );
conversationElement.parentElement
);
console.log("2. Clicking three dot button...", threeDotButton);
threeDotButton.dispatchEvent(pointerDownEvent);
await delay(300);
const deleteButton = await waitForDeleteButton(); console.log("2. Clicking three dot button...", threeDotButton);
const pointerDownEvent = new PointerEvent("pointerdown", {
bubbles: true,
cancelable: true,
pointerType: "mouse",
});
threeDotButton.dispatchEvent(pointerDownEvent);
await delay(300);
if (deleteButton) { const deleteButton = await waitForDeleteButton();
console.log("3. Clicking delete button...", deleteButton);
deleteButton.click(); if (deleteButton) {
console.log("3. Clicking delete button...", deleteButton);
deleteButton.click();
const confirmButton = await waitForElement(Selectors.confirmDeleteButton); const confirmButton = await waitForElement(Selectors.confirmDeleteButton);
if (confirmButton) { if (confirmButton) {
console.log("4. Clicking confirm button..."); console.log("4. Clicking confirm button...");
confirmButton.click(); confirmButton.click();
await waitForElementToDisappear(Selectors.confirmDeleteButton);
await waitForElementToDisappear(Selectors.confirmDeleteButton); return true;
}
} }
} catch (error) {
console.log("Could not complete deletion process:", error);
return false;
} }
console.log("5. Deletion completed."); return false;
} }
async function waitForDeleteButton(parent = document, timeout = 2000) { async function waitForDeleteButton(parent = document, timeout = 2000) {
@@ -134,4 +167,5 @@ async function waitForElementToDisappear(selector, timeout = 2000) {
throw new Error(`Element ${selector} did not disappear within ${timeout}ms`); throw new Error(`Element ${selector} did not disappear within ${timeout}ms`);
} }
// Start the bulk delete process
bulkDeleteConversations(); bulkDeleteConversations();