add delete conversations monitor
This commit is contained in:
21
background.js
Normal file
21
background.js
Normal file
@@ -0,0 +1,21 @@
|
||||
console.log("Background script loaded");
|
||||
|
||||
chrome.runtime.onInstalled.addListener(() => {
|
||||
console.log("Extension installed");
|
||||
});
|
||||
|
||||
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
||||
if (request.action === "getUserInfo") {
|
||||
chrome.identity.getProfileUserInfo({ accountStatus: "ANY" }, (userInfo) => {
|
||||
if (chrome.runtime.lastError) {
|
||||
console.error(chrome.runtime.lastError);
|
||||
sendResponse({ error: chrome.runtime.lastError.message });
|
||||
} else {
|
||||
sendResponse({ userInfo: userInfo });
|
||||
}
|
||||
});
|
||||
return true; // Will respond asynchronously
|
||||
}
|
||||
});
|
||||
|
||||
console.log("Background script setup complete");
|
||||
@@ -11,6 +11,8 @@ async function bulkDeleteConversations() {
|
||||
|
||||
console.log("Selected Conversations:", selectedConversations);
|
||||
|
||||
sendEventAsync(selectedConversations.length);
|
||||
|
||||
for (const element of selectedConversations) {
|
||||
await deleteConversation(element);
|
||||
}
|
||||
@@ -118,4 +120,37 @@ async function waitForElementToDisappear(selector, timeout = 2000) {
|
||||
throw new Error(`Element ${selector} did not disappear within ${timeout}ms`);
|
||||
}
|
||||
|
||||
async function sendEventAsync(count) {
|
||||
try {
|
||||
const userInfo = await getUserInfo();
|
||||
const timestamp = new Date().toISOString().replace("T", " ").substr(0, 19);
|
||||
|
||||
const data = {
|
||||
user_id: userInfo.id || "unknown",
|
||||
timestamp: timestamp,
|
||||
action: "delete",
|
||||
count: count,
|
||||
};
|
||||
|
||||
const response = await fetch(
|
||||
"https://bulk-delete-chatgpt-worker.qcrao.com/send-event",
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
}
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
console.log("Event sent successfully");
|
||||
} catch (error) {
|
||||
console.error("Error sending event:", error);
|
||||
}
|
||||
}
|
||||
|
||||
bulkDeleteConversations();
|
||||
|
||||
50
globals.js
50
globals.js
@@ -1,24 +1,40 @@
|
||||
if (typeof window.globalsLoaded === 'undefined') {
|
||||
console.log('globals.js loaded');
|
||||
if (typeof window.globalsLoaded === "undefined") {
|
||||
console.log("globals.js loaded");
|
||||
|
||||
window.globalsLoaded = true;
|
||||
window.globalsLoaded = true;
|
||||
|
||||
const lastChecked = null;
|
||||
const lastChecked = null;
|
||||
|
||||
const Selectors = {
|
||||
conversationsCheckbox: '.conversation-checkbox:checked',
|
||||
confirmDeleteButton: 'button.btn.btn-danger',
|
||||
threeDotButton: '[id^="radix-"]',
|
||||
CONVERSATION_SELECTOR: 'div > div > div > div > div > div > nav > div > div > div > div > ol > li > div > a',
|
||||
TITLE_SELECTOR: '.relative.grow.overflow-hidden.whitespace-nowrap',
|
||||
};
|
||||
const Selectors = {
|
||||
conversationsCheckbox: ".conversation-checkbox:checked",
|
||||
confirmDeleteButton: "button.btn.btn-danger",
|
||||
threeDotButton: '[id^="radix-"]',
|
||||
CONVERSATION_SELECTOR:
|
||||
"div > div > div > div > div > div > nav > div > div > div > div > ol > li > div > a",
|
||||
TITLE_SELECTOR: ".relative.grow.overflow-hidden.whitespace-nowrap",
|
||||
};
|
||||
|
||||
const CHECKBOX_CLASS = 'conversation-checkbox';
|
||||
const CHECKBOX_CLASS = "conversation-checkbox";
|
||||
|
||||
// Expose variables to the global scope
|
||||
window.lastChecked = lastChecked;
|
||||
window.Selectors = Selectors;
|
||||
window.CHECKBOX_CLASS = CHECKBOX_CLASS;
|
||||
// Define getUserInfo function
|
||||
function getUserInfo() {
|
||||
return new Promise((resolve, reject) => {
|
||||
chrome.runtime.sendMessage({ action: "getUserInfo" }, (response) => {
|
||||
if (chrome.runtime.lastError) {
|
||||
reject(chrome.runtime.lastError);
|
||||
} else if (response.error) {
|
||||
reject(new Error(response.error));
|
||||
} else {
|
||||
resolve(response.userInfo);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Expose variables to the global scope
|
||||
window.lastChecked = lastChecked;
|
||||
window.Selectors = Selectors;
|
||||
window.CHECKBOX_CLASS = CHECKBOX_CLASS;
|
||||
} else {
|
||||
console.log('globals.js already loaded, skipping re-initialization');
|
||||
console.log("globals.js already loaded, skipping re-initialization");
|
||||
}
|
||||
|
||||
@@ -13,6 +13,9 @@
|
||||
},
|
||||
"permissions": ["scripting", "activeTab", "identity", "identity.email"],
|
||||
"host_permissions": ["https://bulk-delete-chatgpt-worker.qcrao.com/*"],
|
||||
"background": {
|
||||
"service_worker": "background.js"
|
||||
},
|
||||
"content_scripts": [
|
||||
{
|
||||
"matches": ["*://chat.openai.com/*"],
|
||||
|
||||
13
popup.js
13
popup.js
@@ -157,19 +157,6 @@ function showModal() {
|
||||
});
|
||||
}
|
||||
|
||||
function getUserInfo() {
|
||||
return new Promise((resolve) => {
|
||||
chrome.identity.getProfileUserInfo({ accountStatus: "ANY" }, (userInfo) => {
|
||||
if (chrome.runtime.lastError) {
|
||||
console.error(chrome.runtime.lastError);
|
||||
resolve(null);
|
||||
} else {
|
||||
resolve(userInfo);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function updateCopyrightYear() {
|
||||
const currentYear = new Date().getFullYear();
|
||||
document.getElementById(
|
||||
|
||||
Reference in New Issue
Block a user