Skip to content

Commit 51fb3b8

Browse files
committed
chore: move ts to js
1 parent 04493de commit 51fb3b8

24 files changed

+230
-235
lines changed

bun.lockb

-32 Bytes
Binary file not shown.

package.json

+2-5
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@
2121
"test": "vitest run",
2222
"test:watch": "vitest",
2323
"test:cov": "vitest run --coverage",
24-
"dev": "run-p -rl vite:watch serve:firefox",
25-
"vite:site": "vite",
26-
"vite:watch": "vite build --watch --mode development --minify false",
27-
"build": "tsc && vite build",
24+
"dev": "run-p -rl 'vite build --watch --mode development --minify false' serve:firefox",
25+
"build": "vite build",
2826
"serve:firefox": "web-ext run -s dist",
2927
"serve:chromium": "web-ext run -t chromium -s dist",
3028
"bundle": "web-ext build -s dist -a out --overwrite-dest -n replace_maps.zip",
@@ -39,7 +37,6 @@
3937
"prettier": "^3.3.2",
4038
"release-it": "^17.4.0",
4139
"release-it-changelogen": "^0.1.0",
42-
"typescript": "^5.5.2",
4340
"vite": "^5.3.2",
4441
"vite-plugin-static-copy": "^1.0.5",
4542
"vitest": "^1.6.0",

src/bg.html

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

src/bg/action.ts renamed to src/bg/action.js

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

@@ -10,9 +10,9 @@ import { getHostname, invertHostState } from './utils/storage'
1010
*
1111
* Requests all frames from the current tab, filters them for extension Leaflet frames and Maps frames.
1212
* Reloads the full tab on extension Leaflet or Maps frame match.
13-
* @param tab Currently active tab
13+
* @param {Tabs.Tab} tab Currently active tab
1414
*/
15-
async function actionClick(tab: Tabs.Tab): Promise<void> {
15+
async function actionClick(tab) {
1616
if (!tab.url || !tab.id) return
1717

1818
let hostname = getHostname(tab.url)

src/bg/bg.ts renamed to src/bg/bg.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { runtime, tabs, windows, webRequest, type WebRequest } from 'webextension-polyfill'
1+
import { runtime, tabs, windows, webRequest, WebRequest } from 'webextension-polyfill'
22
import { disabledHosts, getHostname } from './utils/storage'
33
import { updateActiveTabIcon } from './utils/actionIcon'
44
import { domainEnds } from './utils/domainEnds'
55

6-
const gLocales: string = domainEnds.join('|') // TODO: collect more locales
7-
export const matcher: RegExp = new RegExp(
6+
const gLocales = domainEnds.join('|') // TODO: collect more locales
7+
export const matcher = new RegExp(
88
// TODO: fix regex to fit more patterns
99
`^(https?:\/\/)?(maps\.google\.(${gLocales})\/maps.*\?.*output=embed|(www\.)?google\.(${gLocales})\/maps\/embed.*\?)`
1010
)
@@ -14,10 +14,10 @@ export const runtimeMapUrl = runtime.getURL('map.html')
1414
* Checks if `frames` send a request to Maps.
1515
* 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.
1616
* Else the request is'nt blocked.
17-
* @param req Web Request from frame
18-
* @returns Redirect to extension map or pass through if extension disabled for website
17+
* @param {WebRequest.OnBeforeRequestDetailsType} req Web Request from frame
18+
* @returns {WebRequest.BlockingResponse} Redirect to extension map or pass through if extension disabled for website
1919
*/
20-
function redirect(req: WebRequest.OnBeforeRequestDetailsType): WebRequest.BlockingResponse {
20+
function redirect(req) {
2121
// TODO: check if originUrl always matches current tab url -> e.g. in frames with subframes
2222
if (req.originUrl && req.url.match(matcher)) {
2323
if (!disabledHosts.includes(getHostname(req.originUrl))) {

src/bg/utils/actionIcon.ts renamed to src/bg/utils/actionIcon.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { disabledHosts, getHostname } from './storage'
33

44
/**
55
* Updates the action icon
6-
* @param hostname Hostname
6+
* @param {string} hostname Hostname
77
*/
8-
export function updateIcon(hostname: string): void {
8+
export function updateIcon(hostname) {
99
let disabled = disabledHosts.includes(hostname)
1010

1111
browserAction.setIcon({
@@ -24,7 +24,7 @@ export function updateIcon(hostname: string): void {
2424
/**
2525
* Async function to update the icon of the currently active tab. Uses `updateIcon` internally
2626
*/
27-
export async function updateActiveTabIcon(): Promise<void> {
27+
export async function updateActiveTabIcon() {
2828
let browserTabs = await tabs.query({ active: true, currentWindow: true })
2929

3030
let tab = browserTabs[0]

src/bg/utils/domainEnds.ts renamed to src/bg/utils/domainEnds.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Domain ends of google
2-
export const domainEnds: string[] = [
2+
export const domainEnds = [
33
'com',
44
'ac',
55
'ad',

src/bg/utils/storage.ts renamed to src/bg/utils/storage.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import { updateIcon } from './actionIcon'
44
export const KEY_DISABLED_HOSTS = 'disabled_hosts'
55

66
// Listens to changes on the storage. Updates disabled hosts list, if stored list changes
7-
export let disabledHosts: string[] = await getDisabledHosts()
7+
/** @type {string[]} */
8+
export let disabledHosts = await getDisabledHosts()
89
storage.local.onChanged.addListener((changes) => {
910
if (KEY_DISABLED_HOSTS in changes) {
1011
disabledHosts = changes[KEY_DISABLED_HOSTS].newValue ?? []
@@ -13,18 +14,18 @@ storage.local.onChanged.addListener((changes) => {
1314

1415
/**
1516
* Async function to get the list of disabled hostnames
16-
* @returns List of disabled hostnames
17+
* @returns {Promise<string[]>} List of disabled hostnames
1718
*/
18-
async function getDisabledHosts(): Promise<string[]> {
19+
async function getDisabledHosts() {
1920
return (await storage.local.get(KEY_DISABLED_HOSTS))[KEY_DISABLED_HOSTS] ?? []
2021
}
2122

2223
/**
2324
* Async function to invert the state of a hostname.
2425
* Adds new entry if not disabled, removes entry, if already disabled
25-
* @param hostname Hostname to invert the state of
26+
* @param {string} hostname Hostname to invert the state of
2627
*/
27-
export async function invertHostState(hostname: string): Promise<void> {
28+
export async function invertHostState(hostname) {
2829
if (disabledHosts.includes(hostname)) {
2930
disabledHosts.splice(disabledHosts.indexOf(hostname), 1)
3031
} else {
@@ -40,10 +41,10 @@ export async function invertHostState(hostname: string): Promise<void> {
4041

4142
/**
4243
* Retrieves the hostname from a URL
43-
* @param url Full URL string
44-
* @returns Hostname string
44+
* @param {string} url Full URL string
45+
* @returns {string} Hostname string
4546
*/
46-
export function getHostname(url: string): string {
47+
export function getHostname(url) {
4748
url = url.replace(/^\w+:\/\//, '')
4849
url = url.split(/[\/#\?]/, 1)[0]
4950
return url

src/map.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212

1313
<body>
1414
<div id="map"></div>
15-
<script src="map/map.ts" type="module"></script>
15+
<script src="map/map.js" type="module"></script>
1616
</body>
1717
</html>

src/map/map.ts renamed to src/map/map.js

+20-18
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import L from 'leaflet'
22
import 'leaflet-fullscreen'
33

4-
import { readPB, readQ, type MapData } from './utils/read'
5-
import { type TileType, tileTypes } from './utils/parsePB'
4+
import { readPB, readQ, MapData } from './utils/read'
5+
import { tileTypes } from './utils/parsePB'
66

7-
type Tiles = {
8-
[K in TileType]: {
9-
layer: string
10-
attr: string
11-
}
12-
}
7+
/**
8+
* @typedef {object} Tile
9+
* @property {string} layer
10+
* @property {string} attr
11+
*/
1312

1413
// https://leaflet-extras.github.io/leaflet-providers/preview/
15-
const tileProviders: Tiles = {
14+
/** @type {{TileTypes: Tile}} */
15+
const tileProviders = {
1616
roadmap: {
1717
layer: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png', // OpenStreetMap.Mapnik
1818
attr: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
@@ -24,28 +24,30 @@ const tileProviders: Tiles = {
2424
}, // TODO: add street layer etc to satellite
2525
}
2626

27-
const gPos: string = 'pb'
28-
const gQuery: string = 'q'
29-
const gZoom: string = 'z'
30-
const params: URLSearchParams = new URLSearchParams(document.location.search)
27+
const gPos = 'pb'
28+
const gQuery = 'q'
29+
const gZoom = 'z'
30+
const params = new URLSearchParams(document.location.search)
3131

32-
let mapData: MapData = {}
32+
/** @type {MapData} */
33+
const mapData = {}
3334

3435
if (params.has(gPos)) {
35-
mapData = await readPB(params.get(gPos) as string)
36+
mapData = await readPB(params.get(gPos))
3637
} else if (params.has(gQuery)) {
37-
let marker = await readQ(params.get(gQuery) as string)
38+
let marker = await readQ(params.get(gQuery))
3839

3940
if (marker) {
4041
mapData.markers = [marker]
4142
}
4243
}
4344

4445
if (params.has(gZoom)) {
45-
mapData.zoom = parseInt(params.get(gZoom) as string)
46+
mapData.zoom = parseInt(params.get(gZoom))
4647
}
4748

48-
const map: L.Map = L.map('map', {
49+
/** @type {L.Map} */
50+
const map = L.map('map', {
4951
fullscreenControl: true,
5052
scrollWheelZoom: true, // TODO: on pc allow ctrl + scroll
5153
zoom: mapData.zoom ?? 17,

src/map/utils/parseDMS.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Converts DMS coordinates to Lat and Lon
3+
* @param {string} input String containing DMS coordinates
4+
* @returns {[number, number]} Array containing Latitude and Longitude
5+
*/
6+
export function parseDMS(input) {
7+
/** @type {string[]} */
8+
const parts = input.split(/[^\d\w\.]+/)
9+
const lat = convertDMSToDD(parts.slice(0, 4))
10+
const lon = convertDMSToDD(parts.slice(4))
11+
12+
return [lat, lon]
13+
}
14+
/**
15+
* Converts DMS part to Lat/Lon
16+
* @param {string[]} dms Array of four strings representing: Degree Minutes Seconds Direction
17+
* @returns {number} DMS part converted to Latitude / Longitude
18+
*/
19+
function convertDMSToDD(dms) {
20+
const [degrees, minutes, seconds, direction] = dms
21+
let dd = Number(degrees) + Number(minutes) / 60 + Number(seconds) / (60 * 60)
22+
23+
if (direction === 'S' || direction === 'W') {
24+
dd = dd * -1
25+
} // Don't do anything for N or E
26+
return dd
27+
}

src/map/utils/parseDMS.ts

-26
This file was deleted.

src/map/utils/parsePB.ts renamed to src/map/utils/parsePB.js

+18-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
export type TileType = 'roadmap' | 'satellite'
2-
export const tileTypes: TileType[] = ['roadmap', 'satellite']
1+
/**
2+
* @typedef {'roadmap' | 'satellite'} TileType
3+
* @type {TileType[]}
4+
*/
5+
export const tileTypes = ['roadmap', 'satellite']
36

47
/**
58
* Takes one bang operator and decodes it.
@@ -17,16 +20,18 @@ export const tileTypes: TileType[] = ['roadmap', 'satellite']
1720
*
1821
* Unknown types are kept as string.
1922
*
20-
* @param item One bang operator with the structure: position, one character (data type), encoded data
21-
* @returns Array of two items. First is the decoded result. Second describes if the result is a new matrix.
23+
* @param {string} item One bang operator with the structure: position, one character (data type), encoded data
24+
* @returns {[string | TileType | number, boolean]} Array of two items. First is the decoded result. Second describes if the result is a new matrix.
2225
*/
23-
function convertType(item: string): [string | TileType | number, boolean] {
26+
function convertType(item) {
2427
item = item.replace(/^\d+/, '')
25-
const type: string = item.charAt(0)
28+
/** @type {string} */
29+
const type = item.charAt(0)
2630
item = item.substring(1)
2731

2832
// s: string || v: timestamp || b: boolean?/byte?
29-
let val: string | TileType | number = item
33+
/** @type {string | TileType | number} */
34+
let val = item
3035

3136
switch (type) {
3237
case 'f':
@@ -66,21 +71,21 @@ function convertType(item: string): [string | TileType | number, boolean] {
6671
* - https://andrewwhitby.com/2014/09/09/google-maps-new-embed-format/
6772
* - https://blog.themillhousegroup.com/2016/08/deep-diving-into-google-pb-embedded-map.html
6873
* - https://stackoverflow.com/a/47042514
69-
* @param items Bang operators (e.g. `!1m13`) split into pieces at `!`
70-
* @param out Array for top and recursion levels to save results and return
71-
* @returns Filled `out` array with bang operators converted into readable format
74+
* @param {string[]} items Bang operators (e.g. `!1m13`) split into pieces at `!`
75+
* @param {any[]} out Array for top and recursion levels to save results and return
76+
* @returns {any[]} Filled `out` array with bang operators converted into readable format
7277
*/
73-
export function parsePB(items: string[], out: any[] = []): any[] {
78+
export function parsePB(items, out = []) {
7479
let i = 0
7580
while (i < items.length) {
7681
let [val, isNew] = convertType(items[i])
7782

7883
if (!isNew) {
7984
out.push(val)
8085
} else {
81-
let itemsPart = items.slice(i + 1, i + (val as number) + 1)
86+
let itemsPart = items.slice(i + 1, i + val + 1)
8287
out.push(parsePB(itemsPart))
83-
i += val as number
88+
i += val
8489
}
8590
i++
8691
}

0 commit comments

Comments
 (0)