@@ -1,3 +1,5 @@
|
|||||||
|
console.log('addCheckboxes.js loaded');
|
||||||
|
|
||||||
// 查找带有特定选择器的祖先元素
|
// 查找带有特定选择器的祖先元素
|
||||||
function findAncestorWithCheckbox(el, selector) {
|
function findAncestorWithCheckbox(el, selector) {
|
||||||
while ((el = el.parentElement) && !el.querySelector(selector));
|
while ((el = el.parentElement) && !el.querySelector(selector));
|
||||||
@@ -6,6 +8,11 @@ function findAncestorWithCheckbox(el, selector) {
|
|||||||
|
|
||||||
// 切换复选框的选中状态
|
// 切换复选框的选中状态
|
||||||
function toggleCheckbox(event) {
|
function toggleCheckbox(event) {
|
||||||
|
// 阻止事件的默认行为(例如链接跳转)
|
||||||
|
event.preventDefault();
|
||||||
|
// 阻止事件冒泡到父元素
|
||||||
|
event.stopPropagation();
|
||||||
|
|
||||||
const parentElement = findAncestorWithCheckbox(event.currentTarget, `.${CHECKBOX_CLASS}`);
|
const parentElement = findAncestorWithCheckbox(event.currentTarget, `.${CHECKBOX_CLASS}`);
|
||||||
const checkbox = parentElement ? parentElement.querySelector(`.${CHECKBOX_CLASS}`) : null;
|
const checkbox = parentElement ? parentElement.querySelector(`.${CHECKBOX_CLASS}`) : null;
|
||||||
if (checkbox) {
|
if (checkbox) {
|
||||||
@@ -21,7 +28,8 @@ function preventEventPropagation(event) {
|
|||||||
|
|
||||||
// 添加复选框到每个对话
|
// 添加复选框到每个对话
|
||||||
function addCheckboxes() {
|
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) => {
|
conversations.forEach((conversation, index) => {
|
||||||
let existingCheckbox = conversation.querySelector(`.${CHECKBOX_CLASS}`);
|
let existingCheckbox = conversation.querySelector(`.${CHECKBOX_CLASS}`);
|
||||||
@@ -42,7 +50,7 @@ function addCheckboxes() {
|
|||||||
conversation.insertAdjacentElement('afterbegin', checkbox);
|
conversation.insertAdjacentElement('afterbegin', checkbox);
|
||||||
|
|
||||||
// 为对话标题添加点击事件
|
// 为对话标题添加点击事件
|
||||||
const titleElement = conversation.querySelector(TITLE_SELECTOR);
|
const titleElement = conversation.querySelector(window.getSelectors().TITLE_SELECTOR);
|
||||||
if (titleElement) {
|
if (titleElement) {
|
||||||
titleElement.style.cursor = 'default';
|
titleElement.style.cursor = 'default';
|
||||||
if (!titleElement.dataset.hasClickListener) { // 检查是否已经添加了监听器
|
if (!titleElement.dataset.hasClickListener) { // 检查是否已经添加了监听器
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
console.log('bulkDeleteConversations.js loaded');
|
||||||
|
|
||||||
async function bulkDeleteConversations() {
|
async function bulkDeleteConversations() {
|
||||||
const selectedConversations = getSelectedConversations();
|
const selectedConversations = getSelectedConversations();
|
||||||
|
|
||||||
@@ -15,38 +17,50 @@ async function bulkDeleteConversations() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getSelectedConversations() {
|
function getSelectedConversations() {
|
||||||
return [...document.querySelectorAll(Selectors.conversationsCheckbox)];
|
return [...document.querySelectorAll(window.getSelectors().conversationsCheckbox)];
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeAllCheckboxes() {
|
function removeAllCheckboxes() {
|
||||||
const allCheckboxes = document.querySelectorAll(Selectors.conversationsCheckbox);
|
const allCheckboxes = document.querySelectorAll(window.getSelectors().conversationsCheckbox);
|
||||||
allCheckboxes.forEach(checkbox => checkbox.remove());
|
allCheckboxes.forEach(checkbox => checkbox.remove());
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteConversation(checkbox) {
|
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();
|
conversationElement.click();
|
||||||
await delay(300);
|
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) {
|
if (deleteButton) {
|
||||||
console.log("2. 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(window.getSelectors().confirmDeleteButton);
|
||||||
|
|
||||||
if (confirmButton) {
|
if (confirmButton) {
|
||||||
console.log("3. Clicking confirm button");
|
console.log("4. Clicking confirm button...");
|
||||||
confirmButton.click();
|
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) {
|
async function waitForElement(selector, timeout = 2000) {
|
||||||
|
|||||||
34
globals.js
34
globals.js
@@ -1,13 +1,39 @@
|
|||||||
|
console.log('globals.js loaded');
|
||||||
|
|
||||||
let lastChecked = null;
|
let lastChecked = null;
|
||||||
|
|
||||||
const Selectors = {
|
const standardSelectors = {
|
||||||
|
// 标准用户的选择器
|
||||||
conversationsCheckbox: '.conversation-checkbox:checked',
|
conversationsCheckbox: '.conversation-checkbox:checked',
|
||||||
deleteButton: 'nav div a>div>button:nth-child(2)',
|
deleteButton: 'nav div a>div>button:nth-child(2)',
|
||||||
confirmDeleteButton: 'button.btn.btn-danger',
|
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 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 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';
|
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;
|
||||||
Reference in New Issue
Block a user