Skip to content

Commit

Permalink
docs: add JS-Doc to rest of functions
Browse files Browse the repository at this point in the history
  • Loading branch information
nobkd committed May 6, 2023
1 parent faa7327 commit 1b65966
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 38 deletions.
12 changes: 10 additions & 2 deletions src/bg/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@ import { matcher, runtimeMapUrl } from './bg';
const replacedUrlMatcher = new RegExp(`^${runtimeMapUrl}\?`);

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

let hostname = getHostname(tab.url);
Expand All @@ -29,4 +35,6 @@ browserAction.onClicked.addListener(async (tab: Tabs.Tab) => {
code: 'document.location.reload();',
});
});
});
}

browserAction.onClicked.addListener(actionClick);
10 changes: 5 additions & 5 deletions src/bg/utils/actionIcon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { browserAction, tabs } from 'webextension-polyfill';
import { disabledHosts, getHostname } from './storage';

/**
*
* @param hostname
* Updates the action icon
* @param hostname Hostname
*/
export function updateIcon(hostname: string) {
export function updateIcon(hostname: string): void {
let disabled = disabledHosts.includes(hostname);

browserAction.setIcon({
Expand All @@ -22,9 +22,9 @@ export function updateIcon(hostname: string) {
}

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

let tab = browserTabs[0];
Expand Down
17 changes: 9 additions & 8 deletions src/bg/utils/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { updateIcon } from './actionIcon';

export const KEY_DISABLED_HOSTS = 'disabled_hosts';

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

/**
*
* @returns
* Async function to get the list of disabled hostnames
* @returns List of disabled hostnames
*/
async function getDisabledHosts(): Promise<string[]> {
return (await storage.local.get(KEY_DISABLED_HOSTS))[KEY_DISABLED_HOSTS] ?? [];
}

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

/**
*
* @param url
* @returns
* Retrieves the hostname from a URL
* @param url Full URL string
* @returns Hostname string
*/
export function getHostname(url: string): string {
url = url.replace(/^\w+:\/\//, '');
Expand Down
6 changes: 3 additions & 3 deletions src/map/utils/read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ export type MapData = {
};

/**
*
* @param param
* @returns
* Decodes the `pb` parameter with the help of `parsePB` and `readQ`
* @param param Content of the `pb` parameter as a string
* @returns MapData with area, zoom, tile type and markers
*/
export async function readPB(param: string): Promise<MapData> {
let mapData: MapData = {
Expand Down
8 changes: 4 additions & 4 deletions src/map/utils/zoom.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// https://groups.google.com/g/google-earth-browser-plugin/c/eSL9GlAkWBk/m/T4mdToJz_FgJ

const factor: number = 35200000;
const precision: number = 10;

/**
* Converts *altitude over the map* to *zoom level of the map*
*
* @param alt
* @returns
* Reference: https://groups.google.com/g/google-earth-browser-plugin/c/eSL9GlAkWBk/m/T4mdToJz_FgJ
* @param alt Altitude as number
* @returns Zoom level between 0 and 19
*/
export function getMapZoom(alt: number): number {
let zoom = Math.log2(factor / alt) * 1.225;
Expand Down
32 changes: 16 additions & 16 deletions src/options/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ import {
const table = document.querySelector('.table')!;

/**
*
* (Re)Builds the list of diasabled hostnames
*/
function buildEntries() {
function buildEntries(): void {
table.innerHTML = '';
disabledHosts.forEach(createEntry);
}

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

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

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

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

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

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

Expand Down

0 comments on commit 1b65966

Please sign in to comment.