Skip to content

Commit 2a8161f

Browse files
authored
Merge pull request #22 from nobkd/use-nue
Use nue
2 parents 6ebab15 + c7ba721 commit 2a8161f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+413
-672
lines changed

.github/workflows/publish.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ jobs:
2727
run: bun run bundle
2828

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

3232
- name: Release
3333
uses: browser-actions/release-firefox-addon@latest
3434
with:
3535
36-
addon-path: .out/replace_maps.zip
37-
source-path: .out/replace_maps_source.zip
36+
addon-path: .dist/replace_maps.zip
37+
source-path: .dist/replace_maps_source.zip
3838
approval-note: Follow the instructions in AMO-README.md
3939
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
4040
license: MPL-2.0

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
node_modules/
22
.dist/
3-
.out/
43

54
.version-update
65
.env
6+
7+
src/@lib/**/*.png

AMO-README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ This uses the `package-lock.json` file for installation to avoid package changes
1818
bun run build && bun run bundle
1919
```
2020

21-
This minifies the JavaScript, copies static resources and bundles the output to `.out/replace_maps.zip`.
21+
This minifies the JavaScript, copies static resources and bundles the output to `.dist/replace_maps.zip`.

README.md

-55
Original file line numberDiff line numberDiff line change
@@ -27,67 +27,12 @@ As a result, the response is an extension page that contains a [Leaflet](https:/
2727

2828
You can turn the extension off for every hostname by using the browser action button or by using the settings page.
2929

30-
### Extension Flowchart
31-
32-
```mermaid
33-
flowchart TD
34-
35-
subgraph action [Browser Action]
36-
actionclick(Action Icon) -->|add / remove| storage[(Disabled Hostnames)]
37-
settings(Settings Page) -->|add / remove| storage
38-
end
39-
40-
41-
subgraph reqres [Request-Response Sytem]
42-
req([Frame Request]) --> url{Matches\nGoogle Maps\nURL?}
43-
url -->|no| nomatch([Continue Original Request])
44-
45-
url -->|yes| match{Hostname\nDisabled?}
46-
storage -->|provide hostnames| match
47-
match -->|no| res([Redirect to extension map page])
48-
match -->|yes| nomatch
49-
50-
end
51-
52-
res -->|use params| params
53-
54-
subgraph dec [Search-Param Decoding]
55-
params(Search Params) -->|has q| q([readQ])
56-
q -->|with title| pos[Marker/s]
57-
params -->|has z| zoom[Zoom]
58-
59-
params -->|has pb| pb([readPB])
60-
pb -->|has| minfo[Marker Info]
61-
pb -->|has| marea[Map Area]
62-
63-
minfo -->|has\nsearch string| q
64-
minfo -->|has\n0x...:0x...| cid[CID]
65-
cid -.->|unknown usage| pos
66-
minfo -->|has\nDMS coords| dms([parseDMS])
67-
dms --> pos
68-
69-
pb -->|has| mtype[Map Type]
70-
71-
marea -->|has\ncoords| mcoords[Map Coords]
72-
marea -->|has\naltitude| mzoom([getMapZoom])
73-
mzoom --> zoom
74-
75-
pos --> mdata[(Map Data)]
76-
mtype --> mdata
77-
mcoords --> mdata
78-
zoom --> mdata
79-
end
80-
81-
mdata -->|use map data| mview([Load Leaflet Map])
82-
```
83-
8430
### Known issues
8531

8632
- Sometimes the zoom level is completely wrong
8733
- Not working when a website does not use an iFrame / embed
8834
- Not working when iFrame uses only CIDs
8935
- No routes, just positions
90-
- If insufficient information is gathered, the map stays blank
9136

9237
<!-- Badges & Links -->
9338
[badge-license]: https://img.shields.io/github/license/nobkd/replace-maps

build-icons.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { join } from 'path'
33
import { mkdirSync } from 'fs'
44

55
const indir = 'icons'
6-
const outdir = 'public/icons'
6+
const outdir = 'src/icons'
77
const svgs = ['icon-grey.svg', 'icon.svg']
88
const sizes = [48, 96]
99

build.sh

-16
This file was deleted.

bump.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { writeFileSync } from 'node:fs'
22
import { version } from './package.json' with { type: 'json' }
3-
import manifest from './public/manifest.json' with { type: 'json' }
3+
import manifest from './src/manifest.json' with { type: 'json' }
44

55
manifest.version = version
6-
writeFileSync('./public/manifest.json', JSON.stringify(manifest, null, 2))
6+
writeFileSync('./src/manifest.json', JSON.stringify(manifest, null, 2))

bun.lock

+34-15
Large diffs are not rendered by default.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/test/parseDMS.test.js renamed to map-utils/test/parseDMS.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { test, expect } from 'bun:test'
2-
import { parseDMS } from '../map/utils/parseDMS.js'
2+
import { parseDMS } from '../parseDMS.js'
33

44
test('Parse Degrees Minutes Seconds Direction: Example', () => {
55
const res = parseDMS(`10°60'36.0"N 10°60'36.0"E`)

src/test/parsePB.test.js renamed to map-utils/test/parsePB.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { test, expect } from 'bun:test'
2-
import { parsePB, tileTypes } from '../map/utils/parsePB.js'
2+
import { parsePB, tileTypes } from '../parsePB.js'
33

44
test('Parse PB: empty list', () => {
55
const res = parsePB([])

src/test/read.test.js renamed to map-utils/test/read.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { test, expect, mock } from 'bun:test'
2-
import { readPB, readQ, nominatimQ } from '../map/utils/read.js'
2+
import { readPB, readQ, nominatimQ } from '../read.js'
33

44
globalThis.fetch = mock()
55

File renamed without changes.

package.json

+9-5
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,20 @@
1515
"url": "git+https://github.com/nobkd/replace-maps.git"
1616
},
1717
"scripts": {
18+
"postinstall": "bun -e \"import {$} from 'bun'; $`cp -r 'node_modules/leaflet/dist/images' 'node_modules/leaflet-fullscreen/dist/fullscreen.png' 'node_modules/leaflet-fullscreen/dist/[email protected]' 'src/@lib/'`\"",
1819
"icons": "bun i --no-save oslllo-svg2 && bun build-icons.js",
19-
"dev": "run-p -rl build:dev serve",
20-
"build": "sh build.sh",
21-
"build:dev": "sh build.sh dev",
22-
"serve": "web-ext run -s .dist",
23-
"bundle": "web-ext build -s .dist -a .out --overwrite-dest -n replace_maps.zip",
20+
"dev": "run-p -rl build:dev serve:dev",
21+
"prod": "run-s -l build serve",
22+
"build": "nue build -pr src",
23+
"build:dev": "nue -r src",
24+
"serve": "web-ext run -s src/.dist/prod",
25+
"serve:dev": "web-ext run -s src/.dist/dev",
26+
"bundle": "web-ext build -s src/.dist/prod -a .dist --overwrite-dest -n replace_maps.zip",
2427
"release": "bun i --no-save release-it release-it-changelogen && release-it"
2528
},
2629
"devDependencies": {
2730
"npm-run-all": "^4.1.5",
31+
"nuekit": "^1.0.0-RC.3",
2832
"web-ext": "^8.5.0"
2933
},
3034
"dependencies": {

src/@global/bootstrap.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { router } from '/@nue/app-router.js'
2+
3+
router.configure({
4+
route: '/:',
5+
url_params: ['q', 'pb', 'z'],
6+
persistent_params: ['theme', 'disabled_hosts', 'resizable'],
7+
})
8+
9+
router.initialize({ root: document.body })

src/@global/layout.html

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<head>
2+
<slot for="head" />
3+
<meta name="color-scheme" content="light dark">
4+
</head>
5+
6+
<main>
7+
<slot for="content"/>
8+
</main>
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,48 @@
1-
import { runtime, webRequest, tabs, windows } from 'webextension-polyfill'
1+
import { changeHostnameState, getHostnameState, nueStateChange } from '/@util/helper.js'
2+
import { browserAction, tabs, webRequest, windows, runtime } from '/@util/webext.js'
23

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

7-
const gLocales = domainEnds.join('|') // TODO: collect more locales
8-
export const matcher = new RegExp(
5+
/*** action ***/
6+
7+
function updateIcon(url) {
8+
browserAction.setIcon({
9+
path: !getHostnameState(url) ? {
10+
48: '/icons/48-icon.png',
11+
96: '/icons/96-icon.png',
12+
} : {
13+
48: '/icons/48-icon-grey.png',
14+
96: '/icons/96-icon-grey.png',
15+
},
16+
})
17+
}
18+
19+
async function updateActiveTabIcon() {
20+
let browserTabs = await tabs.query({ active: true, currentWindow: true })
21+
22+
let tab = browserTabs[0]
23+
if (tab && tab.url) updateIcon(tab.url)
24+
}
25+
26+
function actionClick(tab) {
27+
if (!tab.url || !tab.id) return
28+
else if (tab.url.startsWith('about:')) return
29+
30+
changeHostnameState(tab.url)
31+
updateActiveTabIcon()
32+
tabs.reload(tab.id, { bypassCache: true })
33+
}
34+
35+
36+
/*** bg ***/
37+
38+
const gLocales = (await (await fetch('/domain-ends.json')).json()).join('|')
39+
40+
const matcher = new RegExp(
941
// TODO: fix regex to fit more patterns
1042
`^(https?:\/\/)?(maps\.google\.(${gLocales})\/maps.*\?.*output=embed|(www\.)?google\.(${gLocales})\/maps\/embed.*\?)`
1143
)
12-
export const runtimeMapUrl = runtime.getURL('map.html')
44+
45+
const runtimeMapUrl = runtime.getURL('map.html')
1346

1447
/**
1548
* Checks if `frames` send a request to Maps.
@@ -21,23 +54,28 @@ export const runtimeMapUrl = runtime.getURL('map.html')
2154
function redirect(req) {
2255
// TODO: check if originUrl always matches current tab url -> e.g. in frames with subframes
2356
if (req.originUrl && req.url.match(matcher)) {
24-
if (!disabledHosts.includes(getHostname(req.originUrl))) {
57+
if (!getHostnameState(req.originUrl)) {
2558
return {
26-
redirectUrl: runtimeMapUrl + '?' + req.url.split('?').pop(),
59+
redirectUrl: `${runtimeMapUrl}?${req.url.split('?').pop()}`,
2760
}
2861
}
2962
}
3063
return {}
3164
}
3265

66+
67+
/*** onload ***/
68+
69+
browserAction.onClicked.addListener(actionClick)
70+
3371
// Listens to web requests from frames, redirects when fitting `matcher`
3472
webRequest.onBeforeRequest.addListener(
3573
redirect,
3674
{
3775
urls: ['<all_urls>'],
3876
types: ['sub_frame'],
3977
},
40-
['blocking']
78+
['blocking'],
4179
)
4280

4381
// listen to tab URL changes
@@ -51,3 +89,5 @@ windows.onFocusChanged.addListener(updateActiveTabIcon)
5189

5290
// update icon at startup
5391
updateActiveTabIcon()
92+
93+
nueStateChange(updateActiveTabIcon)

src/@lib/map.css

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@import "leaflet/dist/leaflet.css";
2+
@import "leaflet-fullscreen/dist/leaflet.fullscreen.css";
3+
4+
5+
html, body, div { margin: 0; padding: 0; }
6+
7+
#map { width: 100%; height: 100vh; }
8+
9+
.leaflet-container {
10+
&[data-theme="dark"] { background: #111 !important; }
11+
@media (prefers-color-scheme: dark) { &[data-theme="system"] { background: #111 !important; } }
12+
}
13+
14+
.leaflet-layer, .leaflet-popup, .leaflet-tooltip, .leaflet-control, .leaflet-control-layers-toggle, .leaflet-attribution-flag {
15+
[data-theme="dark"] & { filter: invert(100%) hue-rotate(180deg) brightness(120%) contrast(120%); }
16+
@media (prefers-color-scheme: dark) { [data-theme="system"] & { filter: invert(100%) hue-rotate(180deg) brightness(120%) contrast(120%); } }
17+
}

src/@lib/map.dhtml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<script>
2+
import { router } from '/@nue/app-router.js'
3+
import { nueStateChange } from '/@util/helper.js'
4+
import { init } from '/@util/leaflet.js'
5+
</script>
6+
7+
<div @name="maps" :data-theme="router.state.theme || 'system'" id="map">
8+
9+
<script>
10+
router = router
11+
12+
mounted() {
13+
router.on('theme resizable', this.update)
14+
nueStateChange(this.update)
15+
init(this.root, router.state)
16+
}
17+
</script>
18+
</div>

src/@lib/options.css

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
html, body, ul, p { margin: 0; padding: 0; }
2+
3+
* { box-sizing: border-box; font: inherit; }
4+
5+
:root {
6+
--text: black;
7+
--bg: white;
8+
9+
--table-even: #d3d2db;
10+
--table-odd: #c3c2cb;
11+
12+
@media (prefers-color-scheme: dark) {
13+
--text: #ccc;
14+
--bg: #1c1b22;
15+
16+
--table-even: #53525b;
17+
--table-odd: #33323b;
18+
}
19+
20+
font-family: system-ui, sans-serif;
21+
font-size: 14px;
22+
}
23+
24+
body, main, main > div { width: 100%; min-height: 100vh; }
25+
26+
main > div { color: var(--text); background-color: var(--bg); }
27+
28+
label { font-weight: bold; }
29+
30+
input, button, select { padding: 0.5rem; border-radius: 0.5rem; border-style: solid; border-color: color-mix(in srgb, var(--text), transparent); }
31+
32+
section { padding: 0.5rem; display: grid; gap: 0.75rem; }
33+
34+
.items, .form :is(form, li) {
35+
display: grid;
36+
grid-template-columns: 1fr auto;
37+
align-items: center;
38+
gap: 0.5rem;
39+
}
40+
41+
.form ul {
42+
display: grid;
43+
gap: 0.25rem;
44+
45+
li {
46+
border-radius: 0.25rem;
47+
padding: 0.5rem;
48+
49+
&:nth-child(even) { background-color: var(--table-even); }
50+
&:nth-child(odd) { background-color: var(--table-odd); }
51+
52+
button {
53+
width: 1.75rem;
54+
height: 1.75rem;
55+
color: red;
56+
display: flex;
57+
justify-content: center;
58+
align-items: center;
59+
}
60+
}
61+
}

0 commit comments

Comments
 (0)