refactor add checkbox logic
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -13,4 +13,6 @@
|
|||||||
|
|
||||||
# Dependency directories (remove the comment below to include it)
|
# Dependency directories (remove the comment below to include it)
|
||||||
# vendor/
|
# vendor/
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
|
.idea
|
||||||
@@ -1,32 +1,36 @@
|
|||||||
|
function toggleCheckbox(event) {
|
||||||
|
// 从标题元素获取其前一个兄弟元素,即复选框
|
||||||
|
const checkbox = event.currentTarget.parentElement.querySelector('.conversation-checkbox');
|
||||||
|
if (checkbox && checkbox.type === 'checkbox') {
|
||||||
|
checkbox.checked = !checkbox.checked;
|
||||||
|
}
|
||||||
|
event.stopPropagation();
|
||||||
|
}
|
||||||
|
|
||||||
|
function preventEventPropagation(event) {
|
||||||
|
event.stopPropagation();
|
||||||
|
}
|
||||||
|
|
||||||
function addCheckboxes() {
|
function addCheckboxes() {
|
||||||
const conversations = document.querySelectorAll('.flex.py-3.px-3.items-center.gap-3.relative.rounded-md');
|
const conversationSelectors = '.flex.py-3.px-3.items-center.gap-3.relative.rounded-md';
|
||||||
|
const titleSelectors = '.flex-1.text-ellipsis.max-h-5.overflow-hidden.break-all.relative';
|
||||||
conversations.forEach((conversation, index) => {
|
const conversations = document.querySelectorAll(conversationSelectors);
|
||||||
|
|
||||||
|
for (const [index, conversation] of conversations.entries()) {
|
||||||
const checkbox = document.createElement('input');
|
const checkbox = document.createElement('input');
|
||||||
checkbox.type = 'checkbox';
|
checkbox.type = 'checkbox';
|
||||||
checkbox.className = 'conversation-checkbox';
|
checkbox.className = 'conversation-checkbox';
|
||||||
checkbox.dataset.index = index;
|
checkbox.dataset.index = index;
|
||||||
|
|
||||||
conversation.insertAdjacentElement('afterbegin', checkbox);
|
conversation.insertAdjacentElement('afterbegin', checkbox);
|
||||||
|
|
||||||
// Add click event listener to the conversation title
|
const titleElement = conversation.querySelector(titleSelectors);
|
||||||
const titleElement = conversation.querySelector('.flex-1.text-ellipsis.max-h-5.overflow-hidden.break-all.relative');
|
|
||||||
if (titleElement) {
|
if (titleElement) {
|
||||||
titleElement.style.cursor = 'default'; // Ensure the cursor is the default arrow pointer
|
titleElement.style.cursor = 'default';
|
||||||
titleElement.addEventListener('click', function(event) {
|
titleElement.addEventListener('click', toggleCheckbox);
|
||||||
// Toggle the checkbox state
|
checkbox.addEventListener('click', preventEventPropagation);
|
||||||
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();
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ 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(2)'); // Updated delete button selector
|
const deleteButton = document.querySelector('.absolute.flex.right-1.z-10.text-gray-300.visible button:nth-child(3)'); // Updated delete button selector
|
||||||
|
|
||||||
if (deleteButton) {
|
if (deleteButton) {
|
||||||
console.log("点击删除按钮1...")
|
console.log("点击删除按钮1...")
|
||||||
|
|||||||
Reference in New Issue
Block a user