skip unread conversation
This commit is contained in:
@@ -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,16 +81,20 @@ async function deleteConversation(checkbox) {
|
|||||||
conversationElement.dispatchEvent(hoverEvent);
|
conversationElement.dispatchEvent(hoverEvent);
|
||||||
await delay(200);
|
await delay(200);
|
||||||
|
|
||||||
|
// Try to find the three dot button
|
||||||
|
try {
|
||||||
|
const threeDotButton = await waitForElement(
|
||||||
|
Selectors.threeDotButton,
|
||||||
|
conversationElement.parentElement,
|
||||||
|
1000 // Reduced timeout for non-hoverable items
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log("2. Clicking three dot button...", threeDotButton);
|
||||||
const pointerDownEvent = new PointerEvent("pointerdown", {
|
const pointerDownEvent = new PointerEvent("pointerdown", {
|
||||||
bubbles: true,
|
bubbles: true,
|
||||||
cancelable: true,
|
cancelable: true,
|
||||||
pointerType: "mouse",
|
pointerType: "mouse",
|
||||||
});
|
});
|
||||||
const threeDotButton = await waitForElement(
|
|
||||||
Selectors.threeDotButton,
|
|
||||||
conversationElement.parentElement
|
|
||||||
);
|
|
||||||
console.log("2. Clicking three dot button...", threeDotButton);
|
|
||||||
threeDotButton.dispatchEvent(pointerDownEvent);
|
threeDotButton.dispatchEvent(pointerDownEvent);
|
||||||
await delay(300);
|
await delay(300);
|
||||||
|
|
||||||
@@ -72,19 +102,22 @@ async function deleteConversation(checkbox) {
|
|||||||
|
|
||||||
if (deleteButton) {
|
if (deleteButton) {
|
||||||
console.log("3. Clicking delete button...", deleteButton);
|
console.log("3. Clicking delete button...", deleteButton);
|
||||||
|
|
||||||
deleteButton.click();
|
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();
|
||||||
|
|||||||
Reference in New Issue
Block a user