fix: do not work after openai updates
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -13,3 +13,4 @@
|
||||
|
||||
# Dependency directories (remove the comment below to include it)
|
||||
# vendor/
|
||||
.DS_Store
|
||||
@@ -1,21 +1,32 @@
|
||||
function addCheckboxes() {
|
||||
const conversations = document.querySelectorAll(
|
||||
'.flex.py-3.px-3.items-center.gap-3.relative.rounded-md'
|
||||
);
|
||||
const conversations = document.querySelectorAll('.flex.py-3.px-3.items-center.gap-3.relative.rounded-md');
|
||||
|
||||
conversations.forEach((conversation, index) => {
|
||||
const existingCheckbox = conversation.querySelector('.conversation-checkbox');
|
||||
if (!existingCheckbox) {
|
||||
const checkbox = document.createElement('input');
|
||||
checkbox.type = 'checkbox';
|
||||
checkbox.className = 'conversation-checkbox';
|
||||
checkbox.dataset.index = index; // 设置 data-index 属性
|
||||
checkbox.addEventListener('click', (e) => {
|
||||
e.stopPropagation();
|
||||
checkbox.dataset.index = index;
|
||||
|
||||
conversation.insertAdjacentElement('afterbegin', checkbox);
|
||||
|
||||
// Add click event listener to the conversation title
|
||||
const titleElement = conversation.querySelector('.flex-1.text-ellipsis.max-h-5.overflow-hidden.break-all.relative');
|
||||
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();
|
||||
});
|
||||
conversation.insertBefore(checkbox, conversation.firstChild);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
addCheckboxes();
|
||||
|
||||
@@ -13,39 +13,16 @@ async function bulkDeleteConversations() {
|
||||
return;
|
||||
}
|
||||
|
||||
const waitForElement = (selector, timeout = 5000) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const element = document.querySelector(selector);
|
||||
if (element) {
|
||||
resolve(element);
|
||||
async function waitForElement(selector, timeout = 5000) {
|
||||
const startedAt = Date.now();
|
||||
let el = null;
|
||||
while ((Date.now() - startedAt) < timeout) {
|
||||
el = document.querySelector(selector);
|
||||
if (el) return el;
|
||||
await new Promise(r => setTimeout(r, 100));
|
||||
}
|
||||
|
||||
const observer = new MutationObserver((mutations) => {
|
||||
mutations.forEach((mutation) => {
|
||||
if (!mutation.addedNodes) return;
|
||||
|
||||
for (const node of mutation.addedNodes) {
|
||||
if (node.matches && node.matches(selector)) {
|
||||
observer.disconnect();
|
||||
resolve(node);
|
||||
return;
|
||||
throw new Error(`Element ${selector} not found within ${timeout}ms`);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
setTimeout(() => {
|
||||
observer.disconnect();
|
||||
reject(new Error('Element not found.'));
|
||||
}, timeout);
|
||||
|
||||
observer.observe(document.body, {
|
||||
childList: true,
|
||||
subtree: true
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
console.log("开始删除...")
|
||||
const checkbox = conversationCheckboxes[0];
|
||||
@@ -55,14 +32,18 @@ async function bulkDeleteConversations() {
|
||||
conversationElement.click(); // Click the conversation first
|
||||
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) {
|
||||
console.log("点击删除按钮...")
|
||||
console.log("点击删除按钮1...")
|
||||
deleteButton.click(); // Click the delete button
|
||||
await waitForElement('.absolute.flex.right-1.z-10.text-gray-300.visible');
|
||||
const buttonsContainer = document.querySelector('.absolute.flex.right-1.z-10.text-gray-300.visible');
|
||||
const confirmButton = buttonsContainer.querySelector('button:nth-child(1)'); // Get the first button as confirm button
|
||||
console.log("点击删除按钮2...")
|
||||
await waitForElement('div[role="dialog"][data-state="open"] button.btn-danger');
|
||||
|
||||
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) {
|
||||
console.log("点击确认按钮...")
|
||||
confirmButton.click();
|
||||
@@ -70,7 +51,7 @@ async function bulkDeleteConversations() {
|
||||
// 等待删除按钮消失
|
||||
const deleteButtonDisappeared = new Promise((resolve) => {
|
||||
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();
|
||||
resolve();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user