Files
kintone-helper-extenstion/background.js
2025-10-17 14:39:34 +08:00

43 lines
1.3 KiB
JavaScript

/**
* Injects the content scripts into the active tab to enable Kintone helper functionality
* @param {Object} tab - The active tab object from Chrome API
* @returns {Promise<void>} Resolves when all scripts are injected successfully
*/
const injectKintoneHelperScripts = async (tab) => {
const scriptFiles = ['fields.js', 'dom.js', 'main.js'];
try {
// Inject all scripts in parallel for better performance
await Promise.all(
scriptFiles.map(file =>
chrome.scripting.executeScript({
target: { tabId: tab.id },
files: [file],
world: 'MAIN',
})
)
);
console.log('Kintone helper scripts injected successfully');
} catch (error) {
console.error('Failed to inject Kintone helper scripts:', error);
throw error; // Re-throw to allow caller to handle if needed
}
};
/**
* Handles the extension action click event
* @param {Object} tab - The active tab that triggered the action
*/
const handleActionClick = async (tab) => {
try {
await injectKintoneHelperScripts(tab);
} catch (error) {
// Error already logged in injectKintoneHelperScripts
// Could add user notification here if needed
}
};
// Register the click handler for the browser action
chrome.action.onClicked.addListener(handleActionClick);