Skip to content

Commit 9ffb840

Browse files
committed
Support Firefox
1 parent afeba0e commit 9ffb840

File tree

6 files changed

+30
-4
lines changed

6 files changed

+30
-4
lines changed

Diff for: .github/workflows/build-release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818

1919
- run: yarn
2020
- run: yarn --cwd functions
21-
- run: yarn run build
21+
- run: yarn run build:firefox
2222
- run: npx web-ext --config web-ext.config.js build
2323
- run: npx web-ext --config web-ext.config.js sign
2424
env:

Diff for: package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
{
22
"name": "spotify-lyrics",
3-
"version": "1.5.33",
3+
"version": "1.6.0",
44
"description": "Desktop Spotify Web Player Instant Synchronized Lyrics",
55
"scripts": {
66
"lint": "tsc --noEmit && eslint --ext .ts --fix src/",
77
"test": "vitest",
88
"build": "vite build",
9+
"build:firefox": "yarn run build && node ./scripts/mv2.js",
910
"watch": "cross-env NODE_ENV=development yarn build --watch",
1011
"serve": "web-ext --config web-ext.config.js run --start-url open.spotify.com",
1112
"serve:chromium": "yarn run serve -- -t chromium",

Diff for: public/manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "https://raw.githubusercontent.com/extend-chrome/manifest-json-schema/main/schema/manifest.schema.json",
33
"name": "__MSG_extensionName__",
4-
"version": "1.5.33",
4+
"version": "1.6.0",
55
"manifest_version": 3,
66
"description": "__MSG_extensionDescription__",
77
"default_locale": "en",

Diff for: scripts/mv2.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const pkg = require('../extension/manifest.json');
2+
pkg.manifest_version = 2;
3+
pkg.web_accessible_resources = ['*'];
4+
pkg.host_permissions = undefined;
5+
pkg.background = { scripts: [pkg.background.service_worker] };
6+
pkg.browser_action = pkg.action;
7+
pkg.action = undefined;
8+
require('fs').writeFileSync('./extension/manifest.json', JSON.stringify(pkg, null, 2));

Diff for: src/background.ts

+17
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,23 @@ Sentry.init({
2525
});
2626
getOptions().then(({ cid }) => Sentry.setUser({ id: cid }));
2727

28+
// firefox mv2
29+
if (!browser.action) {
30+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
31+
// @ts-ignore
32+
browser.action = browser.browserAction;
33+
34+
const oCreate = browser.contextMenus.create;
35+
browser.contextMenus.create = (arg) => {
36+
return oCreate({
37+
...arg,
38+
contexts: arg.contexts?.map((e) =>
39+
e === 'action' ? 'browser_action' : '',
40+
) as browser.Menus.ContextType[],
41+
});
42+
};
43+
}
44+
2845
function disableBrowserAction() {
2946
browser.action.disable();
3047
browser.action.setTitle({ title: i18n.actionDisableTitle() });

Diff for: src/options/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Firefox 不能在内容脚本中使用自定义元素
12
// https://bugs.chromium.org/p/chromium/issues/detail?id=390807
23
import '@webcomponents/webcomponentsjs';
34
import { render, html } from '@mantou/gem/lib/element';
@@ -45,7 +46,6 @@ if (!isWebApp) {
4546
captureException(e);
4647
});
4748
} else {
48-
// https://bugs.chromium.org/p/chromium/issues/detail?id=390807
4949
// hack content script custom element
5050
Object.defineProperty(HTMLElement.prototype, 'attachInternals', {
5151
value: function attachInternals() {

0 commit comments

Comments
 (0)