Skip to content

Commit 53dca29

Browse files
authored
Migrate to manifest v3 (#68)
* Migrate to manifest v3 The migration required splitting the extensions between Chrome and Firefox. Firefox doesn't support service workers, but otherwise the extensions are the same. * Fix lint issues
1 parent 1ca82b7 commit 53dca29

File tree

13 files changed

+86
-43
lines changed

13 files changed

+86
-43
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414

1515
strategy:
1616
matrix:
17-
node-version: [16.x, 18.x, 19.x]
17+
node-version: [18.x, 20.x, 22.x]
1818

1919
steps:
2020
- uses: actions/checkout@v2

.github/workflows/release.yml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ jobs:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- uses: actions/checkout@v2
13-
- name: Use Node.js 18.x
13+
- name: Use Node.js 20.x
1414
uses: actions/setup-node@v1
1515
with:
16-
node-version: 18.x
16+
node-version: 20.x
1717
- run: npm ci
1818
- run: npm run lint
1919
- run: npm run build
@@ -27,12 +27,21 @@ jobs:
2727
release_name: Advent of Code to Markdown ${{ github.ref }}
2828
draft: false
2929
prerelease: false
30-
- name: Upload Release Asset
30+
- name: Upload Release Asset - Chrome
3131
uses: actions/upload-release-asset@v1
3232
env:
3333
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3434
with:
3535
upload_url: ${{ steps.create_release.outputs.upload_url }}
36-
asset_path: ./web-ext-artifacts/aoc-to-markdown-addon.zip
37-
asset_name: aoc-to-markdown-addon-${{ github.ref }}.zip
36+
asset_path: ./web-ext-artifacts/aoc-to-markdown-chrome.zip
37+
asset_name: aoc-to-markdown-chrome-${{ github.ref }}.zip
38+
asset_content_type: application/zip
39+
- name: Upload Release Asset - Firefox
40+
uses: actions/upload-release-asset@v1
41+
env:
42+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
43+
with:
44+
upload_url: ${{ steps.create_release.outputs.upload_url }}
45+
asset_path: ./web-ext-artifacts/aoc-to-markdown-firefox.zip
46+
asset_name: aoc-to-markdown-firefox-${{ github.ref }}.zip
3847
asset_content_type: application/zip

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ typings/
6161
.next
6262

6363
# Build output
64-
/addon/**/*.js
65-
/addon/manifest.json
64+
addon/
6665
web-ext-artifacts/
6766
.web-extension-id

package.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@
44
"description": "Converts a given Advent of Code page to a GitHub-compatible Markdown file.",
55
"repository": "github:kfarnung/aoc-to-markdown",
66
"scripts": {
7-
"build": "npm run compile && web-ext build -n aoc-to-markdown-addon.zip -s addon --overwrite-dest",
8-
"compile": "npm run genmanifest && webpack",
9-
"genmanifest": "node ./tools/genmanifest.js ./src/manifest.json ./addon/manifest.json",
10-
"lint": "eslint . && npm run compile && web-ext lint -s addon",
7+
"build": "npm run compile && npm run build-chrome && npm run build-firefox",
8+
"build-chrome": "web-ext build -n aoc-to-markdown-chrome.zip -s addon/chrome --overwrite-dest",
9+
"build-firefox": "web-ext build -n aoc-to-markdown-firefox.zip -s addon/firefox --overwrite-dest",
10+
"compile": "webpack && npm run genmanifest && npm run copyicons",
11+
"copyicons": "node ./tools/copyicons.js",
12+
"genmanifest": "node ./tools/genmanifest.js",
13+
"lint": "eslint . && npm run compile && web-ext lint -s addon/firefox",
1114
"lint-fix": "eslint . --fix",
1215
"prepare": "npm run compile",
1316
"prestart": "npm run compile",
1417
"pretest": "npm run compile",
15-
"start": "web-ext run -s addon",
18+
"start": "web-ext run -s ./addon/firefox",
1619
"test": "echo \"Error: no test specified\" && exit 1",
1720
"version": "npm run genmanifest"
1821
},

src/background_scripts/background.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import {
2+
action,
23
runtime,
3-
pageAction,
44
tabs as _tabs,
55
} from "webextension-polyfill";
66

77
runtime.onMessage.addListener((data, sender) => {
88
switch (data.action) {
99
case "showPageAction":
10-
pageAction.show(sender.tab.id);
10+
action.enable(sender.tab.id);
1111
break;
1212

1313
default:
@@ -16,7 +16,11 @@ runtime.onMessage.addListener((data, sender) => {
1616
}
1717
});
1818

19-
pageAction.onClicked.addListener(() => {
19+
runtime.onInstalled.addListener(() => {
20+
action.disable();
21+
});
22+
23+
action.onClicked.addListener(() => {
2024
_tabs
2125
.query({ active: true, currentWindow: true })
2226
.then((tabs) => {
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/manifest.json

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"manifest_version": 2,
2+
"manifest_version": 3,
33
"name": "Advent of Code to Markdown",
44
"version": null,
55
"description": "Converts a given Advent of Code page to a GitHub-compatible Markdown file.",
@@ -10,21 +10,30 @@
1010
"128": "icons/aoc-to-markdown-128.png"
1111
},
1212
"background": {
13-
"scripts": ["background_scripts/index.js"]
13+
"service_worker": "background_scripts/index.js"
1414
},
1515
"content_scripts": [
1616
{
17-
"js": ["/content_scripts/index.js"],
18-
"matches": ["*://adventofcode.com/*/day/*"]
17+
"js": [
18+
"/content_scripts/index.js"
19+
],
20+
"matches": [
21+
"*://adventofcode.com/*/day/*"
22+
]
1923
}
2024
],
21-
"page_action": {
25+
"action": {
2226
"default_icon": {
2327
"16": "icons/aoc-to-markdown-16.png",
2428
"32": "icons/aoc-to-markdown-32.png",
2529
"48": "icons/aoc-to-markdown-48.png",
2630
"128": "icons/aoc-to-markdown-128.png"
2731
},
2832
"default_title": "Advent of Code to Markdown"
33+
},
34+
"browser_specific_settings": {
35+
"gecko": {
36+
"id": "{9255ec71-5fba-48c8-9d40-0ae6ef3d6fb3}"
37+
}
2938
}
30-
}
39+
}

0 commit comments

Comments
 (0)