Files
bulk-delete-chatGPT/popup.js
Joseph Nahm c731c5316d Ensure globals.js is loaded prior to execution of dependent scripts
This commit prevents a race condition that causes global variables
defined in globals.js to be inaccessible to the other content scripts
2024-04-08 22:20:57 -07:00

38 lines
1.1 KiB
JavaScript

function loadGlobalsThenExecute(tabId, secondaryScript) {
chrome.scripting.executeScript({
target: { tabId: tabId },
files: ['globals.js']
}, () => {
chrome.scripting.executeScript({
target: { tabId: tabId },
files: [secondaryScript]
});
});
}
function addButtonListener(buttonId, scriptName) {
document.getElementById(buttonId).addEventListener('click', () => {
chrome.tabs.query({ active: true, currentWindow: true }, ([tab]) => {
if (tab) {
loadGlobalsThenExecute(tab.id, scriptName);
}
});
});
}
function initializeButtons() {
addButtonListener('add-checkboxes', 'addCheckboxes.js');
addButtonListener('bulk-delete', 'bulkDeleteConversations.js');
addButtonListener('toggle-checkboxes', 'toggleCheckboxes.js');
addButtonListener('remove-checkboxes', 'removeCheckboxes.js');
}
function updateCopyrightYear() {
const currentYear = new Date().getFullYear();
document.getElementById('copyright').innerHTML =
`&copy; ${currentYear} <a href="https://github.com/qcrao/bulk-delete-chatGPT" target="_blank">qcrao@GitHub</a>`;
}
initializeButtons();
updateCopyrightYear();