fix: do not work after openai updates

This commit is contained in:
qcrao
2023-08-21 23:48:19 +08:00
parent 7f7fed5e85
commit 186afaaa6b
3 changed files with 52 additions and 59 deletions

1
.gitignore vendored
View File

@@ -13,3 +13,4 @@
# Dependency directories (remove the comment below to include it) # Dependency directories (remove the comment below to include it)
# vendor/ # vendor/
.DS_Store

View File

@@ -1,21 +1,32 @@
function addCheckboxes() { function addCheckboxes() {
const conversations = document.querySelectorAll( const conversations = document.querySelectorAll('.flex.py-3.px-3.items-center.gap-3.relative.rounded-md');
'.flex.py-3.px-3.items-center.gap-3.relative.rounded-md'
);
conversations.forEach((conversation, index) => { conversations.forEach((conversation, index) => {
const existingCheckbox = conversation.querySelector('.conversation-checkbox'); const checkbox = document.createElement('input');
if (!existingCheckbox) { checkbox.type = 'checkbox';
const checkbox = document.createElement('input'); checkbox.className = 'conversation-checkbox';
checkbox.type = 'checkbox'; checkbox.dataset.index = index;
checkbox.className = 'conversation-checkbox';
checkbox.dataset.index = index; // 设置 data-index 属性 conversation.insertAdjacentElement('afterbegin', checkbox);
checkbox.addEventListener('click', (e) => {
e.stopPropagation(); // Add click event listener to the conversation title
}); const titleElement = conversation.querySelector('.flex-1.text-ellipsis.max-h-5.overflow-hidden.break-all.relative');
conversation.insertBefore(checkbox, conversation.firstChild); if (titleElement) {
} titleElement.style.cursor = 'default'; // Ensure the cursor is the default arrow pointer
}); titleElement.addEventListener('click', function(event) {
} // Toggle the checkbox state
checkbox.checked = !checkbox.checked;
// Prevent the event from propagating further
event.stopPropagation();
});
// Ensure the checkbox click doesn't trigger the title's click event
checkbox.addEventListener('click', function(event) {
event.stopPropagation();
});
}
});
}
addCheckboxes();
addCheckboxes();

View File

@@ -13,39 +13,16 @@ async function bulkDeleteConversations() {
return; return;
} }
const waitForElement = (selector, timeout = 5000) => { async function waitForElement(selector, timeout = 5000) {
return new Promise((resolve, reject) => { const startedAt = Date.now();
const element = document.querySelector(selector); let el = null;
if (element) { while ((Date.now() - startedAt) < timeout) {
resolve(element); el = document.querySelector(selector);
} if (el) return el;
await new Promise(r => setTimeout(r, 100));
const observer = new MutationObserver((mutations) => { }
mutations.forEach((mutation) => { throw new Error(`Element ${selector} not found within ${timeout}ms`);
if (!mutation.addedNodes) return; }
for (const node of mutation.addedNodes) {
if (node.matches && node.matches(selector)) {
observer.disconnect();
resolve(node);
return;
}
}
});
});
setTimeout(() => {
observer.disconnect();
reject(new Error('Element not found.'));
}, timeout);
observer.observe(document.body, {
childList: true,
subtree: true
});
});
};
console.log("开始删除...") console.log("开始删除...")
const checkbox = conversationCheckboxes[0]; const checkbox = conversationCheckboxes[0];
@@ -55,14 +32,18 @@ async function bulkDeleteConversations() {
conversationElement.click(); // Click the conversation first conversationElement.click(); // Click the conversation first
await new Promise(resolve => setTimeout(resolve, 500)); // Add a delay of 0.5 second await new Promise(resolve => setTimeout(resolve, 500)); // Add a delay of 0.5 second
const deleteButton = document.querySelector('.absolute.flex.right-1.z-10.text-gray-300.visible button:nth-child(3)'); // Updated delete button selector const deleteButton = document.querySelector('.absolute.flex.right-1.z-10.text-gray-300.visible button:nth-child(2)'); // Updated delete button selector
if (deleteButton) { if (deleteButton) {
console.log("点击删除按钮...") console.log("点击删除按钮1...")
deleteButton.click(); // Click the delete button deleteButton.click(); // Click the delete button
await waitForElement('.absolute.flex.right-1.z-10.text-gray-300.visible'); console.log("点击删除按钮2...")
const buttonsContainer = document.querySelector('.absolute.flex.right-1.z-10.text-gray-300.visible'); await waitForElement('div[role="dialog"][data-state="open"] button.btn-danger');
const confirmButton = buttonsContainer.querySelector('button:nth-child(1)'); // Get the first button as confirm button
console.log("点击删除按钮3...")
// const buttonsContainer = document.querySelector('mt-5 flex flex-col gap-3 sm:mt-4 sm:flex-row-reverse');
const confirmButton = document.querySelector('button.btn.btn-danger');
if (confirmButton) { if (confirmButton) {
console.log("点击确认按钮...") console.log("点击确认按钮...")
confirmButton.click(); confirmButton.click();
@@ -70,7 +51,7 @@ async function bulkDeleteConversations() {
// 等待删除按钮消失 // 等待删除按钮消失
const deleteButtonDisappeared = new Promise((resolve) => { const deleteButtonDisappeared = new Promise((resolve) => {
const observer = new MutationObserver(() => { const observer = new MutationObserver(() => {
if (!document.querySelector('.absolute.flex.right-1.z-10.text-gray-300.visible')) { if (!document.querySelector('button.btn.btn-danger')) {
observer.disconnect(); observer.disconnect();
resolve(); resolve();
} }