Skip to content

Commit b5d477a

Browse files
committed
lint: chnage rules, cleanup vitest code
1 parent f064723 commit b5d477a

25 files changed

+1000
-1009
lines changed

.prettierrc

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
2-
"tabWidth": 4,
3-
"useTabs": false,
4-
"endOfLine": "lf",
5-
"bracketSameLine": true,
6-
"bracketSpacing": true,
7-
"semi": true,
8-
"trailingComma": "es5",
9-
"singleQuote": true,
10-
"arrowParens": "always",
11-
"printWidth": 100
2+
"tabWidth": 2,
3+
"useTabs": false,
4+
"endOfLine": "lf",
5+
"bracketSameLine": true,
6+
"bracketSpacing": true,
7+
"semi": false,
8+
"trailingComma": "es5",
9+
"singleQuote": true,
10+
"arrowParens": "always",
11+
"printWidth": 100
1212
}

package.json

+74-74
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,80 @@
11
{
2-
"name": "replace_maps",
3-
"description": "Replace Google Maps iFrames with OSM",
4-
"author": "nobkd",
5-
"license": "MPL-2.0",
6-
"version": "0.0.6",
7-
"type": "module",
8-
"private": true,
9-
"homepage": "https://github.com/nobkd/replace-maps#readme",
10-
"bugs": {
11-
"url": "https://github.com/nobkd/replace-maps/issues"
2+
"name": "replace_maps",
3+
"description": "Replace Google Maps iFrames with OSM",
4+
"author": "nobkd",
5+
"license": "MPL-2.0",
6+
"version": "0.0.6",
7+
"type": "module",
8+
"private": true,
9+
"homepage": "https://github.com/nobkd/replace-maps#readme",
10+
"bugs": {
11+
"url": "https://github.com/nobkd/replace-maps/issues"
12+
},
13+
"repository": {
14+
"type": "git",
15+
"url": "git+https://github.com/nobkd/replace-maps.git"
16+
},
17+
"scripts": {
18+
"icons": "inkscape -w 48 -h 48 icons/icon.svg -o public/icons/48.png && inkscape -w 48 -h 48 icons/icon-grey.svg -o public/icons/48-grey.png && inkscape -w 96 -h 96 icons/icon.svg -o public/icons/96.png && inkscape -w 96 -h 96 icons/icon-grey.svg -o public/icons/96-grey.png",
19+
"format": "prettier . --check",
20+
"format:fix": "npm run format -- --write",
21+
"test": "vitest run",
22+
"dev": "run-p -rl vite:watch serve:firefox",
23+
"vite:site": "vite",
24+
"vite:watch": "vite build --watch --mode development --minify false",
25+
"build": "tsc && vite build",
26+
"serve:firefox": "web-ext run -s dist",
27+
"serve:chromium": "web-ext run -t chromium -s dist",
28+
"bundle": "web-ext build -s dist -a out --overwrite-dest -n replace_maps.zip",
29+
"release": "release-it"
30+
},
31+
"devDependencies": {
32+
"@types/leaflet": "^1.9.12",
33+
"@types/leaflet-fullscreen": "^1.0.9",
34+
"@types/webextension-polyfill": "^0.10.7",
35+
"npm-run-all": "^4.1.5",
36+
"prettier": "^3.3.2",
37+
"release-it": "^17.4.0",
38+
"release-it-changelogen": "^0.1.0",
39+
"typescript": "^5.5.2",
40+
"vite": "^5.3.1",
41+
"vite-plugin-static-copy": "^1.0.5",
42+
"web-ext": "^8.2.0",
43+
"webextension-polyfill": "^0.12.0"
44+
},
45+
"dependencies": {
46+
"leaflet": "^1.9.4",
47+
"leaflet-fullscreen": "^1.0.2"
48+
},
49+
"release-it": {
50+
"git": {
51+
"tagName": "v${version}",
52+
"commitMessage": "chore(release): v${version}",
53+
"tagAnnotation": "v${version}"
1254
},
13-
"repository": {
14-
"type": "git",
15-
"url": "git+https://github.com/nobkd/replace-maps.git"
55+
"github": {
56+
"release": true,
57+
"releaseName": "v${version}"
1658
},
17-
"scripts": {
18-
"icons": "inkscape -w 48 -h 48 icons/icon.svg -o public/icons/48.png && inkscape -w 48 -h 48 icons/icon-grey.svg -o public/icons/48-grey.png && inkscape -w 96 -h 96 icons/icon.svg -o public/icons/96.png && inkscape -w 96 -h 96 icons/icon-grey.svg -o public/icons/96-grey.png",
19-
"format": "prettier . --check",
20-
"format:fix": "npm run format -- --write",
21-
"test": "vitest run",
22-
"dev": "run-p -rl vite:watch serve:firefox",
23-
"vite:site": "vite",
24-
"vite:watch": "vite build --watch --mode development --minify false",
25-
"build": "tsc && vite build",
26-
"serve:firefox": "web-ext run -s dist",
27-
"serve:chromium": "web-ext run -t chromium -s dist",
28-
"bundle": "web-ext build -s dist -a out --overwrite-dest -n replace_maps.zip",
29-
"release": "release-it"
30-
},
31-
"devDependencies": {
32-
"@types/leaflet": "^1.9.12",
33-
"@types/leaflet-fullscreen": "^1.0.9",
34-
"@types/webextension-polyfill": "^0.10.7",
35-
"npm-run-all": "^4.1.5",
36-
"prettier": "^3.3.2",
37-
"release-it": "^17.4.0",
38-
"release-it-changelogen": "^0.1.0",
39-
"typescript": "^5.5.2",
40-
"vite": "^5.3.1",
41-
"vite-plugin-static-copy": "^1.0.5",
42-
"web-ext": "^8.2.0",
43-
"webextension-polyfill": "^0.12.0"
44-
},
45-
"dependencies": {
46-
"leaflet": "^1.9.4",
47-
"leaflet-fullscreen": "^1.0.2"
48-
},
49-
"release-it": {
50-
"git": {
51-
"tagName": "v${version}",
52-
"commitMessage": "chore(release): v${version}",
53-
"tagAnnotation": "v${version}"
54-
},
55-
"github": {
56-
"release": true,
57-
"releaseName": "v${version}"
58-
},
59-
"plugins": {
60-
"release-it-changelogen": {
61-
"disableVersion": true,
62-
"templates": {
63-
"commitMessage": "chore(release): v{{newVersion}}",
64-
"tagMessage": "v{{newVersion}}",
65-
"tagBody": "v{{newVersion}}"
66-
}
67-
}
68-
},
69-
"hooks": {
70-
"before:init": [
71-
"npm run format",
72-
"npm test",
73-
"npm run build"
74-
],
75-
"after:bump": [
76-
"sh scripts/bump.sh"
77-
]
59+
"plugins": {
60+
"release-it-changelogen": {
61+
"disableVersion": true,
62+
"templates": {
63+
"commitMessage": "chore(release): v{{newVersion}}",
64+
"tagMessage": "v{{newVersion}}",
65+
"tagBody": "v{{newVersion}}"
7866
}
67+
}
68+
},
69+
"hooks": {
70+
"before:init": [
71+
"npm run format",
72+
"npm test",
73+
"npm run build"
74+
],
75+
"after:bump": [
76+
"sh scripts/bump.sh"
77+
]
7978
}
79+
}
8080
}

public/manifest.json

+37-37
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
11
{
2-
"description": "Replace Google Maps iFrames with OpenStreetMap",
3-
"manifest_version": 2,
4-
"name": "Replace Maps",
5-
"version": "0.0.6",
6-
"homepage_url": "https://github.com/nobkd/replace-maps",
7-
"icons": {
8-
"48": "icons/48.png",
9-
"96": "icons/96.png"
10-
},
11-
"browser_specific_settings": {
12-
"gecko": {
13-
14-
"strict_min_version": "89.0"
15-
}
16-
},
17-
"permissions": [
18-
"tabs",
19-
"webNavigation",
20-
"storage",
21-
"webRequest",
22-
"webRequestBlocking",
23-
"<all_urls>"
24-
],
25-
"background": {
26-
"page": "bg.html"
27-
},
28-
"web_accessible_resources": ["map.html"],
29-
"browser_action": {
30-
"default_icon": {
31-
"48": "icons/48.png",
32-
"96": "icons/96.png"
33-
},
34-
"default_area": "navbar",
35-
"default_title": "Replace Maps"
36-
},
37-
"options_ui": {
38-
"page": "options.html"
2+
"description": "Replace Google Maps iFrames with OpenStreetMap",
3+
"manifest_version": 2,
4+
"name": "Replace Maps",
5+
"version": "0.0.6",
6+
"homepage_url": "https://github.com/nobkd/replace-maps",
7+
"icons": {
8+
"48": "icons/48.png",
9+
"96": "icons/96.png"
10+
},
11+
"browser_specific_settings": {
12+
"gecko": {
13+
14+
"strict_min_version": "89.0"
3915
}
16+
},
17+
"permissions": [
18+
"tabs",
19+
"webNavigation",
20+
"storage",
21+
"webRequest",
22+
"webRequestBlocking",
23+
"<all_urls>"
24+
],
25+
"background": {
26+
"page": "bg.html"
27+
},
28+
"web_accessible_resources": ["map.html"],
29+
"browser_action": {
30+
"default_icon": {
31+
"48": "icons/48.png",
32+
"96": "icons/96.png"
33+
},
34+
"default_area": "navbar",
35+
"default_title": "Replace Maps"
36+
},
37+
"options_ui": {
38+
"page": "options.html"
39+
}
4040
}

src/bg.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!doctype html>
22
<head>
3-
<meta charset="UTF-8" />
4-
<script src="bg/action.ts" type="module"></script>
5-
<script src="bg/bg.ts" type="module"></script>
3+
<meta charset="UTF-8" />
4+
<script src="bg/action.ts" type="module"></script>
5+
<script src="bg/bg.ts" type="module"></script>
66
</head>

src/bg/action.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { browserAction, /*webNavigation,*/ type Tabs, tabs } from 'webextension-polyfill';
2-
import { getHostname, invertHostState } from './utils/storage';
1+
import { browserAction, /*webNavigation,*/ type Tabs, tabs } from 'webextension-polyfill'
2+
import { getHostname, invertHostState } from './utils/storage'
33
//import { matcher as mapsUrlMatcher, runtimeMapUrl } from './bg';
44

55
//const replacedUrlMatcher = new RegExp(`^${runtimeMapUrl}\?`);
@@ -13,12 +13,12 @@ import { getHostname, invertHostState } from './utils/storage';
1313
* @param tab Currently active tab
1414
*/
1515
async function actionClick(tab: Tabs.Tab): Promise<void> {
16-
if (!tab.url || !tab.id) return;
16+
if (!tab.url || !tab.id) return
1717

18-
let hostname = getHostname(tab.url);
19-
await invertHostState(hostname);
18+
let hostname = getHostname(tab.url)
19+
await invertHostState(hostname)
2020

21-
/*
21+
/*
2222
// TODO: try to only reload necessary parts!!!
2323
let frames = (await webNavigation.getAllFrames({ tabId: tab.id })) ?? [];
2424
@@ -28,7 +28,7 @@ async function actionClick(tab: Tabs.Tab): Promise<void> {
2828
})
2929
)
3030
*/
31-
tabs.reload(tab.id, { bypassCache: true });
31+
tabs.reload(tab.id, { bypassCache: true })
3232
}
3333

34-
browserAction.onClicked.addListener(actionClick);
34+
browserAction.onClicked.addListener(actionClick)

src/bg/bg.ts

+28-28
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { runtime, tabs, windows, webRequest, type WebRequest } from 'webextension-polyfill';
2-
import { disabledHosts, getHostname } from './utils/storage';
3-
import { updateActiveTabIcon } from './utils/actionIcon';
4-
import { domainEnds } from './utils/domainEnds';
1+
import { runtime, tabs, windows, webRequest, type WebRequest } from 'webextension-polyfill'
2+
import { disabledHosts, getHostname } from './utils/storage'
3+
import { updateActiveTabIcon } from './utils/actionIcon'
4+
import { domainEnds } from './utils/domainEnds'
55

6-
const gLocales: string = domainEnds.join('|'); // TODO: collect more locales
6+
const gLocales: string = domainEnds.join('|') // TODO: collect more locales
77
export const matcher: RegExp = new RegExp(
8-
// TODO: fix regex to fit more patterns
9-
`^(https?:\/\/)?(maps\.google\.(${gLocales})\/maps.*\?.*output=embed|(www\.)?google\.(${gLocales})\/maps\/embed.*\?)`
10-
);
11-
export const runtimeMapUrl = runtime.getURL('map.html');
8+
// TODO: fix regex to fit more patterns
9+
`^(https?:\/\/)?(maps\.google\.(${gLocales})\/maps.*\?.*output=embed|(www\.)?google\.(${gLocales})\/maps\/embed.*\?)`
10+
)
11+
export const runtimeMapUrl = runtime.getURL('map.html')
1212

1313
/**
1414
* Checks if `frames` send a request to Maps.
@@ -18,35 +18,35 @@ export const runtimeMapUrl = runtime.getURL('map.html');
1818
* @returns Redirect to extension map or pass through if extension disabled for website
1919
*/
2020
function redirect(req: WebRequest.OnBeforeRequestDetailsType): WebRequest.BlockingResponse {
21-
// TODO: check if originUrl always matches current tab url -> e.g. in frames with subframes
22-
if (req.originUrl && req.url.match(matcher)) {
23-
if (!disabledHosts.includes(getHostname(req.originUrl))) {
24-
return {
25-
redirectUrl: runtimeMapUrl + '?' + req.url.split('?')[1],
26-
};
27-
}
21+
// TODO: check if originUrl always matches current tab url -> e.g. in frames with subframes
22+
if (req.originUrl && req.url.match(matcher)) {
23+
if (!disabledHosts.includes(getHostname(req.originUrl))) {
24+
return {
25+
redirectUrl: runtimeMapUrl + '?' + req.url.split('?')[1],
26+
}
2827
}
29-
return {};
28+
}
29+
return {}
3030
}
3131

3232
// Listens to web requests from frames, redirects when fitting `matcher`
3333
webRequest.onBeforeRequest.addListener(
34-
redirect,
35-
{
36-
urls: ['<all_urls>'],
37-
types: ['sub_frame'],
38-
},
39-
['blocking']
40-
);
34+
redirect,
35+
{
36+
urls: ['<all_urls>'],
37+
types: ['sub_frame'],
38+
},
39+
['blocking']
40+
)
4141

4242
// listen to tab URL changes
43-
tabs.onUpdated.addListener(updateActiveTabIcon);
43+
tabs.onUpdated.addListener(updateActiveTabIcon)
4444

4545
// listen to tab switching
46-
tabs.onActivated.addListener(updateActiveTabIcon);
46+
tabs.onActivated.addListener(updateActiveTabIcon)
4747

4848
// listen for window switching
49-
windows.onFocusChanged.addListener(updateActiveTabIcon);
49+
windows.onFocusChanged.addListener(updateActiveTabIcon)
5050

5151
// update icon at startup
52-
updateActiveTabIcon();
52+
updateActiveTabIcon()

0 commit comments

Comments
 (0)