fix delete button

This commit is contained in:
qcrao
2024-05-04 17:23:27 +08:00
parent 8c2fcc9f52
commit 2856b3a3e4
3 changed files with 23 additions and 3 deletions

View File

@@ -54,7 +54,7 @@ async function deleteConversation(checkbox) {
await delay(300);
console.log("2. Clicking three dot button...", threeDotButton);
const deleteButton = await waitForElement(Selectors.deleteButton);
const deleteButton = await waitForDeleteButton();
if (deleteButton) {
console.log("3. Clicking delete button...", deleteButton);
@@ -73,6 +73,27 @@ async function deleteConversation(checkbox) {
console.log("5. Deletion completed.");
}
async function waitForDeleteButton(parent = document, timeout = 2000) {
const selector = 'div[role="menuitem"]'; // 设定好选择器
const textContent = "Delete chat"; // 指定文本内容
const startedAt = Date.now();
while ((Date.now() - startedAt) < timeout) {
const elements = parent.querySelectorAll(selector);
const element = Array.from(elements).find(el => el.textContent.trim() === textContent);
if (element) return element; // 返回找到的元素
await delay(100);
}
console.log(`Delete button not found within ${timeout}ms`);
throw new Error(`Delete button not found within ${timeout}ms`);
}
// Helper function to create a delay
function delay(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function waitForElement(selector, parent = document, timeout = 2000) {
const startedAt = Date.now();
while ((Date.now() - startedAt) < timeout) {

View File

@@ -8,7 +8,6 @@ if (typeof window.globalsLoaded === 'undefined') {
let Selectors = {
// Plus 用户的选择器
conversationsCheckbox: '.conversation-checkbox:checked',
deleteButton: '[class*="text-red"]',
confirmDeleteButton: 'button.btn.btn-danger',
threeDotButton: '[id^="radix-"]',
// 其他 Plus 用户选择器...

View File

@@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "ChatGPT Bulk Delete",
"version": "4.3",
"version": "4.4",
"description": "A Chrome extension to bulk delete ChatGPT conversations",
"icons": {
"48": "icon48.png"