Upload files to "/"
This commit is contained in:
49
background.js
Normal file
49
background.js
Normal file
@ -0,0 +1,49 @@
|
||||
// Extension initialization
|
||||
chrome.runtime.onInstalled.addListener(() => {
|
||||
console.log("Word Replacer Addon installed.");
|
||||
|
||||
// Set default replacements if they don't already exist
|
||||
chrome.storage.local.get('wordReplacements', (data) => {
|
||||
if (!data.wordReplacements) {
|
||||
chrome.storage.local.set({
|
||||
wordReplacements: {
|
||||
"oldWord1": "newWord1",
|
||||
"oldWord2": "newWord2",
|
||||
"oldWord3": "newWord3"
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Data cleanup when possible
|
||||
function cleanupStorageData() {
|
||||
chrome.storage.local.clear(() => {
|
||||
console.log("Extension storage cleared.");
|
||||
});
|
||||
}
|
||||
|
||||
// For Firefox we can use onSuspend which is called when the extension process
|
||||
// is terminated (can happen on deactivation or uninstallation)
|
||||
chrome.runtime.onSuspend.addListener(() => {
|
||||
console.log("Word Replacer Addon terminated.");
|
||||
// Uncomment the following line if you want to remove all data on suspension
|
||||
// cleanupStorageData();
|
||||
});
|
||||
|
||||
// Add a command to manually clean the data
|
||||
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
||||
if (message.action === 'getReplacements') {
|
||||
chrome.storage.local.get('wordReplacements', (data) => {
|
||||
sendResponse(data.wordReplacements || {});
|
||||
});
|
||||
return true; // Required for asynchronous sendResponse
|
||||
}
|
||||
|
||||
// New command to clean the data
|
||||
if (message.action === 'clearStorageData') {
|
||||
cleanupStorageData();
|
||||
sendResponse({success: true});
|
||||
return true;
|
||||
}
|
||||
});
|
Reference in New Issue
Block a user