-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathaddCheckboxes.js
More file actions
117 lines (95 loc) · 3.61 KB
/
addCheckboxes.js
File metadata and controls
117 lines (95 loc) · 3.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/**
* ChatGPT Bulk Delete - Add Checkboxes Operation
*
* This script adds checkboxes to all visible conversation items.
* It uses the CheckboxManager module for the actual implementation.
*/
(function() {
'use strict';
// Wait for core system to be ready
if (!window.ChatGPTBulkDelete || !window.ChatGPTBulkDelete.initialized) {
console.error('[AddCheckboxes] Core system not ready, deferring execution');
setTimeout(arguments.callee, 50);
return;
}
const core = window.ChatGPTBulkDelete;
const utils = core.utils;
utils.debug('AddCheckboxes script loaded');
/**
* Main function to add checkboxes to conversations
*/
function addCheckboxesToConversations() {
return core.executeOperation('addCheckboxes', () => {
utils.log('log', 'Starting checkbox addition operation');
// Check if history container exists
const history = utils.safeQuery(UI_CONFIG.SELECTORS.HISTORY);
if (!history) {
utils.log('log', 'History container not found, unable to add checkboxes');
return { success: false, reason: 'No history container found' };
}
// Get required modules
const CheckboxManager = core.getModule('CheckboxManager');
const DOMHandler = core.getModule('DOMHandler');
const EventHandler = core.getModule('EventHandler');
if (!CheckboxManager) {
throw new Error('CheckboxManager module not available');
}
if (!DOMHandler) {
throw new Error('DOMHandler module not available');
}
// Get all conversations
const conversations = DOMHandler.getAllConversations();
utils.log('log', `Found ${conversations.length} conversations to process`);
if (conversations.length === 0) {
return { success: true, processed: 0, message: 'No conversations found' };
}
// Process each conversation
let processedCount = 0;
let errorCount = 0;
conversations.forEach((conversation, index) => {
try {
// Add checkbox to conversation
CheckboxManager.addCheckboxToConversation(conversation, index);
// Setup interaction
CheckboxManager.setupConversationInteraction(conversation);
processedCount++;
} catch (error) {
errorCount++;
utils.log('error', `Failed to process conversation ${index}:`, error);
}
});
// Add keyboard event listeners if EventHandler is available
if (EventHandler && EventHandler.addKeyboardListeners) {
try {
EventHandler.addKeyboardListeners();
utils.debug('Keyboard event listeners added');
} catch (error) {
utils.log('error', 'Failed to add keyboard listeners:', error);
}
}
const result = {
success: errorCount === 0,
processed: processedCount,
errors: errorCount,
total: conversations.length
};
if (result.success) {
utils.log('log', `Successfully added checkboxes to ${processedCount} conversations`);
} else {
utils.log('error', `Added checkboxes with errors: ${processedCount} success, ${errorCount} errors`);
}
return result;
});
}
// Execute the operation
try {
addCheckboxesToConversations();
} catch (error) {
utils.log('error', 'Failed to execute addCheckboxes operation:', error);
// Show user notification if possible
const CommonUtils = core.getModule('CommonUtils');
if (CommonUtils && CommonUtils.showNotification) {
CommonUtils.showNotification(`Failed to add checkboxes: ${error.message}`, 'error');
}
}
})();