diff --git a/addCheckboxes.js b/addCheckboxes.js index 9c8ec2f..c784769 100644 --- a/addCheckboxes.js +++ b/addCheckboxes.js @@ -1,3 +1,5 @@ +console.log('addCheckboxes.js loaded'); + // 查找带有特定选择器的祖先元素 function findAncestorWithCheckbox(el, selector) { while ((el = el.parentElement) && !el.querySelector(selector)); @@ -6,6 +8,11 @@ function findAncestorWithCheckbox(el, selector) { // 切换复选框的选中状态 function toggleCheckbox(event) { + // 阻止事件的默认行为(例如链接跳转) + event.preventDefault(); + // 阻止事件冒泡到父元素 + event.stopPropagation(); + const parentElement = findAncestorWithCheckbox(event.currentTarget, `.${CHECKBOX_CLASS}`); const checkbox = parentElement ? parentElement.querySelector(`.${CHECKBOX_CLASS}`) : null; if (checkbox) { @@ -21,7 +28,8 @@ function preventEventPropagation(event) { // 添加复选框到每个对话 function addCheckboxes() { - const conversations = document.querySelectorAll(CONVERSATION_SELECTOR); + console.log('Adding checkboxes to conversations...', window.getSelectors(), isPlusUser()); + const conversations = document.querySelectorAll(window.getSelectors().CONVERSATION_SELECTOR); conversations.forEach((conversation, index) => { let existingCheckbox = conversation.querySelector(`.${CHECKBOX_CLASS}`); @@ -42,7 +50,7 @@ function addCheckboxes() { conversation.insertAdjacentElement('afterbegin', checkbox); // 为对话标题添加点击事件 - const titleElement = conversation.querySelector(TITLE_SELECTOR); + const titleElement = conversation.querySelector(window.getSelectors().TITLE_SELECTOR); if (titleElement) { titleElement.style.cursor = 'default'; if (!titleElement.dataset.hasClickListener) { // 检查是否已经添加了监听器 diff --git a/bulkDeleteConversations.js b/bulkDeleteConversations.js index 357243c..8b5cc70 100644 --- a/bulkDeleteConversations.js +++ b/bulkDeleteConversations.js @@ -1,3 +1,5 @@ +console.log('bulkDeleteConversations.js loaded'); + async function bulkDeleteConversations() { const selectedConversations = getSelectedConversations(); @@ -15,38 +17,50 @@ async function bulkDeleteConversations() { } function getSelectedConversations() { - return [...document.querySelectorAll(Selectors.conversationsCheckbox)]; + return [...document.querySelectorAll(window.getSelectors().conversationsCheckbox)]; } function removeAllCheckboxes() { - const allCheckboxes = document.querySelectorAll(Selectors.conversationsCheckbox); + const allCheckboxes = document.querySelectorAll(window.getSelectors().conversationsCheckbox); allCheckboxes.forEach(checkbox => checkbox.remove()); } async function deleteConversation(checkbox) { - const conversationElement = await checkbox.closest('.flex.p-3.items-center.gap-3.relative.rounded-md'); + const conversationElement = checkbox.parentElement; - console.log("1. Clicking conversation", conversationElement); + console.log("1. Clicking conversation...", conversationElement); conversationElement.click(); await delay(300); - const deleteButton = await waitForElement(Selectors.deleteButton); + const threeDotButton = conversationElement.parentElement.querySelector(window.getSelectors().threeDotButton); + await delay(500); + + console.log("2. Clicking three dot button...", conversationElement); + const pointerDownEvent = new PointerEvent('pointerdown', { + bubbles: true, + cancelable: true, + pointerType: 'mouse' + }); + + threeDotButton.dispatchEvent(pointerDownEvent); + + const deleteButton = await waitForElement(window.getSelectors().deleteButton); if (deleteButton) { - console.log("2. Clicking delete button", deleteButton); + console.log("3. Clicking delete button...", deleteButton); deleteButton.click(); - const confirmButton = await waitForElement(Selectors.confirmDeleteButton); + const confirmButton = await waitForElement(window.getSelectors().confirmDeleteButton); if (confirmButton) { - console.log("3. Clicking confirm button"); + console.log("4. Clicking confirm button..."); confirmButton.click(); - await waitForElementToDisappear(Selectors.confirmDeleteButton); + await waitForElementToDisappear(window.getSelectors().confirmDeleteButton); } } - console.log("4. Deletion completed"); + console.log("5. Deletion completed."); } async function waitForElement(selector, timeout = 2000) { diff --git a/globals.js b/globals.js index fce3b7e..918f66e 100644 --- a/globals.js +++ b/globals.js @@ -1,13 +1,39 @@ +console.log('globals.js loaded'); + let lastChecked = null; -const Selectors = { +const standardSelectors = { + // 标准用户的选择器 conversationsCheckbox: '.conversation-checkbox:checked', deleteButton: 'nav div a>div>button:nth-child(2)', confirmDeleteButton: 'button.btn.btn-danger', + threeDotButton: '[id^="radix-"]', + // 其他标准用户选择器... + CONVERSATION_SELECTOR: 'div div span div ol li>a.flex', + TITLE_SELECTOR: '.flex-1.text-ellipsis.max-h-5.overflow-hidden.break-all.relative', }; - -// 定义选择器和其他常量 -const CONVERSATION_SELECTOR = 'div div span div ol li>a.flex'; -const TITLE_SELECTOR = '.flex-1.text-ellipsis.max-h-5.overflow-hidden.break-all.relative'; -const CHECKBOX_CLASS = 'conversation-checkbox'; \ No newline at end of file +const plusSelectors = { + // Plus 用户的选择器 + conversationsCheckbox: '.conversation-checkbox:checked', + deleteButton: '[class*="text-red"]', + confirmDeleteButton: 'button.btn.btn-danger', + threeDotButton: '[id^="radix-"]', + // 其他 Plus 用户选择器... + CONVERSATION_SELECTOR: 'div > div > div > div > div > div > nav > div > div > div > span > div > ol > li > div > a', + TITLE_SELECTOR: '.relative.grow.overflow-hidden.whitespace-nowrap', +}; + +const CHECKBOX_CLASS = 'conversation-checkbox'; + +function isPlusUser() { + const spans = document.querySelectorAll('span.text-sm'); + return Array.from(spans).some(span => span.textContent.trim() === "Explore"); +} + +function getSelectors() { + return isPlusUser() ? plusSelectors : plusSelectors; +} + +// 暴露 getSelectors 函数到全局作用域 +window.getSelectors = getSelectors; \ No newline at end of file