Skip to content

Commit

Permalink
lint: chnage rules, cleanup vitest code
Browse files Browse the repository at this point in the history
  • Loading branch information
nobkd committed Jun 25, 2024
1 parent f064723 commit b5d477a
Show file tree
Hide file tree
Showing 25 changed files with 1,000 additions and 1,009 deletions.
20 changes: 10 additions & 10 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"tabWidth": 4,
"useTabs": false,
"endOfLine": "lf",
"bracketSameLine": true,
"bracketSpacing": true,
"semi": true,
"trailingComma": "es5",
"singleQuote": true,
"arrowParens": "always",
"printWidth": 100
"tabWidth": 2,
"useTabs": false,
"endOfLine": "lf",
"bracketSameLine": true,
"bracketSpacing": true,
"semi": false,
"trailingComma": "es5",
"singleQuote": true,
"arrowParens": "always",
"printWidth": 100
}
148 changes: 74 additions & 74 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,80 +1,80 @@
{
"name": "replace_maps",
"description": "Replace Google Maps iFrames with OSM",
"author": "nobkd",
"license": "MPL-2.0",
"version": "0.0.6",
"type": "module",
"private": true,
"homepage": "https://github.com/nobkd/replace-maps#readme",
"bugs": {
"url": "https://github.com/nobkd/replace-maps/issues"
"name": "replace_maps",
"description": "Replace Google Maps iFrames with OSM",
"author": "nobkd",
"license": "MPL-2.0",
"version": "0.0.6",
"type": "module",
"private": true,
"homepage": "https://github.com/nobkd/replace-maps#readme",
"bugs": {
"url": "https://github.com/nobkd/replace-maps/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/nobkd/replace-maps.git"
},
"scripts": {
"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",
"format": "prettier . --check",
"format:fix": "npm run format -- --write",
"test": "vitest run",
"dev": "run-p -rl vite:watch serve:firefox",
"vite:site": "vite",
"vite:watch": "vite build --watch --mode development --minify false",
"build": "tsc && vite build",
"serve:firefox": "web-ext run -s dist",
"serve:chromium": "web-ext run -t chromium -s dist",
"bundle": "web-ext build -s dist -a out --overwrite-dest -n replace_maps.zip",
"release": "release-it"
},
"devDependencies": {
"@types/leaflet": "^1.9.12",
"@types/leaflet-fullscreen": "^1.0.9",
"@types/webextension-polyfill": "^0.10.7",
"npm-run-all": "^4.1.5",
"prettier": "^3.3.2",
"release-it": "^17.4.0",
"release-it-changelogen": "^0.1.0",
"typescript": "^5.5.2",
"vite": "^5.3.1",
"vite-plugin-static-copy": "^1.0.5",
"web-ext": "^8.2.0",
"webextension-polyfill": "^0.12.0"
},
"dependencies": {
"leaflet": "^1.9.4",
"leaflet-fullscreen": "^1.0.2"
},
"release-it": {
"git": {
"tagName": "v${version}",
"commitMessage": "chore(release): v${version}",
"tagAnnotation": "v${version}"
},
"repository": {
"type": "git",
"url": "git+https://github.com/nobkd/replace-maps.git"
"github": {
"release": true,
"releaseName": "v${version}"
},
"scripts": {
"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",
"format": "prettier . --check",
"format:fix": "npm run format -- --write",
"test": "vitest run",
"dev": "run-p -rl vite:watch serve:firefox",
"vite:site": "vite",
"vite:watch": "vite build --watch --mode development --minify false",
"build": "tsc && vite build",
"serve:firefox": "web-ext run -s dist",
"serve:chromium": "web-ext run -t chromium -s dist",
"bundle": "web-ext build -s dist -a out --overwrite-dest -n replace_maps.zip",
"release": "release-it"
},
"devDependencies": {
"@types/leaflet": "^1.9.12",
"@types/leaflet-fullscreen": "^1.0.9",
"@types/webextension-polyfill": "^0.10.7",
"npm-run-all": "^4.1.5",
"prettier": "^3.3.2",
"release-it": "^17.4.0",
"release-it-changelogen": "^0.1.0",
"typescript": "^5.5.2",
"vite": "^5.3.1",
"vite-plugin-static-copy": "^1.0.5",
"web-ext": "^8.2.0",
"webextension-polyfill": "^0.12.0"
},
"dependencies": {
"leaflet": "^1.9.4",
"leaflet-fullscreen": "^1.0.2"
},
"release-it": {
"git": {
"tagName": "v${version}",
"commitMessage": "chore(release): v${version}",
"tagAnnotation": "v${version}"
},
"github": {
"release": true,
"releaseName": "v${version}"
},
"plugins": {
"release-it-changelogen": {
"disableVersion": true,
"templates": {
"commitMessage": "chore(release): v{{newVersion}}",
"tagMessage": "v{{newVersion}}",
"tagBody": "v{{newVersion}}"
}
}
},
"hooks": {
"before:init": [
"npm run format",
"npm test",
"npm run build"
],
"after:bump": [
"sh scripts/bump.sh"
]
"plugins": {
"release-it-changelogen": {
"disableVersion": true,
"templates": {
"commitMessage": "chore(release): v{{newVersion}}",
"tagMessage": "v{{newVersion}}",
"tagBody": "v{{newVersion}}"
}
}
},
"hooks": {
"before:init": [
"npm run format",
"npm test",
"npm run build"
],
"after:bump": [
"sh scripts/bump.sh"
]
}
}
}
74 changes: 37 additions & 37 deletions public/manifest.json
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
{
"description": "Replace Google Maps iFrames with OpenStreetMap",
"manifest_version": 2,
"name": "Replace Maps",
"version": "0.0.6",
"homepage_url": "https://github.com/nobkd/replace-maps",
"icons": {
"48": "icons/48.png",
"96": "icons/96.png"
},
"browser_specific_settings": {
"gecko": {
"id": "[email protected]",
"strict_min_version": "89.0"
}
},
"permissions": [
"tabs",
"webNavigation",
"storage",
"webRequest",
"webRequestBlocking",
"<all_urls>"
],
"background": {
"page": "bg.html"
},
"web_accessible_resources": ["map.html"],
"browser_action": {
"default_icon": {
"48": "icons/48.png",
"96": "icons/96.png"
},
"default_area": "navbar",
"default_title": "Replace Maps"
},
"options_ui": {
"page": "options.html"
"description": "Replace Google Maps iFrames with OpenStreetMap",
"manifest_version": 2,
"name": "Replace Maps",
"version": "0.0.6",
"homepage_url": "https://github.com/nobkd/replace-maps",
"icons": {
"48": "icons/48.png",
"96": "icons/96.png"
},
"browser_specific_settings": {
"gecko": {
"id": "[email protected]",
"strict_min_version": "89.0"
}
},
"permissions": [
"tabs",
"webNavigation",
"storage",
"webRequest",
"webRequestBlocking",
"<all_urls>"
],
"background": {
"page": "bg.html"
},
"web_accessible_resources": ["map.html"],
"browser_action": {
"default_icon": {
"48": "icons/48.png",
"96": "icons/96.png"
},
"default_area": "navbar",
"default_title": "Replace Maps"
},
"options_ui": {
"page": "options.html"
}
}
6 changes: 3 additions & 3 deletions src/bg.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!doctype html>
<head>
<meta charset="UTF-8" />
<script src="bg/action.ts" type="module"></script>
<script src="bg/bg.ts" type="module"></script>
<meta charset="UTF-8" />
<script src="bg/action.ts" type="module"></script>
<script src="bg/bg.ts" type="module"></script>
</head>
16 changes: 8 additions & 8 deletions src/bg/action.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { browserAction, /*webNavigation,*/ type Tabs, tabs } from 'webextension-polyfill';
import { getHostname, invertHostState } from './utils/storage';
import { browserAction, /*webNavigation,*/ type Tabs, tabs } from 'webextension-polyfill'
import { getHostname, invertHostState } from './utils/storage'
//import { matcher as mapsUrlMatcher, runtimeMapUrl } from './bg';

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

let hostname = getHostname(tab.url);
await invertHostState(hostname);
let hostname = getHostname(tab.url)
await invertHostState(hostname)

/*
/*
// TODO: try to only reload necessary parts!!!
let frames = (await webNavigation.getAllFrames({ tabId: tab.id })) ?? [];
Expand All @@ -28,7 +28,7 @@ async function actionClick(tab: Tabs.Tab): Promise<void> {
})
)
*/
tabs.reload(tab.id, { bypassCache: true });
tabs.reload(tab.id, { bypassCache: true })
}

browserAction.onClicked.addListener(actionClick);
browserAction.onClicked.addListener(actionClick)
56 changes: 28 additions & 28 deletions src/bg/bg.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { runtime, tabs, windows, webRequest, type WebRequest } from 'webextension-polyfill';
import { disabledHosts, getHostname } from './utils/storage';
import { updateActiveTabIcon } from './utils/actionIcon';
import { domainEnds } from './utils/domainEnds';
import { runtime, tabs, windows, webRequest, type WebRequest } from 'webextension-polyfill'
import { disabledHosts, getHostname } from './utils/storage'
import { updateActiveTabIcon } from './utils/actionIcon'
import { domainEnds } from './utils/domainEnds'

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

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

// Listens to web requests from frames, redirects when fitting `matcher`
webRequest.onBeforeRequest.addListener(
redirect,
{
urls: ['<all_urls>'],
types: ['sub_frame'],
},
['blocking']
);
redirect,
{
urls: ['<all_urls>'],
types: ['sub_frame'],
},
['blocking']
)

// listen to tab URL changes
tabs.onUpdated.addListener(updateActiveTabIcon);
tabs.onUpdated.addListener(updateActiveTabIcon)

// listen to tab switching
tabs.onActivated.addListener(updateActiveTabIcon);
tabs.onActivated.addListener(updateActiveTabIcon)

// listen for window switching
windows.onFocusChanged.addListener(updateActiveTabIcon);
windows.onFocusChanged.addListener(updateActiveTabIcon)

// update icon at startup
updateActiveTabIcon();
updateActiveTabIcon()
Loading

0 comments on commit b5d477a

Please sign in to comment.