Skip to content

Commit

Permalink
Merge pull request #75 from wtetsu/manifestv3_release
Browse files Browse the repository at this point in the history
Manifest V3
  • Loading branch information
wtetsu committed May 14, 2022
2 parents cf58b62 + a394a8f commit 22056a2
Show file tree
Hide file tree
Showing 7 changed files with 378 additions and 109 deletions.
2 changes: 1 addition & 1 deletion __test__/main/core/rule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import rule from "../../../src/main/core/rule";
import fs from "fs";

beforeAll(() => {
define("chrome.extension.getURL", (name) => name);
define("chrome.runtime.getURL", (name) => name);
define("fetch", async (file) => {
const data = fs.readFileSync(file);
return {
Expand Down
444 changes: 350 additions & 94 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mouse-dictionary",
"version": "1.5.14",
"version": "1.6.1",
"repository": "https://github.com/wtetsu/mouse-dictionary.git",
"author": "wtetsu",
"license": "MIT",
Expand Down
18 changes: 11 additions & 7 deletions platform/manifest-chrome.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"manifest_version": 2,
"name": "Mouse Dictionary",
"manifest_version": 3,
"version": "",
"description": "__MSG_appDesc__",
"default_locale": "en",
Expand All @@ -9,17 +9,16 @@
"page": "options/options.html",
"open_in_tab": true
},
"permissions": ["storage", "unlimitedStorage", "activeTab"],
"permissions": ["storage", "unlimitedStorage", "activeTab", "scripting"],
"background": {
"scripts": ["background.js"],
"persistent": false
"service_worker": "background.js"
},
"browser_action": {
"action": {
"default_icon": "icons/icon19.png",
"default_title": "Mouse Dictionary"
},
"commands": {
"_execute_browser_action": {
"_execute_action": {
"description": "Activate the extension"
},
"scroll_down": {
Expand All @@ -34,5 +33,10 @@
"48": "icons/icon48.png",
"128": "icons/icon128.png"
},
"web_accessible_resources": ["data/*.json"]
"web_accessible_resources": [
{
"resources": ["data/rule.json", "data/dict*.json"],
"matches": ["<all_urls>"]
}
]
}
17 changes: 13 additions & 4 deletions src/background/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,20 @@
import ExpiringQueue from "./queue";
import uniqueId from "./unique";

chrome.browserAction.onClicked.addListener(() => {
chrome.tabs.executeScript({
file: "./main.js",
if (BROWSER === "CHROME") {
chrome.action.onClicked.addListener((tab) => {
chrome.scripting.executeScript({
target: { tabId: tab.id },
files: ["main.js"],
});
});
});
} else {
chrome.browserAction.onClicked.addListener(() => {
chrome.tabs.executeScript({
file: "./main.js",
});
});
}

// cross-extension messaging
chrome.runtime.onMessageExternal.addListener((message) => {
Expand Down
2 changes: 1 addition & 1 deletion src/main/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

const loadJson = async (fname) => {
const url = chrome.extension.getURL(fname);
const url = chrome.runtime.getURL(fname);
return fetch(url).then((r) => r.json());
};

Expand Down
2 changes: 1 addition & 1 deletion src/options/logic/dict.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export const registerDefaultDict = async (fnProgress: ProgressCallback): Promise
};

const loadJsonFile = async (fname: string): Promise<Record<string, any>> => {
const url = chrome.extension.getURL(fname);
const url = chrome.runtime.getURL(fname);
const response = await fetch(url);
return response.json();
};
Expand Down

0 comments on commit 22056a2

Please sign in to comment.