Skip to content

Commit 1b65966

Browse files
committed
docs: add JS-Doc to rest of functions
1 parent faa7327 commit 1b65966

File tree

6 files changed

+47
-38
lines changed

6 files changed

+47
-38
lines changed

src/bg/action.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,15 @@ import { matcher, runtimeMapUrl } from './bg';
55
const replacedUrlMatcher = new RegExp(`^${runtimeMapUrl}\?`);
66

77
/**
8+
* Async function to react to clicks on the browser action icon.
9+
* Takes the current tab, takes its hostname and inverts the state of the hostname.
810
*
11+
* Requests all frames from the current tab, filters them for extension Leaflet frames and Maps frames.
12+
* Reloads the full tab on extension Leaflet frame match.
13+
* If no extension Leaflet frames were found it just reloads the Maps frames
14+
* @param tab Currently active tab
915
*/
10-
browserAction.onClicked.addListener(async (tab: Tabs.Tab) => {
16+
async function actionClick(tab: Tabs.Tab): Promise<void> {
1117
if (!tab.url || !tab.id) return;
1218

1319
let hostname = getHostname(tab.url);
@@ -29,4 +35,6 @@ browserAction.onClicked.addListener(async (tab: Tabs.Tab) => {
2935
code: 'document.location.reload();',
3036
});
3137
});
32-
});
38+
}
39+
40+
browserAction.onClicked.addListener(actionClick);

src/bg/utils/actionIcon.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { browserAction, tabs } from 'webextension-polyfill';
22
import { disabledHosts, getHostname } from './storage';
33

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

1111
browserAction.setIcon({
@@ -22,9 +22,9 @@ export function updateIcon(hostname: string) {
2222
}
2323

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

3030
let tab = browserTabs[0];

src/bg/utils/storage.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { updateIcon } from './actionIcon';
33

44
export const KEY_DISABLED_HOSTS = 'disabled_hosts';
55

6-
//
6+
// Listens to changes on the storage. Updates disabled hosts list, if stored list changes
77
export let disabledHosts: string[] = await getDisabledHosts();
88
storage.local.onChanged.addListener((changes) => {
99
if (KEY_DISABLED_HOSTS in changes) {
@@ -12,16 +12,17 @@ storage.local.onChanged.addListener((changes) => {
1212
});
1313

1414
/**
15-
*
16-
* @returns
15+
* Async function to get the list of disabled hostnames
16+
* @returns List of disabled hostnames
1717
*/
1818
async function getDisabledHosts(): Promise<string[]> {
1919
return (await storage.local.get(KEY_DISABLED_HOSTS))[KEY_DISABLED_HOSTS] ?? [];
2020
}
2121

2222
/**
23-
*
24-
* @param hostname
23+
* Async function to invert the state of a hostname.
24+
* Adds new entry if not disabled, removes entry, if already disabled
25+
* @param hostname Hostname to invert the state of
2526
*/
2627
export async function invertHostState(hostname: string): Promise<void> {
2728
if (disabledHosts.includes(hostname)) {
@@ -38,9 +39,9 @@ export async function invertHostState(hostname: string): Promise<void> {
3839
}
3940

4041
/**
41-
*
42-
* @param url
43-
* @returns
42+
* Retrieves the hostname from a URL
43+
* @param url Full URL string
44+
* @returns Hostname string
4445
*/
4546
export function getHostname(url: string): string {
4647
url = url.replace(/^\w+:\/\//, '');

src/map/utils/read.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ export type MapData = {
2525
};
2626

2727
/**
28-
*
29-
* @param param
30-
* @returns
28+
* Decodes the `pb` parameter with the help of `parsePB` and `readQ`
29+
* @param param Content of the `pb` parameter as a string
30+
* @returns MapData with area, zoom, tile type and markers
3131
*/
3232
export async function readPB(param: string): Promise<MapData> {
3333
let mapData: MapData = {

src/map/utils/zoom.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
// https://groups.google.com/g/google-earth-browser-plugin/c/eSL9GlAkWBk/m/T4mdToJz_FgJ
2-
31
const factor: number = 35200000;
42
const precision: number = 10;
53

64
/**
5+
* Converts *altitude over the map* to *zoom level of the map*
76
*
8-
* @param alt
9-
* @returns
7+
* Reference: https://groups.google.com/g/google-earth-browser-plugin/c/eSL9GlAkWBk/m/T4mdToJz_FgJ
8+
* @param alt Altitude as number
9+
* @returns Zoom level between 0 and 19
1010
*/
1111
export function getMapZoom(alt: number): number {
1212
let zoom = Math.log2(factor / alt) * 1.225;

src/options/options.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ import {
99
const table = document.querySelector('.table')!;
1010

1111
/**
12-
*
12+
* (Re)Builds the list of diasabled hostnames
1313
*/
14-
function buildEntries() {
14+
function buildEntries(): void {
1515
table.innerHTML = '';
1616
disabledHosts.forEach(createEntry);
1717
}
1818

1919
/**
20-
*
21-
* @returns
20+
* Async function to add a hostname (from the form / URL Search Params) to the displayed list and the storage list of disabled hosts
21+
* If the entry is already present in the stored hosts, no entry is added to the display list
2222
*/
23-
async function addEntry() {
23+
async function addEntry(): Promise<void> {
2424
const search = new URLSearchParams(document.location.search);
2525
let hostname = search.get('hostname');
2626
if (hostname === null) return;
@@ -33,10 +33,10 @@ async function addEntry() {
3333
}
3434

3535
/**
36-
*
37-
* @param hostname
36+
* Creates a new entry for the displayed list of disabled hostnames and appends it to the view
37+
* @param hostname Hostname to add to the list
3838
*/
39-
function createEntry(hostname: string) {
39+
function createEntry(hostname: string): void {
4040
const div = document.createElement('div');
4141

4242
let span = document.createElement('span');
@@ -50,11 +50,11 @@ function createEntry(hostname: string) {
5050
}
5151

5252
/**
53-
*
54-
* @param click
55-
* @returns
53+
* Async funtion to remove an entry at click of its button.
54+
* Takes the index in the table to remove it from the list of stored hostnames
55+
* @param click Button click
5656
*/
57-
async function removeEntry(click: MouseEvent) {
57+
async function removeEntry(click: MouseEvent): Promise<void> {
5858
let target: EventTarget | null = click.target;
5959
if (target === null) return;
6060

@@ -65,11 +65,11 @@ async function removeEntry(click: MouseEvent) {
6565
}
6666

6767
/**
68-
*
69-
* @param button
70-
* @returns
68+
* Gets the index of a list entry using its clicked button
69+
* @param button Button that was clicked to remove an entry
70+
* @returns Index of the list entry
7171
*/
72-
function getIndex(button: HTMLButtonElement) {
72+
function getIndex(button: HTMLButtonElement): number {
7373
let div: HTMLDivElement = button.parentElement as HTMLDivElement;
7474
if (div === null) return -1;
7575

0 commit comments

Comments
 (0)