diff --git a/background.js b/background.js new file mode 100644 index 0000000..d6adb05 --- /dev/null +++ b/background.js @@ -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; + } +}); \ No newline at end of file diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..68e541e --- /dev/null +++ b/manifest.json @@ -0,0 +1,52 @@ +{ + "manifest_version": 2, + "name": "Word Replacer", + "version": "1.0.0", + "description": "Replaces specific words in web pages with customizable alternatives.", + "author": "krypt77", + "homepage_url": "https://gitea.it/krypt77/Firefox-Word-Replacer-Addon", + + "permissions": [ + "activeTab", + "storage", + "tabs" + ], + + "background": { + "scripts": ["background.js"], + "persistent": false + }, + + "content_scripts": [ + { + "matches": [""], + "js": ["content_scripts/replacer.js"], + "run_at": "document_end" + } + ], + + "icons": { + "48": "icons/icon-48.png", + "96": "icons/icon-96.png" + }, + + "browser_action": { + "default_icon": { + "48": "icons/icon-48.png" + }, + "default_title": "Word Replacer", + "default_popup": "popup/options.html" + }, + + "options_ui": { + "page": "popup/options.html", + "open_in_tab": true + }, + + "applications": { + "gecko": { + "id": "word-replacer@krypt77.com", + "strict_min_version": "57.0" + } + } +} \ No newline at end of file