Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
root = true
charset = utf-8
end_of_line = lf
tab_width = 2
indent_size = 2
indent_style = tab
trim_trailing_whitespace = true
insert_final_newline = true
22 changes: 1 addition & 21 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,9 @@ on:
branches:
- main

concurrency:
group: ${{ github.ref }}
cancel-in-progress: false

jobs:
lint:
name: Lint
timeout-minutes: 10
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v1

- name: Install
run: bun install --frozen-lockfile

- name: Lint
run: bun run lint

test:
name: Test
timeout-minutes: 10
runs-on: ubuntu-latest

steps:
Expand All @@ -41,4 +21,4 @@ jobs:
run: bun install --frozen-lockfile

- name: Test
run: bun run test:cov
run: bun test --coverage
7 changes: 3 additions & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ concurrency:
jobs:
publish:
name: Publish to Firefox AMO
timeout-minutes: 10
runs-on: ubuntu-latest

steps:
Expand All @@ -28,14 +27,14 @@ jobs:
run: bun run bundle

- name: Bundle source
run: git archive --format=zip ${{ github.event.release.tag_name }} --output out/replace_maps_source.zip
run: git archive --format=zip ${{ github.event.release.tag_name }} --output .out/replace_maps_source.zip

- name: Release
uses: browser-actions/release-firefox-addon@latest
with:
addon-id: replace_maps@nobkd.github.io
addon-path: out/replace_maps.zip
source-path: out/replace_maps_source.zip
addon-path: .out/replace_maps.zip
source-path: .out/replace_maps_source.zip
approval-note: Follow the instructions in AMO-README.md
release-note: ${{ github.event.release.body }} # TODO: convert md to html, h1-6 not allowed... Currently ignoring this problem, as the field is needed for publishing
license: MPL-2.0
Expand Down
8 changes: 3 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
node_modules/
dist/
out/
coverage/
.dist/
.out/

.version-update
.env

public/icons/
6 changes: 0 additions & 6 deletions .prettierignore

This file was deleted.

12 changes: 0 additions & 12 deletions .prettierrc

This file was deleted.

2 changes: 1 addition & 1 deletion AMO-README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ This uses the `package-lock.json` file for installation to avoid package changes
bun run build && bun run bundle
```

This transpiles and minifies the TypeScript, copies static resources and bundles the output to `out/replace_maps.zip`.
This minifies the JavaScript, copies static resources and bundles the output to `.out/replace_maps.zip`.
16 changes: 16 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh

# clean & create dir
rm -rf '.dist'
mkdir -p '.dist'

# copy static resources
cp -r 'public/.' '.dist'
cp 'node_modules/leaflet/dist/images/marker-icon-2x.png' 'node_modules/leaflet/dist/images/marker-shadow.png' '.dist'

# check if dev / prod, then build
if [[ $1 == 'dev' ]]; then
echo '--watch'
else
echo '--minify'
fi | xargs bun build --experimental-css --experimental-html --outdir '.dist' 'src/bg.html' 'src/map.html' 'src/options.html'
6 changes: 6 additions & 0 deletions bump.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { writeFileSync } from 'node:fs'
import { version } from './package.json' with { type: 'json' }
import manifest from './public/manifest.json' with { type: 'json' }

manifest.version = version
writeFileSync('./public/manifest.json', JSON.stringify(manifest, null, 2))
283 changes: 283 additions & 0 deletions bun.lock

Large diffs are not rendered by default.

Binary file removed bun.lockb
Binary file not shown.
38 changes: 10 additions & 28 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,21 @@
"url": "git+https://github.com/nobkd/replace-maps.git"
},
"scripts": {
"postinstall": "bun build-icons.js",
"lint": "prettier . --check",
"lint:fix": "prettier . --write",
"test": "vitest run",
"test:watch": "vitest",
"test:cov": "vitest run --coverage",
"icons": "bun i --no-save oslllo-svg2 && bun build-icons.js",
"dev": "run-p -rl build:dev serve",
"build": "vite build",
"build:dev": "vite build --watch --mode development --minify false",
"serve": "web-ext run -s dist",
"bundle": "web-ext build -s dist -a out --overwrite-dest -n replace_maps.zip",
"release": "release-it"
"build": "sh build.sh",
"build:dev": "sh build.sh dev",
"serve": "bunx web-ext run -s .dist",
"bundle": "bunx web-ext build -s .dist -a .out --overwrite-dest -n replace_maps.zip",
"release": "bun i --no-save release-it release-it-changelogen && release-it"
},
"devDependencies": {
"@types/leaflet": "^1.9.12",
"@types/leaflet-fullscreen": "^1.0.9",
"@types/webextension-polyfill": "^0.10.7",
"@vitest/coverage-v8": "^1.6.0",
"npm-run-all": "^4.1.5",
"oslllo-svg2": "^2.0.2",
"prettier": "^3.3.2",
"release-it": "^17.4.0",
"release-it-changelogen": "^0.1.0",
"vite": "^5.3.2",
"vite-plugin-static-copy": "^1.0.5",
"vitest": "^1.6.0",
"web-ext": "^8.2.0",
"webextension-polyfill": "^0.12.0"
"npm-run-all": "^4.1.5"
},
"dependencies": {
"leaflet": "^1.9.4",
"leaflet-fullscreen": "^1.0.2"
"leaflet-fullscreen": "^1.0.2",
"webextension-polyfill": "^0.12.0"
},
"release-it": {
"git": {
Expand All @@ -70,12 +53,11 @@
},
"hooks": {
"before:init": [
"bun run lint",
"bun run test",
"bun run build"
],
"after:bump": [
"sh scripts/bump.sh"
"bun bump.js"
]
}
}
Expand Down
Binary file added public/icons/48-icon-grey.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/icons/48-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/icons/96-icon-grey.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/icons/96-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
"background": {
"page": "bg.html"
},
"web_accessible_resources": ["map.html"],
"web_accessible_resources": [
"map.html"
],
"browser_action": {
"default_icon": {
"48": "icons/48-icon.png",
Expand All @@ -37,4 +39,4 @@
"options_ui": {
"page": "options.html"
}
}
}
1 change: 0 additions & 1 deletion scripts/bump.sh

This file was deleted.

4 changes: 2 additions & 2 deletions src/bg.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!doctype html>
<!DOCTYPE html>
<head>
<meta charset="UTF-8" />
<meta charset="UTF-8">
<script src="bg/action.js" type="module"></script>
<script src="bg/bg.js" type="module"></script>
</head>
7 changes: 4 additions & 3 deletions src/bg/action.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { browserAction, /*webNavigation,*/ Tabs, tabs } from 'webextension-polyfill'
import { getHostname, invertHostState } from './utils/storage'
import { tabs, browserAction, /*webNavigation*/ } from 'webextension-polyfill'

import { getHostname, invertHostState } from './utils/storage.js'
//import { matcher as mapsUrlMatcher, runtimeMapUrl } from './bg';

//const replacedUrlMatcher = new RegExp(`^${runtimeMapUrl}\?`);
Expand All @@ -10,7 +11,7 @@ import { getHostname, invertHostState } from './utils/storage'
*
* Requests all frames from the current tab, filters them for extension Leaflet frames and Maps frames.
* Reloads the full tab on extension Leaflet or Maps frame match.
* @param {Tabs.Tab} tab Currently active tab
* @param {browser.Tabs.Tab} tab Currently active tab
*/
async function actionClick(tab) {
if (!tab.url || !tab.id) return
Expand Down
13 changes: 7 additions & 6 deletions src/bg/bg.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { runtime, tabs, windows, webRequest, WebRequest } from 'webextension-polyfill'
import { disabledHosts, getHostname } from './utils/storage'
import { updateActiveTabIcon } from './utils/actionIcon'
import { domainEnds } from './utils/domainEnds'
import { runtime, webRequest, tabs, windows } from 'webextension-polyfill'

import { disabledHosts, getHostname } from './utils/storage.js'
import { updateActiveTabIcon } from './utils/actionIcon.js'
import domainEnds from './utils/domainEnds.json' with { type: 'json' }

const gLocales = domainEnds.join('|') // TODO: collect more locales
export const matcher = new RegExp(
Expand All @@ -14,8 +15,8 @@ export const runtimeMapUrl = runtime.getURL('map.html')
* Checks if `frames` send a request to Maps.
* If they do and the extension isn't disabled for the current site, then the request is redirected to the extension leaflet map with all URL search params.
* Else the request is'nt blocked.
* @param {WebRequest.OnBeforeRequestDetailsType} req Web Request from frame
* @returns {WebRequest.BlockingResponse} Redirect to extension map or pass through if extension disabled for website
* @param {browser.WebRequest.OnBeforeRequestDetailsType} req Web Request from frame
* @returns {browser.WebRequest.BlockingResponse} Redirect to extension map or pass through if extension disabled for website
*/
function redirect(req) {
// TODO: check if originUrl always matches current tab url -> e.g. in frames with subframes
Expand Down
19 changes: 9 additions & 10 deletions src/bg/utils/actionIcon.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { browserAction, tabs } from 'webextension-polyfill'
import { disabledHosts, getHostname } from './storage'

import { disabledHosts, getHostname } from './storage.js'

/**
* Updates the action icon
Expand All @@ -9,15 +10,13 @@ export function updateIcon(hostname) {
let disabled = disabledHosts.includes(hostname)

browserAction.setIcon({
path: !disabled
? {
48: '/icons/48-icon.png',
96: '/icons/96-icon.png',
}
: {
48: '/icons/48-icon-grey.png',
96: '/icons/96-icon-grey.png',
},
path: !disabled ? {
48: '/icons/48-icon.png',
96: '/icons/96-icon.png',
} : {
48: '/icons/48-icon-grey.png',
96: '/icons/96-icon-grey.png',
},
})
}

Expand Down
Loading
Loading