import { createObservableHistory } from "mobx-observable-history" ; import { createTab , getManifest , getURL , isOptionsPage } from "./extension" ; export type PageId = "settings" | "theme" | "translate" | "history" ; export const defaultPageId = "settings" ; export interface NavigationParams { page ? : PageId ; } export const navigation = createObservableHistory ( ) ; export async function navigate ( params = { } ) { const searchParams = `?${ new URLSearchParams ( Object . entries ( params ) ) }` ; if ( isOptionsPage ( ) ) { navigation . push ( searchParams ) ; } else { const optionsPage = getURL ( getManifest ( ) . options_ui . page ) ; return createTab ( optionsPage + searchParams ) ; } } export function getParam ( name ) { return navigation . searchParams . get ( name ) ; } export function getParams ( name ) { return navigation . searchParams . getAll ( name ) ; }