From cdc35c07e63213779f1a3d4db2f8812abf6dc51e Mon Sep 17 00:00:00 2001 From: ator-dev Date: Wed, 31 May 2023 13:19:14 +0100 Subject: [PATCH] Adapt manifest v3 specific code from main --- manifest/chromium.json | 20 ++++++++++++-------- manifest/firefox.json | 38 +++++++++++++++----------------------- src/background.ts | 24 ++++++++++++------------ 3 files changed, 39 insertions(+), 43 deletions(-) diff --git a/manifest/chromium.json b/manifest/chromium.json index e05b9ac..8dfcaa5 100644 --- a/manifest/chromium.json +++ b/manifest/chromium.json @@ -1,5 +1,5 @@ { - "manifest_version": 3, + "manifest_version": 2, "name": "Mark My Search", "description": "Highlight searched keywords. Find matches instantly.", "version": "1.14.2", @@ -12,19 +12,23 @@ }, "permissions": [ + "*://*/*", "tabs", - "scripting", "storage", "search", "contextMenus" ], - "host_permissions": [ - "*://*/*" - ], - "background": { - "service_worker": "/dist/background.js" + "persistent": false, + "scripts": [ + "/dist/include/utility.js", + "/dist/include/pattern-stem.js", + "/dist/include/pattern-diacritic.js", + "/dist/include/util-privileged.js", + "/dist/include/storage.js", + "/dist/background.js" + ] }, "content_scripts": [ @@ -45,7 +49,7 @@ "browser_style": true }, - "action": { + "browser_action": { "default_icon": { "16": "/icons/dist/mms-16.png", "32": "/icons/dist/mms-32.png" diff --git a/manifest/firefox.json b/manifest/firefox.json index c296321..5d1026d 100644 --- a/manifest/firefox.json +++ b/manifest/firefox.json @@ -1,10 +1,10 @@ { - "manifest_version": 3, + "manifest_version": 2, "name": "Mark My Search", "description": "Highlight searched keywords. Find matches instantly.", "version": "1.14.2", - "browser_specific_settings": { "gecko": { "id": "mark-my-search@searchmarkers.github.io" } }, + "browser_specific_settings": { "gecko": { "id": "{3c87dcad-dbbd-4be1-b07b-b6d0739b0aec}" } }, "icons": { "48": "/icons/mms.svg", @@ -12,8 +12,8 @@ }, "permissions": [ + "*://*/*", "tabs", - "scripting", "storage", "search", "contextMenus" @@ -23,11 +23,8 @@ "bookmarks" ], - "host_permissions": [ - "*://*/*" - ], - "background": { + "persistent": false, "scripts": [ "/dist/include/utility.js", "/dist/include/pattern-stem.js", @@ -56,28 +53,23 @@ "browser_style": true }, - "action": { + "browser_action": { "default_icon": "/icons/mms.svg", "default_title": "Mark My Search", "default_popup": "/pages/popup.html" }, "web_accessible_resources": [ - { - "resources": [ - "/dist/paint.js", - "/icons/arrow.svg", - "/icons/close.svg", - "/icons/search.svg", - "/icons/show.svg", - "/icons/refresh.svg", - "/icons/create.svg", - "/icons/delete.svg", - "/icons/edit.svg", - "/icons/reveal.svg" - ], - "matches": [ "*://*/*" ] - } + "/dist/paint.js", + "/icons/arrow.svg", + "/icons/close.svg", + "/icons/search.svg", + "/icons/show.svg", + "/icons/refresh.svg", + "/icons/create.svg", + "/icons/delete.svg", + "/icons/edit.svg", + "/icons/reveal.svg" ], "commands": { diff --git a/src/background.ts b/src/background.ts index 3ee0d7b..069fd5c 100644 --- a/src/background.ts +++ b/src/background.ts @@ -223,16 +223,16 @@ const manageEnginesCacheOnBookmarkUpdate = (() => { })(); const injectIntoTabs = async () => { - (await chrome.tabs.query({})).filter(tab => tab.id !== undefined).forEach(tab => { - chrome.scripting.executeScript({ - target: { tabId: tab.id as number }, - files: [ - "/dist/include/utility.js", - "/dist/include/pattern-stem.js", - "/dist/include/pattern-diacritic.js", - "/dist/content.js", - ], - }).catch(() => chrome.runtime.lastError); // Read `lastError` to suppress injection errors. + (await chrome.tabs.query({})).filter(tab => tab.id !== undefined).forEach(async tab => { + for (const file of [ + "/dist/include/utility.js", + "/dist/include/pattern-stem.js", + "/dist/include/pattern-diacritic.js", + "/dist/content.js", + ]) { + await chrome.tabs.executeScript(tab.id as number, { file }) + ?.catch(() => chrome.runtime.lastError); // Read `lastError` to suppress injection errors.; + } }); }; @@ -243,7 +243,7 @@ const injectIntoTabs = async () => { const updateActionIcon = (enabled?: boolean) => enabled === undefined ? storageGet("local", [ StorageLocal.ENABLED ]).then(local => updateActionIcon(local.enabled)) - : chrome.action.setIcon({ path: useChromeAPI() + : chrome.browserAction.setIcon({ path: useChromeAPI() ? enabled ? "/icons/dist/mms-32.png" : "/icons/dist/mms-off-32.png" // Chromium lacks SVG support for the icon. : enabled ? "/icons/mms.svg" : "/icons/mms-off.svg" }) @@ -666,7 +666,7 @@ const toggleHighlightsInTab = async (tabId: number, toggleHighlightsOn?: boolean chrome.commands.onCommand.addListener(async commandString => { if (commandString === "open-popup") { - (chrome.action["openPopup"] ?? (() => undefined))(); + (chrome.browserAction["openPopup"] ?? (() => undefined))(); } const [ tab ] = await chrome.tabs.query({ active: true, lastFocusedWindow: true }); const tabId = tab.id as number; // `tab.id` always defined for this case.