Skip to content

Commit

Permalink
Adapt manifest v3 specific code from main
Browse files Browse the repository at this point in the history
  • Loading branch information
ator-dev committed May 31, 2023
1 parent c8ce2d6 commit cdc35c0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 43 deletions.
20 changes: 12 additions & 8 deletions manifest/chromium.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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": [
Expand All @@ -45,7 +49,7 @@
"browser_style": true
},

"action": {
"browser_action": {
"default_icon": {
"16": "/icons/dist/mms-16.png",
"32": "/icons/dist/mms-32.png"
Expand Down
38 changes: 15 additions & 23 deletions manifest/firefox.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"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",
"96": "/icons/mms.svg"
},

"permissions": [
"*://*/*",
"tabs",
"scripting",
"storage",
"search",
"contextMenus"
Expand All @@ -23,11 +23,8 @@
"bookmarks"
],

"host_permissions": [
"*://*/*"
],

"background": {
"persistent": false,
"scripts": [
"/dist/include/utility.js",
"/dist/include/pattern-stem.js",
Expand Down Expand Up @@ -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": {
Expand Down
24 changes: 12 additions & 12 deletions src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.;
}
});
};

Expand All @@ -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"
})
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit cdc35c0

Please sign in to comment.