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);
|
console.log("Selected Conversations:", selectedConversations);
|
||||||
|
|
||||||
|
sendEventAsync(selectedConversations.length);
|
||||||
|
|
||||||
for (const element of selectedConversations) {
|
for (const element of selectedConversations) {
|
||||||
await deleteConversation(element);
|
await deleteConversation(element);
|
||||||
}
|
}
|
||||||
@@ -118,4 +120,37 @@ async function waitForElementToDisappear(selector, timeout = 2000) {
|
|||||||
throw new Error(`Element ${selector} did not disappear within ${timeout}ms`);
|
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();
|
bulkDeleteConversations();
|
||||||
|
|||||||
32
globals.js
32
globals.js
@@ -1,24 +1,40 @@
|
|||||||
if (typeof window.globalsLoaded === 'undefined') {
|
if (typeof window.globalsLoaded === "undefined") {
|
||||||
console.log('globals.js loaded');
|
console.log("globals.js loaded");
|
||||||
|
|
||||||
window.globalsLoaded = true;
|
window.globalsLoaded = true;
|
||||||
|
|
||||||
const lastChecked = null;
|
const lastChecked = null;
|
||||||
|
|
||||||
const Selectors = {
|
const Selectors = {
|
||||||
conversationsCheckbox: '.conversation-checkbox:checked',
|
conversationsCheckbox: ".conversation-checkbox:checked",
|
||||||
confirmDeleteButton: 'button.btn.btn-danger',
|
confirmDeleteButton: "button.btn.btn-danger",
|
||||||
threeDotButton: '[id^="radix-"]',
|
threeDotButton: '[id^="radix-"]',
|
||||||
CONVERSATION_SELECTOR: 'div > div > div > div > div > div > nav > div > div > div > div > ol > li > div > a',
|
CONVERSATION_SELECTOR:
|
||||||
TITLE_SELECTOR: '.relative.grow.overflow-hidden.whitespace-nowrap',
|
"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";
|
||||||
|
|
||||||
|
// 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
|
// Expose variables to the global scope
|
||||||
window.lastChecked = lastChecked;
|
window.lastChecked = lastChecked;
|
||||||
window.Selectors = Selectors;
|
window.Selectors = Selectors;
|
||||||
window.CHECKBOX_CLASS = CHECKBOX_CLASS;
|
window.CHECKBOX_CLASS = CHECKBOX_CLASS;
|
||||||
} else {
|
} 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"],
|
"permissions": ["scripting", "activeTab", "identity", "identity.email"],
|
||||||
"host_permissions": ["https://bulk-delete-chatgpt-worker.qcrao.com/*"],
|
"host_permissions": ["https://bulk-delete-chatgpt-worker.qcrao.com/*"],
|
||||||
|
"background": {
|
||||||
|
"service_worker": "background.js"
|
||||||
|
},
|
||||||
"content_scripts": [
|
"content_scripts": [
|
||||||
{
|
{
|
||||||
"matches": ["*://chat.openai.com/*"],
|
"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() {
|
function updateCopyrightYear() {
|
||||||
const currentYear = new Date().getFullYear();
|
const currentYear = new Date().getFullYear();
|
||||||
document.getElementById(
|
document.getElementById(
|
||||||
|
|||||||
Reference in New Issue
Block a user