From 950d2de0c083eddee0ebd9ebd6c8ad8be6a1a7d2 Mon Sep 17 00:00:00 2001 From: Seif Attar Date: Mon, 1 Apr 2024 03:31:39 +0100 Subject: [PATCH 1/2] Fix firefox host permissions This required changing to MV2 as doing it with MV3 would require a landing page and extra requests for permissions. Added firefox specific listeners as the APIs differs between browser.action.setIcon in chrome and browser.browserAction.setIcon in firefox Re-introduce firefox ext id --- browsers-adapters/firefox/worker-actions.js | 15 +++++++++++++ browsers-adapters/firefox/worker-listeners.js | 18 +++++++++++++++ manifest.firefox.json | 22 ++++++++----------- popup/popup.js | 12 +++++----- 4 files changed, 49 insertions(+), 18 deletions(-) create mode 100644 browsers-adapters/firefox/worker-actions.js create mode 100644 browsers-adapters/firefox/worker-listeners.js diff --git a/browsers-adapters/firefox/worker-actions.js b/browsers-adapters/firefox/worker-actions.js new file mode 100644 index 0000000..db240fd --- /dev/null +++ b/browsers-adapters/firefox/worker-actions.js @@ -0,0 +1,15 @@ +export function sendMessageToTab(tabId, msgObj) { + return browser.tabs.sendMessage(tabId, msgObj); +} + +export function setIcon(details) { + return browser.browserAction.setIcon(details); +} + +export function executeScript(injection) { + return browser.scripting.executeScript(injection); +} + +export function cacheSet(keyValuesObj) { + return browser.storage.local.set(keyValuesObj); +} diff --git a/browsers-adapters/firefox/worker-listeners.js b/browsers-adapters/firefox/worker-listeners.js new file mode 100644 index 0000000..72cd1a7 --- /dev/null +++ b/browsers-adapters/firefox/worker-listeners.js @@ -0,0 +1,18 @@ +import { handleTabVisit } from "../../background.js"; +import * as actions from "./worker-actions.js"; + +// Listen when user switches to a tab (activates it) +browser.tabs.onActivated.addListener((activeInfo) => { + browser.tabs.get(activeInfo.tabId, (tab) => { + if (tab && tab.url) { + handleTabVisit(actions, activeInfo.tabId, tab.url); + } + }); +}); + +// Listen for tab updates (when the URL changes) +browser.tabs.onUpdated.addListener((tabId, changeInfo, tab) => { + if (tabId && changeInfo.status === "complete") { + handleTabVisit(actions, tabId, tab.url); + } +}); diff --git a/manifest.firefox.json b/manifest.firefox.json index 415c093..2c314e4 100644 --- a/manifest.firefox.json +++ b/manifest.firefox.json @@ -1,25 +1,21 @@ { "name": "Boycott-Z", "version": "0.2.1", - "description": "", + "description": "Adds a browser add-on icon that turns red when viewed site or product is on the boycott list.", "permissions": [ + "", "tabs", "activeTab", "scripting", "storage" ], - "host_permissions": [ - "" - ], + "icons": { + "48": "icons/green-triangle-128.png" + }, "web_accessible_resources": [ - { - "resources": [], - "matches": [ - "" - ] - } + "popup/*.*" ], - "action": { + "browser_action": { "default_icon": { "16": "icons/green-triangle-128.png", "48": "icons/green-triangle-128.png", @@ -30,7 +26,7 @@ }, "background": { "scripts": [ - "browsers-adapters/chrome/worker-listeners.js" + "browsers-adapters/firefox/worker-listeners.js" ], "type": "module" }, @@ -39,5 +35,5 @@ "id": "{17a15a43-7d2b-4796-b9a9-1901da7f6335}" } }, - "manifest_version": 3 + "manifest_version": 2 } \ No newline at end of file diff --git a/popup/popup.js b/popup/popup.js index f2b31d7..c318b80 100644 --- a/popup/popup.js +++ b/popup/popup.js @@ -1,6 +1,10 @@ // popup.js -chrome.storage.local.get(["boycottZItem"]).then((result) => { +if (!('browser' in self)) { + self.browser = self.chrome; +} + +browser.storage.local.get(["boycottZItem"]).then((result) => { const boycottZItem = result.boycottZItem if (!boycottZItem) { return window.close() @@ -44,11 +48,9 @@ chrome.storage.local.get(["boycottZItem"]).then((result) => { if (proof) { document.getElementById("boycottZProof").addEventListener('click', (event) => { let ur = event.target.getAttribute('href') - chrome.tabs.create({ url: ur }); + browser.tabs.create({ url: ur }); + return false; }) - // $('body').on('click', 'a', function(){ - // return false; - // }); } }); From ad0c693f47b627e430e5f8994081eb8f10c83ea5 Mon Sep 17 00:00:00 2001 From: Seif Attar Date: Mon, 1 Apr 2024 11:22:24 +0100 Subject: [PATCH 2/2] Up version to 2.2 --- manifest.chrome.json | 4 ++-- manifest.firefox.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/manifest.chrome.json b/manifest.chrome.json index 82dfcdb..6c51d75 100644 --- a/manifest.chrome.json +++ b/manifest.chrome.json @@ -1,7 +1,7 @@ { "name": "Boycott-Z", - "version": "0.2.1", - "description": "", + "version": "0.2.2", + "description": "Adds a browser add-on icon that turns red when viewed site or product is on the boycott list.", "permissions": [ "tabs", "activeTab", diff --git a/manifest.firefox.json b/manifest.firefox.json index 2c314e4..20bd0f4 100644 --- a/manifest.firefox.json +++ b/manifest.firefox.json @@ -1,6 +1,6 @@ { "name": "Boycott-Z", - "version": "0.2.1", + "version": "0.2.2", "description": "Adds a browser add-on icon that turns red when viewed site or product is on the boycott list.", "permissions": [ "",