diff options
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/Command.ts | 56 | ||||
-rw-r--r-- | src/shared/CompletionType.ts | 2 | ||||
-rw-r--r-- | src/shared/SettingData.ts | 155 | ||||
-rw-r--r-- | src/shared/TabFlag.ts | 8 | ||||
-rw-r--r-- | src/shared/messages.ts | 297 | ||||
-rw-r--r-- | src/shared/operations.ts | 480 | ||||
-rw-r--r-- | src/shared/settings/Blacklist.ts | 39 | ||||
-rw-r--r-- | src/shared/settings/Key.ts | 20 | ||||
-rw-r--r-- | src/shared/settings/Keymaps.ts | 21 | ||||
-rw-r--r-- | src/shared/settings/Properties.ts | 47 | ||||
-rw-r--r-- | src/shared/settings/Search.ts | 10 | ||||
-rw-r--r-- | src/shared/settings/Settings.ts | 31 | ||||
-rw-r--r-- | src/shared/urls.ts | 24 | ||||
-rw-r--r-- | src/shared/utils/dom.ts | 55 |
14 files changed, 625 insertions, 620 deletions
diff --git a/src/shared/Command.ts b/src/shared/Command.ts index b8c21ce..05b8b83 100644 --- a/src/shared/Command.ts +++ b/src/shared/Command.ts @@ -1,40 +1,40 @@ export enum Command { - Open = "open", - TabOpen = "tabopen", - WindowOpen = "winopen", - Buffer = "buffer", - BufferDelete = "bdelete", - BufferDeleteForce = "bdelete!", - BuffersDelete = "bdeletes", - BuffersDeleteForce = "bdeletes!", - AddBookmark = "addbookmark", - Quit = "quit", - QuitAll = "quitall", - Set = "set", - Help = "help", + Open = "open", + TabOpen = "tabopen", + WindowOpen = "winopen", + Buffer = "buffer", + BufferDelete = "bdelete", + BufferDeleteForce = "bdelete!", + BuffersDelete = "bdeletes", + BuffersDeleteForce = "bdeletes!", + AddBookmark = "addbookmark", + Quit = "quit", + QuitAll = "quitall", + Set = "set", + Help = "help", } export namespace Command { export function members(): Command[] { return [ - Command.Open , - Command.TabOpen , - Command.WindowOpen , - Command.Buffer , - Command.BufferDelete , - Command.BufferDeleteForce , - Command.BuffersDelete , - Command.BuffersDeleteForce , - Command.AddBookmark , - Command.Quit , - Command.QuitAll , - Command.Set , - Command.Help , - ] + Command.Open, + Command.TabOpen, + Command.WindowOpen, + Command.Buffer, + Command.BufferDelete, + Command.BufferDeleteForce, + Command.BuffersDelete, + Command.BuffersDeleteForce, + Command.AddBookmark, + Command.Quit, + Command.QuitAll, + Command.Set, + Command.Help, + ]; } export function valueOf(value: string): Command { - const map = new Map(members().map(cmd => [cmd.toString(), cmd])); + const map = new Map(members().map((cmd) => [cmd.toString(), cmd])); const cmd = map.get(value); if (!cmd) { throw new Error(`unknown command '${value}`); diff --git a/src/shared/CompletionType.ts b/src/shared/CompletionType.ts index e104455..8ca04a7 100644 --- a/src/shared/CompletionType.ts +++ b/src/shared/CompletionType.ts @@ -4,4 +4,4 @@ enum CompletionType { Bookmarks, } -export default CompletionType;
\ No newline at end of file +export default CompletionType; diff --git a/src/shared/SettingData.ts b/src/shared/SettingData.ts index 5ad360e..a7bdf80 100644 --- a/src/shared/SettingData.ts +++ b/src/shared/SettingData.ts @@ -1,21 +1,21 @@ -import * as operations from './operations'; -import Settings, { DefaultSettingJSONText } from './settings/Settings'; -import Keymaps from './settings/Keymaps'; -import Search from './settings/Search'; -import Properties from './settings/Properties'; -import Blacklist from './settings/Blacklist'; +import * as operations from "./operations"; +import Settings, { DefaultSettingJSONText } from "./settings/Settings"; +import Keymaps from "./settings/Keymaps"; +import Search from "./settings/Search"; +import Properties from "./settings/Properties"; +import Blacklist from "./settings/Blacklist"; export class FormKeymaps { - private readonly data: {[op: string]: string}; + private readonly data: { [op: string]: string }; - private constructor(data: {[op: string]: string}) { + private constructor(data: { [op: string]: string }) { this.data = data; } toKeymaps(): Keymaps { const keymaps: { [key: string]: operations.Operation } = {}; for (const name of Object.keys(this.data)) { - const [type, argStr] = name.split('?'); + const [type, argStr] = name.split("?"); let args = {}; if (argStr) { args = JSON.parse(argStr); @@ -26,7 +26,7 @@ export class FormKeymaps { return Keymaps.fromJSON(keymaps); } - toJSON(): {[op: string]: string} { + toJSON(): { [op: string]: string } { return this.data; } @@ -38,8 +38,8 @@ export class FormKeymaps { return new FormKeymaps(newData); } - static fromJSON(o: ReturnType<FormKeymaps['toJSON']>): FormKeymaps { - const data: {[op: string]: string} = {}; + static fromJSON(o: ReturnType<FormKeymaps["toJSON"]>): FormKeymaps { + const data: { [op: string]: string } = {}; for (const op of Object.keys(o)) { data[op] = o[op] as string; } @@ -48,7 +48,7 @@ export class FormKeymaps { static fromKeymaps(keymaps: Keymaps): FormKeymaps { const json = keymaps.toJSON(); - const data: {[op: string]: string} = {}; + const data: { [op: string]: string } = {}; for (const key of Object.keys(json)) { const op = json[key]; const args = { ...op }; @@ -56,7 +56,7 @@ export class FormKeymaps { let name = op.type; if (Object.keys(args).length > 0) { - name += '?' + JSON.stringify(args); + name += "?" + JSON.stringify(args); } data[name] = key; } @@ -85,18 +85,18 @@ export class FormSearch { toJSON(): { default: string; engines: string[][]; - } { + } { return { default: this.default, engines: this.engines, }; } - static fromJSON(o: ReturnType<FormSearch['toJSON']>): FormSearch { - if (!Object.prototype.hasOwnProperty.call(o, 'default')) { + static fromJSON(o: ReturnType<FormSearch["toJSON"]>): FormSearch { + if (!Object.prototype.hasOwnProperty.call(o, "default")) { throw new TypeError(`"default" field not set`); } - if (!Object.prototype.hasOwnProperty.call(o, 'engines')) { + if (!Object.prototype.hasOwnProperty.call(o, "engines")) { throw new TypeError(`"engines" field not set`); } return new FormSearch(o.default, o.engines); @@ -106,16 +106,15 @@ export class FormSearch { const engines = Object.entries(search.engines).reduce( (o: string[][], [name, url]) => { return o.concat([[name, url]]); - }, []); + }, + [] + ); return new FormSearch(search.defaultEngine, engines); } } export class JSONTextSettings { - constructor( - private json: string, - ) { - } + constructor(private json: string) {} toSettings(): Settings { return Settings.fromJSON(JSON.parse(this.json)); @@ -153,7 +152,7 @@ export class FormSettings { keymaps: FormKeymaps, search: FormSearch, properties: Properties, - blacklist: Blacklist, + blacklist: Blacklist ) { this.keymaps = keymaps; this.search = search; @@ -166,7 +165,7 @@ export class FormSettings { keymaps, this.search, this.properties, - this.blacklist, + this.blacklist ); } @@ -175,17 +174,12 @@ export class FormSettings { this.keymaps, search, this.properties, - this.blacklist, + this.blacklist ); } buildWithProperties(props: Properties): FormSettings { - return new FormSettings( - this.keymaps, - this.search, - props, - this.blacklist, - ); + return new FormSettings(this.keymaps, this.search, props, this.blacklist); } buildWithBlacklist(blacklist: Blacklist): FormSettings { @@ -193,7 +187,7 @@ export class FormSettings { this.keymaps, this.search, this.properties, - blacklist, + blacklist ); } @@ -207,11 +201,11 @@ export class FormSettings { } toJSON(): { - keymaps: ReturnType<FormKeymaps['toJSON']>; - search: ReturnType<FormSearch['toJSON']>; - properties: ReturnType<Properties['toJSON']>; - blacklist: ReturnType<Blacklist['toJSON']>; - } { + keymaps: ReturnType<FormKeymaps["toJSON"]>; + search: ReturnType<FormSearch["toJSON"]>; + properties: ReturnType<Properties["toJSON"]>; + blacklist: ReturnType<Blacklist["toJSON"]>; + } { return { keymaps: this.keymaps.toJSON(), search: this.search.toJSON(), @@ -220,8 +214,8 @@ export class FormSettings { }; } - static fromJSON(o: ReturnType<FormSettings['toJSON']>): FormSettings { - for (const name of ['keymaps', 'search', 'properties', 'blacklist']) { + static fromJSON(o: ReturnType<FormSettings["toJSON"]>): FormSettings { + for (const name of ["keymaps", "search", "properties", "blacklist"]) { if (!Object.prototype.hasOwnProperty.call(o, name)) { throw new Error(`"${name}" field not set`); } @@ -230,7 +224,7 @@ export class FormSettings { FormKeymaps.fromJSON(o.keymaps), FormSearch.fromJSON(o.search), Properties.fromJSON(o.properties), - Blacklist.fromJSON(o.blacklist), + Blacklist.fromJSON(o.blacklist) ); } @@ -239,13 +233,14 @@ export class FormSettings { FormKeymaps.fromKeymaps(data.keymaps), FormSearch.fromSearch(data.search), data.properties, - data.blacklist); + data.blacklist + ); } } export enum SettingSource { - JSON = 'json', - Form = 'form', + JSON = "json", + Form = "form", } export default class SettingData { @@ -256,11 +251,13 @@ export default class SettingData { private form?: FormSettings; constructor({ - source, json, form + source, + json, + form, }: { - source: SettingSource, - json?: JSONTextSettings, - form?: FormSettings, + source: SettingSource; + json?: JSONTextSettings; + form?: FormSettings; }) { this.source = source; this.json = json; @@ -273,40 +270,40 @@ export default class SettingData { getJSON(): JSONTextSettings { if (!this.json) { - throw new TypeError('json settings not set'); + throw new TypeError("json settings not set"); } return this.json; } getForm(): FormSettings { if (!this.form) { - throw new TypeError('form settings not set'); + throw new TypeError("form settings not set"); } return this.form; } toJSON(): any { switch (this.source) { - case SettingSource.JSON: - return { - source: this.source, - json: (this.json as JSONTextSettings).toJSONText(), - }; - case SettingSource.Form: - return { - source: this.source, - form: (this.form as FormSettings).toJSON(), - }; + case SettingSource.JSON: + return { + source: this.source, + json: (this.json as JSONTextSettings).toJSONText(), + }; + case SettingSource.Form: + return { + source: this.source, + form: (this.form as FormSettings).toJSON(), + }; } throw new Error(`unknown settings source: ${this.source}`); } toSettings(): Settings { switch (this.source) { - case SettingSource.JSON: - return this.getJSON().toSettings(); - case SettingSource.Form: - return this.getForm().toSettings(); + case SettingSource.JSON: + return this.getJSON().toSettings(); + case SettingSource.Form: + return this.getForm().toSettings(); } throw new Error(`unknown settings source: ${this.source}`); } @@ -314,27 +311,29 @@ export default class SettingData { static fromJSON(o: { source: string; json?: string; - form?: ReturnType<FormSettings['toJSON']>; + form?: ReturnType<FormSettings["toJSON"]>; }): SettingData { switch (o.source) { - case SettingSource.JSON: - return new SettingData({ - source: o.source, - json: JSONTextSettings.fromText( - o.json as ReturnType<JSONTextSettings['toJSONText']>), - }); - case SettingSource.Form: - return new SettingData({ - source: o.source, - form: FormSettings.fromJSON( - o.form as ReturnType<FormSettings['toJSON']>), - }); + case SettingSource.JSON: + return new SettingData({ + source: o.source, + json: JSONTextSettings.fromText( + o.json as ReturnType<JSONTextSettings["toJSONText"]> + ), + }); + case SettingSource.Form: + return new SettingData({ + source: o.source, + form: FormSettings.fromJSON( + o.form as ReturnType<FormSettings["toJSON"]> + ), + }); } throw new Error(`unknown settings source: ${o.source}`); } } export const DefaultSettingData: SettingData = SettingData.fromJSON({ - source: 'json', + source: "json", json: DefaultSettingJSONText, }); diff --git a/src/shared/TabFlag.ts b/src/shared/TabFlag.ts index b10d5c6..eb4e116 100644 --- a/src/shared/TabFlag.ts +++ b/src/shared/TabFlag.ts @@ -1,7 +1,7 @@ enum TabFlag { - CurrentTab = '%', - LastTab = '#', - None = '', + CurrentTab = "%", + LastTab = "#", + None = "", } -export default TabFlag
\ No newline at end of file +export default TabFlag; diff --git a/src/shared/messages.ts b/src/shared/messages.ts index edb7935..f876b99 100644 --- a/src/shared/messages.ts +++ b/src/shared/messages.ts @@ -1,58 +1,59 @@ -import * as operations from './operations'; +import * as operations from "./operations"; import CompletionType from "./CompletionType"; import TabFlag from "./TabFlag"; -export const BACKGROUND_OPERATION = 'background.operation'; - -export const CONSOLE_UNFOCUS = 'console.unfocus'; -export const CONSOLE_ENTER_COMMAND = 'console.enter.command'; -export const CONSOLE_ENTER_FIND = 'console.enter.find'; -export const CONSOLE_SHOW_COMMAND = 'console.show.command'; -export const CONSOLE_SHOW_ERROR = 'console.show.error'; -export const CONSOLE_SHOW_INFO = 'console.show.info'; -export const CONSOLE_SHOW_FIND = 'console.show.find'; -export const CONSOLE_HIDE = 'console.hide'; -export const CONSOLE_GET_COMPLETION_TYPES = 'console.get.completion.types'; -export const CONSOLE_REQUEST_SEARCH_ENGINES_MESSAGE = 'console.qresut.searchEngines'; -export const CONSOLE_REQUEST_BOOKMARKS = 'console.request.bookmarks'; -export const CONSOLE_REQUEST_HISTORY = 'console.request.history'; -export const CONSOLE_REQUEST_TABS = 'console.request.tabs'; -export const CONSOLE_GET_PROPERTIES = 'console.get.properties'; - -export const FOLLOW_START = 'follow.start'; -export const FOLLOW_REQUEST_COUNT_TARGETS = 'follow.request.count.targets'; -export const FOLLOW_RESPONSE_COUNT_TARGETS = 'follow.response.count.targets'; -export const FOLLOW_CREATE_HINTS = 'follow.create.hints'; -export const FOLLOW_SHOW_HINTS = 'follow.update.hints'; -export const FOLLOW_REMOVE_HINTS = 'follow.remove.hints'; -export const FOLLOW_ACTIVATE = 'follow.activate'; -export const FOLLOW_KEY_PRESS = 'follow.key.press'; - -export const MARK_SET_GLOBAL = 'mark.set.global'; -export const MARK_JUMP_GLOBAL = 'mark.jump.global'; - -export const TAB_SCROLL_TO = 'tab.scroll.to'; - -export const FIND_NEXT = 'find.next'; -export const FIND_PREV = 'find.prev'; -export const FIND_GET_KEYWORD = 'find.get.keyword'; -export const FIND_SET_KEYWORD = 'find.set.keyword'; - -export const ADDON_ENABLED_QUERY = 'addon.enabled.query'; -export const ADDON_ENABLED_RESPONSE = 'addon.enabled.response'; -export const ADDON_TOGGLE_ENABLED = 'addon.toggle.enabled'; - -export const OPEN_URL = 'open.url'; - -export const SETTINGS_CHANGED = 'settings.changed'; -export const SETTINGS_QUERY = 'settings.query'; - -export const CONSOLE_FRAME_MESSAGE = 'console.frame.message'; - -export const NAVIGATE_HISTORY_NEXT = 'navigate.history.next'; -export const NAVIGATE_HISTORY_PREV = 'navigate.history.prev'; -export const NAVIGATE_LINK_NEXT = 'navigate.link.next'; -export const NAVIGATE_LINK_PREV = 'navigate.link.prev'; +export const BACKGROUND_OPERATION = "background.operation"; + +export const CONSOLE_UNFOCUS = "console.unfocus"; +export const CONSOLE_ENTER_COMMAND = "console.enter.command"; +export const CONSOLE_ENTER_FIND = "console.enter.find"; +export const CONSOLE_SHOW_COMMAND = "console.show.command"; +export const CONSOLE_SHOW_ERROR = "console.show.error"; +export const CONSOLE_SHOW_INFO = "console.show.info"; +export const CONSOLE_SHOW_FIND = "console.show.find"; +export const CONSOLE_HIDE = "console.hide"; +export const CONSOLE_GET_COMPLETION_TYPES = "console.get.completion.types"; +export const CONSOLE_REQUEST_SEARCH_ENGINES_MESSAGE = + "console.qresut.searchEngines"; +export const CONSOLE_REQUEST_BOOKMARKS = "console.request.bookmarks"; +export const CONSOLE_REQUEST_HISTORY = "console.request.history"; +export const CONSOLE_REQUEST_TABS = "console.request.tabs"; +export const CONSOLE_GET_PROPERTIES = "console.get.properties"; + +export const FOLLOW_START = "follow.start"; +export const FOLLOW_REQUEST_COUNT_TARGETS = "follow.request.count.targets"; +export const FOLLOW_RESPONSE_COUNT_TARGETS = "follow.response.count.targets"; +export const FOLLOW_CREATE_HINTS = "follow.create.hints"; +export const FOLLOW_SHOW_HINTS = "follow.update.hints"; +export const FOLLOW_REMOVE_HINTS = "follow.remove.hints"; +export const FOLLOW_ACTIVATE = "follow.activate"; +export const FOLLOW_KEY_PRESS = "follow.key.press"; + +export const MARK_SET_GLOBAL = "mark.set.global"; +export const MARK_JUMP_GLOBAL = "mark.jump.global"; + +export const TAB_SCROLL_TO = "tab.scroll.to"; + +export const FIND_NEXT = "find.next"; +export const FIND_PREV = "find.prev"; +export const FIND_GET_KEYWORD = "find.get.keyword"; +export const FIND_SET_KEYWORD = "find.set.keyword"; + +export const ADDON_ENABLED_QUERY = "addon.enabled.query"; +export const ADDON_ENABLED_RESPONSE = "addon.enabled.response"; +export const ADDON_TOGGLE_ENABLED = "addon.toggle.enabled"; + +export const OPEN_URL = "open.url"; + +export const SETTINGS_CHANGED = "settings.changed"; +export const SETTINGS_QUERY = "settings.query"; + +export const CONSOLE_FRAME_MESSAGE = "console.frame.message"; + +export const NAVIGATE_HISTORY_NEXT = "navigate.history.next"; +export const NAVIGATE_HISTORY_PREV = "navigate.history.prev"; +export const NAVIGATE_LINK_NEXT = "navigate.link.next"; +export const NAVIGATE_LINK_PREV = "navigate.link.prev"; export interface BackgroundOperationMessage { type: typeof BACKGROUND_OPERATION; @@ -103,7 +104,7 @@ export interface ConsoleGetCompletionTypesMessage { export interface ConsoleRequestSearchEnginesMessage { type: typeof CONSOLE_REQUEST_SEARCH_ENGINES_MESSAGE; - query: string + query: string; } export interface ConsoleRequestBookmarksMessage { @@ -127,33 +128,33 @@ export interface ConsoleGetPropertiesMessage { } export type ConsoleRequesttabsResponse = { - index: number - flag: TabFlag - title: string - url: string - faviconUrl?: string -}[] + index: number; + flag: TabFlag; + title: string; + url: string; + faviconUrl?: string; +}[]; export type ConsoleGetCompletionTypesResponse = CompletionType[]; export type ConsoleRequestSearchEnginesResponse = { title: string; -}[] +}[]; export type ConsoleRequestBookmarksResponse = { - title: string; - url: string; -}[] + title: string; + url: string; +}[]; export type ConsoleRequestHistoryResponse = { title: string; url: string; -}[] +}[]; export type ConsoleGetPropertiesResponse = { - name: string - type: 'string' | 'boolean' | 'number' -}[] + name: string; + type: "string" | "boolean" | "number"; +}[]; export interface FollowStartMessage { type: typeof FOLLOW_START; @@ -163,8 +164,8 @@ export interface FollowStartMessage { export interface FollowRequestCountTargetsMessage { type: typeof FOLLOW_REQUEST_COUNT_TARGETS; - viewSize: { width: number, height: number }; - framePosition: { x: number, y: number }; + viewSize: { width: number; height: number }; + framePosition: { x: number; y: number }; } export interface FollowResponseCountTargetsMessage { @@ -175,8 +176,8 @@ export interface FollowResponseCountTargetsMessage { export interface FollowCreateHintsMessage { type: typeof FOLLOW_CREATE_HINTS; tags: string[]; - viewSize: { width: number, height: number }; - framePosition: { x: number, y: number }; + viewSize: { width: number; height: number }; + framePosition: { x: number; y: number }; } export interface FollowShowHintsMessage { @@ -287,86 +288,86 @@ export interface NavigateLinkPrev { } export type Message = - BackgroundOperationMessage | - ConsoleUnfocusMessage | - ConsoleEnterCommandMessage | - ConsoleEnterFindMessage | - ConsoleShowCommandMessage | - ConsoleShowErrorMessage | - ConsoleShowInfoMessage | - ConsoleShowFindMessage | - ConsoleHideMessage | - ConsoleRequestBookmarksMessage | - ConsoleRequestHistoryMessage | - ConsoleRequestTabsMessage | - ConsoleGetPropertiesMessage | - ConsoleGetCompletionTypesMessage | - ConsoleRequestSearchEnginesMessage | - FollowStartMessage | - FollowRequestCountTargetsMessage | - FollowResponseCountTargetsMessage | - FollowCreateHintsMessage | - FollowShowHintsMessage | - FollowRemoveHintsMessage | - FollowActivateMessage | - FollowKeyPressMessage | - MarkSetGlobalMessage | - MarkJumpGlobalMessage | - TabScrollToMessage | - FindNextMessage | - FindPrevMessage | - FindGetKeywordMessage | - FindSetKeywordMessage | - AddonEnabledQueryMessage | - AddonEnabledResponseMessage | - AddonToggleEnabledMessage | - OpenUrlMessage | - SettingsChangedMessage | - SettingsQueryMessage | - ConsoleFrameMessageMessage | - NavigateHistoryNextMessage | - NavigateHistoryPrevMessage | - NavigateLinkNext | - NavigateLinkPrev; + | BackgroundOperationMessage + | ConsoleUnfocusMessage + | ConsoleEnterCommandMessage + | ConsoleEnterFindMessage + | ConsoleShowCommandMessage + | ConsoleShowErrorMessage + | ConsoleShowInfoMessage + | ConsoleShowFindMessage + | ConsoleHideMessage + | ConsoleRequestBookmarksMessage + | ConsoleRequestHistoryMessage + | ConsoleRequestTabsMessage + | ConsoleGetPropertiesMessage + | ConsoleGetCompletionTypesMessage + | ConsoleRequestSearchEnginesMessage + | FollowStartMessage + | FollowRequestCountTargetsMessage + | FollowResponseCountTargetsMessage + | FollowCreateHintsMessage + | FollowShowHintsMessage + | FollowRemoveHintsMessage + | FollowActivateMessage + | FollowKeyPressMessage + | MarkSetGlobalMessage + | MarkJumpGlobalMessage + | TabScrollToMessage + | FindNextMessage + | FindPrevMessage + | FindGetKeywordMessage + | FindSetKeywordMessage + | AddonEnabledQueryMessage + | AddonEnabledResponseMessage + | AddonToggleEnabledMessage + | OpenUrlMessage + | SettingsChangedMessage + | SettingsQueryMessage + | ConsoleFrameMessageMessage + | NavigateHistoryNextMessage + | NavigateHistoryPrevMessage + | NavigateLinkNext + | NavigateLinkPrev; // eslint-disable-next-line complexity export const valueOf = (o: any): Message => { switch (o.type) { - case CONSOLE_UNFOCUS: - case CONSOLE_ENTER_COMMAND: - case CONSOLE_ENTER_FIND: - case CONSOLE_SHOW_COMMAND: - case CONSOLE_SHOW_ERROR: - case CONSOLE_SHOW_INFO: - case CONSOLE_SHOW_FIND: - case CONSOLE_HIDE: - case FOLLOW_START: - case FOLLOW_REQUEST_COUNT_TARGETS: - case FOLLOW_RESPONSE_COUNT_TARGETS: - case FOLLOW_CREATE_HINTS: - case FOLLOW_SHOW_HINTS: - case FOLLOW_REMOVE_HINTS: - case FOLLOW_ACTIVATE: - case FOLLOW_KEY_PRESS: - case MARK_SET_GLOBAL: - case MARK_JUMP_GLOBAL: - case TAB_SCROLL_TO: - case FIND_NEXT: - case FIND_PREV: - case FIND_GET_KEYWORD: - case FIND_SET_KEYWORD: - case ADDON_ENABLED_QUERY: - case ADDON_ENABLED_RESPONSE: - case ADDON_TOGGLE_ENABLED: - case OPEN_URL: - case SETTINGS_CHANGED: - case SETTINGS_QUERY: - case CONSOLE_FRAME_MESSAGE: - case NAVIGATE_HISTORY_NEXT: - case NAVIGATE_HISTORY_PREV: - case NAVIGATE_LINK_NEXT: - case NAVIGATE_LINK_PREV: - return o; + case CONSOLE_UNFOCUS: + case CONSOLE_ENTER_COMMAND: + case CONSOLE_ENTER_FIND: + case CONSOLE_SHOW_COMMAND: + case CONSOLE_SHOW_ERROR: + case CONSOLE_SHOW_INFO: + case CONSOLE_SHOW_FIND: + case CONSOLE_HIDE: + case FOLLOW_START: + case FOLLOW_REQUEST_COUNT_TARGETS: + case FOLLOW_RESPONSE_COUNT_TARGETS: + case FOLLOW_CREATE_HINTS: + case FOLLOW_SHOW_HINTS: + case FOLLOW_REMOVE_HINTS: + case FOLLOW_ACTIVATE: + case FOLLOW_KEY_PRESS: + case MARK_SET_GLOBAL: + case MARK_JUMP_GLOBAL: + case TAB_SCROLL_TO: + case FIND_NEXT: + case FIND_PREV: + case FIND_GET_KEYWORD: + case FIND_SET_KEYWORD: + case ADDON_ENABLED_QUERY: + case ADDON_ENABLED_RESPONSE: + case ADDON_TOGGLE_ENABLED: + case OPEN_URL: + case SETTINGS_CHANGED: + case SETTINGS_QUERY: + case CONSOLE_FRAME_MESSAGE: + case NAVIGATE_HISTORY_NEXT: + case NAVIGATE_HISTORY_PREV: + case NAVIGATE_LINK_NEXT: + case NAVIGATE_LINK_PREV: + return o; } - throw new Error('unknown operation type: ' + o.type); + throw new Error("unknown operation type: " + o.type); }; diff --git a/src/shared/operations.ts b/src/shared/operations.ts index beca7b9..3544502 100644 --- a/src/shared/operations.ts +++ b/src/shared/operations.ts @@ -1,85 +1,85 @@ // Hide console; or cancel some user actions -export const CANCEL = 'cancel'; +export const CANCEL = "cancel"; // Addons -export const ADDON_ENABLE = 'addon.enable'; -export const ADDON_DISABLE = 'addon.disable'; -export const ADDON_TOGGLE_ENABLED = 'addon.toggle.enabled'; +export const ADDON_ENABLE = "addon.enable"; +export const ADDON_DISABLE = "addon.disable"; +export const ADDON_TOGGLE_ENABLED = "addon.toggle.enabled"; // Command -export const COMMAND_SHOW = 'command.show'; -export const COMMAND_SHOW_OPEN = 'command.show.open'; -export const COMMAND_SHOW_TABOPEN = 'command.show.tabopen'; -export const COMMAND_SHOW_WINOPEN = 'command.show.winopen'; -export const COMMAND_SHOW_BUFFER = 'command.show.buffer'; -export const COMMAND_SHOW_ADDBOOKMARK = 'command.show.addbookmark'; +export const COMMAND_SHOW = "command.show"; +export const COMMAND_SHOW_OPEN = "command.show.open"; +export const COMMAND_SHOW_TABOPEN = "command.show.tabopen"; +export const COMMAND_SHOW_WINOPEN = "command.show.winopen"; +export const COMMAND_SHOW_BUFFER = "command.show.buffer"; +export const COMMAND_SHOW_ADDBOOKMARK = "command.show.addbookmark"; // Scrolls -export const SCROLL_VERTICALLY = 'scroll.vertically'; -export const SCROLL_HORIZONALLY = 'scroll.horizonally'; -export const SCROLL_PAGES = 'scroll.pages'; -export const SCROLL_TOP = 'scroll.top'; -export const SCROLL_BOTTOM = 'scroll.bottom'; -export const SCROLL_HOME = 'scroll.home'; -export const SCROLL_END = 'scroll.end'; +export const SCROLL_VERTICALLY = "scroll.vertically"; +export const SCROLL_HORIZONALLY = "scroll.horizonally"; +export const SCROLL_PAGES = "scroll.pages"; +export const SCROLL_TOP = "scroll.top"; +export const SCROLL_BOTTOM = "scroll.bottom"; +export const SCROLL_HOME = "scroll.home"; +export const SCROLL_END = "scroll.end"; // Follows -export const FOLLOW_START = 'follow.start'; +export const FOLLOW_START = "follow.start"; // Navigations -export const NAVIGATE_HISTORY_PREV = 'navigate.history.prev'; -export const NAVIGATE_HISTORY_NEXT = 'navigate.history.next'; -export const NAVIGATE_LINK_PREV = 'navigate.link.prev'; -export const NAVIGATE_LINK_NEXT = 'navigate.link.next'; -export const NAVIGATE_PARENT = 'navigate.parent'; -export const NAVIGATE_ROOT = 'navigate.root'; +export const NAVIGATE_HISTORY_PREV = "navigate.history.prev"; +export const NAVIGATE_HISTORY_NEXT = "navigate.history.next"; +export const NAVIGATE_LINK_PREV = "navigate.link.prev"; +export const NAVIGATE_LINK_NEXT = "navigate.link.next"; +export const NAVIGATE_PARENT = "navigate.parent"; +export const NAVIGATE_ROOT = "navigate.root"; // Focus -export const FOCUS_INPUT = 'focus.input'; +export const FOCUS_INPUT = "focus.input"; // Page -export const PAGE_SOURCE = 'page.source'; -export const PAGE_HOME = 'page.home'; +export const PAGE_SOURCE = "page.source"; +export const PAGE_HOME = "page.home"; // Tabs -export const TAB_CLOSE = 'tabs.close'; -export const TAB_CLOSE_FORCE = 'tabs.close.force'; -export const TAB_CLOSE_RIGHT = 'tabs.close.right'; -export const TAB_REOPEN = 'tabs.reopen'; -export const TAB_PREV = 'tabs.prev'; -export const TAB_NEXT = 'tabs.next'; -export const TAB_FIRST = 'tabs.first'; -export const TAB_LAST = 'tabs.last'; -export const TAB_PREV_SEL = 'tabs.prevsel'; -export const TAB_RELOAD = 'tabs.reload'; -export const TAB_PIN = 'tabs.pin'; -export const TAB_UNPIN = 'tabs.unpin'; -export const TAB_TOGGLE_PINNED = 'tabs.pin.toggle'; -export const TAB_DUPLICATE = 'tabs.duplicate'; +export const TAB_CLOSE = "tabs.close"; +export const TAB_CLOSE_FORCE = "tabs.close.force"; +export const TAB_CLOSE_RIGHT = "tabs.close.right"; +export const TAB_REOPEN = "tabs.reopen"; +export const TAB_PREV = "tabs.prev"; +export const TAB_NEXT = "tabs.next"; +export const TAB_FIRST = "tabs.first"; +export const TAB_LAST = "tabs.last"; +export const TAB_PREV_SEL = "tabs.prevsel"; +export const TAB_RELOAD = "tabs.reload"; +export const TAB_PIN = "tabs.pin"; +export const TAB_UNPIN = "tabs.unpin"; +export const TAB_TOGGLE_PINNED = "tabs.pin.toggle"; +export const TAB_DUPLICATE = "tabs.duplicate"; // Zooms -export const ZOOM_IN = 'zoom.in'; -export const ZOOM_OUT = 'zoom.out'; -export const ZOOM_NEUTRAL = 'zoom.neutral'; +export const ZOOM_IN = "zoom.in"; +export const ZOOM_OUT = "zoom.out"; +export const ZOOM_NEUTRAL = "zoom.neutral"; // Url yank/paste -export const URLS_YANK = 'urls.yank'; -export const URLS_PASTE = 'urls.paste'; +export const URLS_YANK = "urls.yank"; +export const URLS_PASTE = "urls.paste"; // Find -export const FIND_START = 'find.start'; -export const FIND_NEXT = 'find.next'; -export const FIND_PREV = 'find.prev'; +export const FIND_START = "find.start"; +export const FIND_NEXT = "find.next"; +export const FIND_PREV = "find.prev"; // Mark -export const MARK_SET_PREFIX = 'mark.set.prefix'; -export const MARK_JUMP_PREFIX = 'mark.jump.prefix'; +export const MARK_SET_PREFIX = "mark.set.prefix"; +export const MARK_JUMP_PREFIX = "mark.jump.prefix"; // Repeat -export const REPEAT_LAST = 'repeat.last'; +export const REPEAT_LAST = "repeat.last"; // Internal -export const INTERNAL_OPEN_URL = 'internal.open.url'; +export const INTERNAL_OPEN_URL = "internal.open.url"; export interface CancelOperation { type: typeof CANCEL; @@ -201,7 +201,7 @@ export interface PageHomeOperation { export interface TabCloseOperation { type: typeof TAB_CLOSE; - select?: 'left' | 'right'; + select?: "left" | "right"; } export interface TabCloseForceOperation { @@ -311,65 +311,67 @@ export interface InternalOpenUrl { } export type Operation = - CancelOperation | - AddonEnableOperation | - AddonDisableOperation | - AddonToggleEnabledOperation | - CommandShowOperation | - CommandShowOpenOperation | - CommandShowTabopenOperation | - CommandShowWinopenOperation | - CommandShowBufferOperation | - CommandShowAddbookmarkOperation | - ScrollVerticallyOperation | - ScrollHorizonallyOperation | - ScrollPagesOperation | - ScrollTopOperation | - ScrollBottomOperation | - ScrollHomeOperation | - ScrollEndOperation | - FollowStartOperation | - NavigateHistoryPrevOperation | - NavigateHistoryNextOperation | - NavigateLinkPrevOperation | - NavigateLinkNextOperation | - NavigateParentOperation | - NavigateRootOperation | - FocusInputOperation | - PageSourceOperation | - PageHomeOperation | - TabCloseOperation | - TabCloseForceOperation | - TabCloseRightOperation | - TabReopenOperation | - TabPrevOperation | - TabNextOperation | - TabFirstOperation | - TabLastOperation | - TabPrevSelOperation | - TabReloadOperation | - TabPinOperation | - TabUnpinOperation | - TabTogglePinnedOperation | - TabDuplicateOperation | - ZoomInOperation | - ZoomOutOperation | - ZoomNeutralOperation | - UrlsYankOperation | - UrlsPasteOperation | - FindStartOperation | - FindNextOperation | - FindPrevOperation | - MarkSetPrefixOperation | - MarkJumpPrefixOperation | - RepeatLastOperation | - InternalOpenUrl; + | CancelOperation + | AddonEnableOperation + | AddonDisableOperation + | AddonToggleEnabledOperation + | CommandShowOperation + | CommandShowOpenOperation + | CommandShowTabopenOperation + | CommandShowWinopenOperation + | CommandShowBufferOperation + | CommandShowAddbookmarkOperation + | ScrollVerticallyOperation + | ScrollHorizonallyOperation + | ScrollPagesOperation + | ScrollTopOperation + | ScrollBottomOperation + | ScrollHomeOperation + | ScrollEndOperation + | FollowStartOperation + | NavigateHistoryPrevOperation + | NavigateHistoryNextOperation + | NavigateLinkPrevOperation + | NavigateLinkNextOperation + | NavigateParentOperation + | NavigateRootOperation + | FocusInputOperation + | PageSourceOperation + | PageHomeOperation + | TabCloseOperation + | TabCloseForceOperation + | TabCloseRightOperation + | TabReopenOperation + | TabPrevOperation + | TabNextOperation + | TabFirstOperation + | TabLastOperation + | TabPrevSelOperation + | TabReloadOperation + | TabPinOperation + | TabUnpinOperation + | TabTogglePinnedOperation + | TabDuplicateOperation + | ZoomInOperation + | ZoomOutOperation + | ZoomNeutralOperation + | UrlsYankOperation + | UrlsPasteOperation + | FindStartOperation + | FindNextOperation + | FindPrevOperation + | MarkSetPrefixOperation + | MarkJumpPrefixOperation + | RepeatLastOperation + | InternalOpenUrl; const assertOptionalBoolean = (obj: any, name: string) => { - if (Object.prototype.hasOwnProperty.call(obj, name) && - typeof obj[name] !== 'boolean') { + if ( + Object.prototype.hasOwnProperty.call(obj, name) && + typeof obj[name] !== "boolean" + ) { throw new TypeError( - `Not a boolean parameter: '${name} (${typeof obj[name]})'`, + `Not a boolean parameter: '${name} (${typeof obj[name]})'` ); } }; @@ -377,9 +379,9 @@ const assertOptionalBoolean = (obj: any, name: string) => { const assertOptionalString = (obj: any, name: string, values?: string[]) => { if (Object.prototype.hasOwnProperty.call(obj, name)) { const value = obj[name]; - if (typeof value !== 'string') { + if (typeof value !== "string") { throw new TypeError( - `Not a string parameter: '${name}' (${typeof value})`, + `Not a string parameter: '${name}' (${typeof value})` ); } if (values && values.length && values.indexOf(value) === -1) { @@ -390,147 +392,157 @@ const assertOptionalString = (obj: any, name: string, values?: string[]) => { }; const assertRequiredNumber = (obj: any, name: string) => { - if (!Object.prototype.hasOwnProperty.call(obj, name) || - typeof obj[name] !== 'number') { + if ( + !Object.prototype.hasOwnProperty.call(obj, name) || + typeof obj[name] !== "number" + ) { throw new TypeError(`Missing number parameter: '${name}`); } }; const assertRequiredString = (obj: any, name: string) => { - if (!Object.prototype.hasOwnProperty.call(obj, name) || - typeof obj[name] !== 'string') { + if ( + !Object.prototype.hasOwnProperty.call(obj, name) || + typeof obj[name] !== "string" + ) { throw new TypeError(`Missing string parameter: '${name}`); } }; // eslint-disable-next-line complexity, max-lines-per-function export const valueOf = (o: any): Operation => { - if (!Object.prototype.hasOwnProperty.call(o, 'type')) { + if (!Object.prototype.hasOwnProperty.call(o, "type")) { throw new TypeError(`Missing 'type' field`); } switch (o.type) { - case COMMAND_SHOW_OPEN: - case COMMAND_SHOW_TABOPEN: - case COMMAND_SHOW_WINOPEN: - case COMMAND_SHOW_ADDBOOKMARK: - assertOptionalBoolean(o, 'alter'); - return { type: o.type, alter: Boolean(o.alter) }; - case SCROLL_VERTICALLY: - case SCROLL_HORIZONALLY: - case SCROLL_PAGES: - assertRequiredNumber(o, 'count'); - return { type: o.type, count: Number(o.count) }; - case FOLLOW_START: - assertOptionalBoolean(o, 'newTab'); - assertOptionalBoolean(o, 'background'); - return { - type: FOLLOW_START, - newTab: Boolean(typeof o.newTab === 'undefined' ? false : o.newTab), - background: Boolean(typeof o.background === 'undefined' ? true : o.background), // eslint-disable-line max-len - }; - case PAGE_HOME: - assertOptionalBoolean(o, 'newTab'); - return { - type: PAGE_HOME, - newTab: Boolean(typeof o.newTab === 'undefined' ? false : o.newTab), - }; - case TAB_CLOSE: - assertOptionalString(o, 'select', ['left', 'right']); - return { - type: TAB_CLOSE, - select: (typeof o.select === 'undefined' ? 'right' : o.select), - }; - case TAB_RELOAD: - assertOptionalBoolean(o, 'cache'); - return { - type: TAB_RELOAD, - cache: Boolean(typeof o.cache === 'undefined' ? false : o.cache), - }; - case URLS_PASTE: - assertOptionalBoolean(o, 'newTab'); - return { - type: URLS_PASTE, - newTab: Boolean(typeof o.newTab === 'undefined' ? false : o.newTab), - }; - case INTERNAL_OPEN_URL: - assertOptionalBoolean(o, 'newTab'); - assertOptionalBoolean(o, 'newWindow'); - assertOptionalBoolean(o, 'background'); - assertRequiredString(o, 'url'); - return { - type: INTERNAL_OPEN_URL, - url: o.url, - newTab: Boolean(typeof o.newTab === 'undefined' ? false : o.newTab), - newWindow: Boolean(typeof o.newWindow === 'undefined' ? false : o.newWindow), // eslint-disable-line max-len - background: Boolean(typeof o.background === 'undefined' ? true : o.background), // eslint-disable-line max-len - }; - case CANCEL: - case ADDON_ENABLE: - case ADDON_DISABLE: - case ADDON_TOGGLE_ENABLED: - case COMMAND_SHOW: - case COMMAND_SHOW_BUFFER: - case SCROLL_TOP: - case SCROLL_BOTTOM: - case SCROLL_HOME: - case SCROLL_END: - case NAVIGATE_HISTORY_PREV: - case NAVIGATE_HISTORY_NEXT: - case NAVIGATE_LINK_PREV: - case NAVIGATE_LINK_NEXT: - case NAVIGATE_PARENT: - case NAVIGATE_ROOT: - case FOCUS_INPUT: - case PAGE_SOURCE: - case TAB_CLOSE_FORCE: - case TAB_CLOSE_RIGHT: - case TAB_REOPEN: - case TAB_PREV: - case TAB_NEXT: - case TAB_FIRST: - case TAB_LAST: - case TAB_PREV_SEL: - case TAB_PIN: - case TAB_UNPIN: - case TAB_TOGGLE_PINNED: - case TAB_DUPLICATE: - case ZOOM_IN: - case ZOOM_OUT: - case ZOOM_NEUTRAL: - case URLS_YANK: - case FIND_START: - case FIND_NEXT: - case FIND_PREV: - case MARK_SET_PREFIX: - case MARK_JUMP_PREFIX: - case REPEAT_LAST: - return { type: o.type }; + case COMMAND_SHOW_OPEN: + case COMMAND_SHOW_TABOPEN: + case COMMAND_SHOW_WINOPEN: + case COMMAND_SHOW_ADDBOOKMARK: + assertOptionalBoolean(o, "alter"); + return { type: o.type, alter: Boolean(o.alter) }; + case SCROLL_VERTICALLY: + case SCROLL_HORIZONALLY: + case SCROLL_PAGES: + assertRequiredNumber(o, "count"); + return { type: o.type, count: Number(o.count) }; + case FOLLOW_START: + assertOptionalBoolean(o, "newTab"); + assertOptionalBoolean(o, "background"); + return { + type: FOLLOW_START, + newTab: Boolean(typeof o.newTab === "undefined" ? false : o.newTab), + background: Boolean( + typeof o.background === "undefined" ? true : o.background + ), // eslint-disable-line max-len + }; + case PAGE_HOME: + assertOptionalBoolean(o, "newTab"); + return { + type: PAGE_HOME, + newTab: Boolean(typeof o.newTab === "undefined" ? false : o.newTab), + }; + case TAB_CLOSE: + assertOptionalString(o, "select", ["left", "right"]); + return { + type: TAB_CLOSE, + select: typeof o.select === "undefined" ? "right" : o.select, + }; + case TAB_RELOAD: + assertOptionalBoolean(o, "cache"); + return { + type: TAB_RELOAD, + cache: Boolean(typeof o.cache === "undefined" ? false : o.cache), + }; + case URLS_PASTE: + assertOptionalBoolean(o, "newTab"); + return { + type: URLS_PASTE, + newTab: Boolean(typeof o.newTab === "undefined" ? false : o.newTab), + }; + case INTERNAL_OPEN_URL: + assertOptionalBoolean(o, "newTab"); + assertOptionalBoolean(o, "newWindow"); + assertOptionalBoolean(o, "background"); + assertRequiredString(o, "url"); + return { + type: INTERNAL_OPEN_URL, + url: o.url, + newTab: Boolean(typeof o.newTab === "undefined" ? false : o.newTab), + newWindow: Boolean( + typeof o.newWindow === "undefined" ? false : o.newWindow + ), // eslint-disable-line max-len + background: Boolean( + typeof o.background === "undefined" ? true : o.background + ), // eslint-disable-line max-len + }; + case CANCEL: + case ADDON_ENABLE: + case ADDON_DISABLE: + case ADDON_TOGGLE_ENABLED: + case COMMAND_SHOW: + case COMMAND_SHOW_BUFFER: + case SCROLL_TOP: + case SCROLL_BOTTOM: + case SCROLL_HOME: + case SCROLL_END: + case NAVIGATE_HISTORY_PREV: + case NAVIGATE_HISTORY_NEXT: + case NAVIGATE_LINK_PREV: + case NAVIGATE_LINK_NEXT: + case NAVIGATE_PARENT: + case NAVIGATE_ROOT: + case FOCUS_INPUT: + case PAGE_SOURCE: + case TAB_CLOSE_FORCE: + case TAB_CLOSE_RIGHT: + case TAB_REOPEN: + case TAB_PREV: + case TAB_NEXT: + case TAB_FIRST: + case TAB_LAST: + case TAB_PREV_SEL: + case TAB_PIN: + case TAB_UNPIN: + case TAB_TOGGLE_PINNED: + case TAB_DUPLICATE: + case ZOOM_IN: + case ZOOM_OUT: + case ZOOM_NEUTRAL: + case URLS_YANK: + case FIND_START: + case FIND_NEXT: + case FIND_PREV: + case MARK_SET_PREFIX: + case MARK_JUMP_PREFIX: + case REPEAT_LAST: + return { type: o.type }; } - throw new TypeError('Unknown operation type: ' + o.type); + throw new TypeError("Unknown operation type: " + o.type); }; export const isNRepeatable = (type: string): boolean => { switch (type) { - case SCROLL_VERTICALLY: - case SCROLL_HORIZONALLY: - case SCROLL_PAGES: - case NAVIGATE_HISTORY_PREV: - case NAVIGATE_HISTORY_NEXT: - case NAVIGATE_PARENT: - case TAB_CLOSE: - case TAB_CLOSE_FORCE: - case TAB_CLOSE_RIGHT: - case TAB_REOPEN: - case TAB_PREV: - case TAB_NEXT: - case TAB_DUPLICATE: - case ZOOM_IN: - case ZOOM_OUT: - case URLS_PASTE: - case FIND_NEXT: - case FIND_PREV: - case REPEAT_LAST: - return true; + case SCROLL_VERTICALLY: + case SCROLL_HORIZONALLY: + case SCROLL_PAGES: + case NAVIGATE_HISTORY_PREV: + case NAVIGATE_HISTORY_NEXT: + case NAVIGATE_PARENT: + case TAB_CLOSE: + case TAB_CLOSE_FORCE: + case TAB_CLOSE_RIGHT: + case TAB_REOPEN: + case TAB_PREV: + case TAB_NEXT: + case TAB_DUPLICATE: + case ZOOM_IN: + case ZOOM_OUT: + case URLS_PASTE: + case FIND_NEXT: + case FIND_PREV: + case REPEAT_LAST: + return true; } return false; }; diff --git a/src/shared/settings/Blacklist.ts b/src/shared/settings/Blacklist.ts index 6c54d73..278dbd6 100644 --- a/src/shared/settings/Blacklist.ts +++ b/src/shared/settings/Blacklist.ts @@ -1,14 +1,16 @@ -import Key from './Key'; +import Key from "./Key"; -export type BlacklistItemJSON = string | { - url: string, - keys: string[], -}; +export type BlacklistItemJSON = + | string + | { + url: string; + keys: string[]; + }; export type BlacklistJSON = BlacklistItemJSON[]; const regexFromWildcard = (pattern: string): RegExp => { - const regexStr = '^' + pattern.replace(/\*/g, '.*') + '$'; + const regexStr = "^" + pattern.replace(/\*/g, ".*") + "$"; return new RegExp(regexStr); }; @@ -23,11 +25,7 @@ export class BlacklistItem { private readonly keyEntities: Key[]; - constructor( - pattern: string, - partial: boolean, - keys: string[] - ) { + constructor(pattern: string, partial: boolean, keys: string[]) { this.pattern = pattern; this.regex = regexFromWildcard(pattern); this.partial = partial; @@ -36,7 +34,7 @@ export class BlacklistItem { } static fromJSON(json: BlacklistItemJSON): BlacklistItem { - return typeof json === 'string' + return typeof json === "string" ? new BlacklistItem(json, false, []) : new BlacklistItem(json.url, true, json.keys); } @@ -49,7 +47,7 @@ export class BlacklistItem { } matches(url: URL): boolean { - return this.pattern.includes('/') + return this.pattern.includes("/") ? this.regex.test(url.host + url.pathname) : this.regex.test(url.host); } @@ -58,30 +56,27 @@ export class BlacklistItem { if (!this.matches(url) || !this.partial) { return false; } - return this.keyEntities.some(k => k.equals(key)); + return this.keyEntities.some((k) => k.equals(key)); } } export default class Blacklist { - constructor( - public readonly items: BlacklistItem[], - ) { - } + constructor(public readonly items: BlacklistItem[]) {} static fromJSON(json: BlacklistJSON): Blacklist { - const items = json.map(o => BlacklistItem.fromJSON(o)); + const items = json.map((o) => BlacklistItem.fromJSON(o)); return new Blacklist(items); } toJSON(): BlacklistJSON { - return this.items.map(item => item.toJSON()); + return this.items.map((item) => item.toJSON()); } includesEntireBlacklist(url: URL): boolean { - return this.items.some(item => !item.partial && item.matches(url)); + return this.items.some((item) => !item.partial && item.matches(url)); } includeKey(url: URL, key: Key) { - return this.items.some(item => item.includeKey(url, key)); + return this.items.some((item) => item.includeKey(url, key)); } } diff --git a/src/shared/settings/Key.ts b/src/shared/settings/Key.ts index 1464e57..2f47aff 100644 --- a/src/shared/settings/Key.ts +++ b/src/shared/settings/Key.ts @@ -1,4 +1,4 @@ -const digits = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']; +const digits = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]; export default class Key { public readonly key: string; @@ -32,10 +32,10 @@ export default class Key { } static fromMapKey(str: string): Key { - if (str.startsWith('<') && str.endsWith('>')) { + if (str.startsWith("<") && str.endsWith(">")) { const inner = str.slice(1, -1); - const shift = inner.includes('S-'); - let base = inner.slice(inner.lastIndexOf('-') + 1); + const shift = inner.includes("S-"); + let base = inner.slice(inner.lastIndexOf("-") + 1); if (shift && base.length === 1) { base = base.toUpperCase(); } else if (!shift && base.length === 1) { @@ -44,9 +44,9 @@ export default class Key { return new Key({ key: base, shift: shift, - ctrl: inner.includes('C-'), - alt: inner.includes('A-'), - meta: inner.includes('M-'), + ctrl: inner.includes("C-"), + alt: inner.includes("A-"), + meta: inner.includes("M-"), }); } @@ -64,10 +64,12 @@ export default class Key { } equals(key: Key) { - return this.key === key.key && + return ( + this.key === key.key && this.ctrl === key.ctrl && this.meta === key.meta && this.alt === key.alt && - this.shift === key.shift; + this.shift === key.shift + ); } } diff --git a/src/shared/settings/Keymaps.ts b/src/shared/settings/Keymaps.ts index 3880654..718427e 100644 --- a/src/shared/settings/Keymaps.ts +++ b/src/shared/settings/Keymaps.ts @@ -1,18 +1,17 @@ -import * as operations from '../operations'; +import * as operations from "../operations"; -type OperationJson = { - type: string -} | { - type: string; - [prop: string]: string | number | boolean; -}; +type OperationJson = + | { + type: string; + } + | { + type: string; + [prop: string]: string | number | boolean; + }; export type KeymapsJSON = { [key: string]: OperationJson }; export default class Keymaps { - constructor( - private readonly data: { [key: string]: operations.Operation }, - ) { - } + constructor(private readonly data: { [key: string]: operations.Operation }) {} static fromJSON(json: KeymapsJSON): Keymaps { const entries: { [key: string]: operations.Operation } = {}; diff --git a/src/shared/settings/Properties.ts b/src/shared/settings/Properties.ts index 27fb62e..cf10d61 100644 --- a/src/shared/settings/Properties.ts +++ b/src/shared/settings/Properties.ts @@ -1,4 +1,3 @@ - export type PropertiesJSON = { hintchars?: string; smoothscroll?: boolean; @@ -11,38 +10,40 @@ export type PropertyTypes = { complete: string; }; -type PropertyName = 'hintchars' | 'smoothscroll' | 'complete'; +type PropertyName = "hintchars" | "smoothscroll" | "complete"; type PropertyDef = { name: PropertyName; description: string; defaultValue: string | number | boolean; - type: 'string' | 'number' | 'boolean'; + type: "string" | "number" | "boolean"; }; const defs: PropertyDef[] = [ { - name: 'hintchars', - description: 'hint characters on follow mode', - defaultValue: 'abcdefghijklmnopqrstuvwxyz', - type: 'string', - }, { - name: 'smoothscroll', - description: 'smooth scroll', + name: "hintchars", + description: "hint characters on follow mode", + defaultValue: "abcdefghijklmnopqrstuvwxyz", + type: "string", + }, + { + name: "smoothscroll", + description: "smooth scroll", defaultValue: false, - type: 'boolean', - }, { - name: 'complete', - description: 'which are completed at the open page', - defaultValue: 'sbh', - type: 'string', - } + type: "boolean", + }, + { + name: "complete", + description: "which are completed at the open page", + defaultValue: "sbh", + type: "string", + }, ]; const defaultValues = { - hintchars: 'abcdefghijklmnopqrstuvwxyz', + hintchars: "abcdefghijklmnopqrstuvwxyz", smoothscroll: false, - complete: 'sbh', + complete: "sbh", }; export default class Properties { @@ -72,14 +73,14 @@ export default class Properties { static types(): PropertyTypes { return { - hintchars: 'string', - smoothscroll: 'boolean', - complete: 'string', + hintchars: "string", + smoothscroll: "boolean", + complete: "string", }; } static def(name: string): PropertyDef | undefined { - return defs.find(p => p.name === name); + return defs.find((p) => p.name === name); } static defs(): PropertyDef[] { diff --git a/src/shared/settings/Search.ts b/src/shared/settings/Search.ts index 7de03de..b25aa78 100644 --- a/src/shared/settings/Search.ts +++ b/src/shared/settings/Search.ts @@ -6,16 +6,12 @@ export type SearchJSON = { }; export default class Search { - constructor( - public defaultEngine: string, - public engines: Entries, - ) { - } + constructor(public defaultEngine: string, public engines: Entries) {} static fromJSON(json: SearchJSON): Search { for (const [name, url] of Object.entries(json.engines)) { - if (!(/^[a-zA-Z0-9]+$/).test(name)) { - throw new TypeError('Search engine\'s name must be [a-zA-Z0-9]+'); + if (!/^[a-zA-Z0-9]+$/.test(name)) { + throw new TypeError("Search engine's name must be [a-zA-Z0-9]+"); } const matches = url.match(/{}/g); if (matches === null) { diff --git a/src/shared/settings/Settings.ts b/src/shared/settings/Settings.ts index add5389..1bb9249 100644 --- a/src/shared/settings/Settings.ts +++ b/src/shared/settings/Settings.ts @@ -1,16 +1,16 @@ -import Ajv from 'ajv'; +import Ajv from "ajv"; -import Keymaps, { KeymapsJSON } from './Keymaps'; -import Search, { SearchJSON } from './Search'; -import Properties, { PropertiesJSON } from './Properties'; -import Blacklist, { BlacklistJSON } from './Blacklist'; -import validate from './validate'; +import Keymaps, { KeymapsJSON } from "./Keymaps"; +import Search, { SearchJSON } from "./Search"; +import Properties, { PropertiesJSON } from "./Properties"; +import Blacklist, { BlacklistJSON } from "./Blacklist"; +import validate from "./validate"; export type SettingsJSON = { - keymaps?: KeymapsJSON, - search?: SearchJSON, - properties?: PropertiesJSON, - blacklist?: BlacklistJSON, + keymaps?: KeymapsJSON; + search?: SearchJSON; + properties?: PropertiesJSON; + blacklist?: BlacklistJSON; }; export default class Settings { @@ -42,11 +42,11 @@ export default class Settings { static fromJSON(json: unknown): Settings { const valid = validate(json); if (!valid) { - const message = (validate as any).errors!! - .map((err: Ajv.ErrorObject) => { + const message = (validate as any) + .errors!!.map((err: Ajv.ErrorObject) => { return `'${err.dataPath}' ${err.message}`; }) - .join('; '); + .join("; "); throw new TypeError(message); } @@ -162,5 +162,6 @@ export const DefaultSettingJSONText = `{ ] }`; -export const DefaultSetting: Settings = - Settings.fromJSON(JSON.parse(DefaultSettingJSONText)); +export const DefaultSetting: Settings = Settings.fromJSON( + JSON.parse(DefaultSettingJSONText) +); diff --git a/src/shared/urls.ts b/src/shared/urls.ts index bac929e..2bfa44b 100644 --- a/src/shared/urls.ts +++ b/src/shared/urls.ts @@ -1,28 +1,28 @@ -import Search from './settings/Search'; +import Search from "./settings/Search"; const trimStart = (str: string): string => { // NOTE String.trimStart is available on Firefox 61 - return str.replace(/^\s+/, ''); + return str.replace(/^\s+/, ""); }; -const SUPPORTED_PROTOCOLS = ['http:', 'https:', 'ftp:', 'mailto:', 'about:']; +const SUPPORTED_PROTOCOLS = ["http:", "https:", "ftp:", "mailto:", "about:"]; const isLocalhost = (url: string): boolean => { - if (url === 'localhost') { + if (url === "localhost") { return true; } - const [host, port] = url.split(':', 2); - return host === 'localhost' && !isNaN(Number(port)); + const [host, port] = url.split(":", 2); + return host === "localhost" && !isNaN(Number(port)); }; const isMissingHttp = (keywords: string): boolean => { - if (keywords.includes('.') && !keywords.includes(' ')) { + if (keywords.includes(".") && !keywords.includes(" ")) { return true; } try { - const u = new URL('http://' + keywords); + const u = new URL("http://" + keywords); return isLocalhost(u.host); } catch (e) { // fallthrough @@ -41,18 +41,18 @@ const searchUrl = (keywords: string, search: Search): string => { } if (isMissingHttp(keywords)) { - return 'http://' + keywords; + return "http://" + keywords; } let template = search.engines[search.defaultEngine]; let query = keywords; - const first = trimStart(keywords).split(' ')[0]; + const first = trimStart(keywords).split(" ")[0]; if (Object.keys(search.engines).includes(first)) { template = search.engines[first]; query = trimStart(trimStart(keywords).slice(first.length)); } - return template.replace('{}', encodeURIComponent(query)); + return template.replace("{}", encodeURIComponent(query)); }; const normalizeUrl = (url: string): string => { @@ -64,7 +64,7 @@ const normalizeUrl = (url: string): string => { } catch (e) { // fallthrough } - return 'http://' + url; + return "http://" + url; }; export { searchUrl, normalizeUrl }; diff --git a/src/shared/utils/dom.ts b/src/shared/utils/dom.ts index a6186cb..0cf2ee8 100644 --- a/src/shared/utils/dom.ts +++ b/src/shared/utils/dom.ts @@ -1,9 +1,9 @@ const isContentEditable = (element: Element): boolean => { - const value = element.getAttribute('contenteditable'); + const value = element.getAttribute("contenteditable"); if (value === null) { return false; } - return value.toLowerCase() === 'true' || value.toLowerCase() === ''; + return value.toLowerCase() === "true" || value.toLowerCase() === ""; }; interface Rect { @@ -14,12 +14,12 @@ interface Rect { } const rectangleCoordsRect = (coords: string): Rect => { - const [left, top, right, bottom] = coords.split(',').map(n => Number(n)); + const [left, top, right, bottom] = coords.split(",").map((n) => Number(n)); return { left, top, right, bottom }; }; const circleCoordsRect = (coords: string): Rect => { - const [x, y, r] = coords.split(',').map(n => Number(n)); + const [x, y, r] = coords.split(",").map((n) => Number(n)); return { left: x - r, top: y - r, @@ -29,7 +29,7 @@ const circleCoordsRect = (coords: string): Rect => { }; const polygonCoordsRect = (coords: string): Rect => { - const params = coords.split(','); + const params = coords.split(","); let minx = Number(params[0]), maxx = Number(params[0]), miny = Number(params[1]), @@ -55,7 +55,7 @@ const polygonCoordsRect = (coords: string): Rect => { }; const viewportRect = (e: Element): Rect => { - if (e.tagName !== 'AREA') { + if (e.tagName !== "AREA") { return e.getBoundingClientRect(); } @@ -63,29 +63,26 @@ const viewportRect = (e: Element): Rect => { const imgElement = document.querySelector( `img[usemap="#${mapElement.name}"]` ) as HTMLImageElement; - const { - left: mapLeft, - top: mapTop - } = imgElement.getBoundingClientRect(); - const coords = e.getAttribute('coords'); + const { left: mapLeft, top: mapTop } = imgElement.getBoundingClientRect(); + const coords = e.getAttribute("coords"); if (!coords) { return e.getBoundingClientRect(); } let rect = { left: 0, top: 0, right: 0, bottom: 0 }; - switch (e.getAttribute('shape')) { - case 'rect': - case 'rectangle': - rect = rectangleCoordsRect(coords); - break; - case 'circ': - case 'circle': - rect = circleCoordsRect(coords); - break; - case 'poly': - case 'polygon': - rect = polygonCoordsRect(coords); - break; + switch (e.getAttribute("shape")) { + case "rect": + case "rectangle": + rect = rectangleCoordsRect(coords); + break; + case "circ": + case "circle": + rect = circleCoordsRect(coords); + break; + case "poly": + case "polygon": + rect = polygonCoordsRect(coords); + break; } return { left: rect.left + mapLeft, @@ -99,7 +96,7 @@ const isVisible = (element: Element): boolean => { const rect = element.getBoundingClientRect(); const style = window.getComputedStyle(element); - if (style.overflow !== 'visible' && (rect.width === 0 || rect.height === 0)) { + if (style.overflow !== "visible" && (rect.width === 0 || rect.height === 0)) { return false; } if (rect.right < 0 && rect.bottom < 0) { @@ -108,13 +105,15 @@ const isVisible = (element: Element): boolean => { if (window.innerWidth < rect.left && window.innerHeight < rect.top) { return false; } - if (element instanceof HTMLInputElement && - element.type.toLowerCase() === 'hidden') { + if ( + element instanceof HTMLInputElement && + element.type.toLowerCase() === "hidden" + ) { return false; } const { display, visibility } = window.getComputedStyle(element); - if (display === 'none' || visibility === 'hidden') { + if (display === "none" || visibility === "hidden") { return false; } return true; |