diff --git a/ext/js/display/display.js b/ext/js/display/display.js index 2867e6bcc7..81eccabe5f 100644 --- a/ext/js/display/display.js +++ b/ext/js/display/display.js @@ -199,25 +199,25 @@ export class Display extends EventDispatcher { /* eslint-disable @stylistic/no-multi-spaces */ this._hotkeyHandler.registerActions([ - ['close', () => { this._onHotkeyClose(); }], - ['nextEntry', this._onHotkeyActionMoveRelative.bind(this, 1)], - ['previousEntry', this._onHotkeyActionMoveRelative.bind(this, -1)], - ['lastEntry', () => { this._focusEntry(this._dictionaryEntries.length - 1, 0, true); }], - ['firstEntry', () => { this._focusEntry(0, 0, true); }], - ['historyBackward', () => { this._sourceTermView(); }], - ['historyForward', () => { this._nextTermView(); }], - ['profilePrevious', async () => { await setProfile(-1, this._application); }], - ['profileNext', async () => { await setProfile(1, this._application); }], + ['close', () => {this._onHotkeyClose();}], + ['nextEntry', this._onHotkeyActionMoveRelative.bind(this, 1)], + ['previousEntry', this._onHotkeyActionMoveRelative.bind(this, -1)], + ['lastEntry', () => {this._focusEntry(this._dictionaryEntries.length - 1, 0, true);}], + ['firstEntry', () => {this._focusEntry(0, 0, true);}], + ['historyBackward', () => {this._sourceTermView();}], + ['historyForward', () => {this._nextTermView();}], + ['profilePrevious', async () => {await setProfile(-1, this._application);}], + ['profileNext', async () => {await setProfile(1, this._application);}], ['copyHostSelection', () => this._copyHostSelection()], - ['nextEntryDifferentDictionary', () => { this._focusEntryWithDifferentDictionary(1, true); }], - ['previousEntryDifferentDictionary', () => { this._focusEntryWithDifferentDictionary(-1, true); }], + ['nextEntryDifferentDictionary', () => {this._focusEntryWithDifferentDictionary(1, true);}], + ['previousEntryDifferentDictionary', () => {this._focusEntryWithDifferentDictionary(-1, true);}], ]); this.registerDirectMessageHandlers([ ['displaySetOptionsContext', this._onMessageSetOptionsContext.bind(this)], - ['displaySetContent', this._onMessageSetContent.bind(this)], - ['displaySetCustomCss', this._onMessageSetCustomCss.bind(this)], - ['displaySetContentScale', this._onMessageSetContentScale.bind(this)], - ['displayConfigure', this._onMessageConfigure.bind(this)], + ['displaySetContent', this._onMessageSetContent.bind(this)], + ['displaySetCustomCss', this._onMessageSetCustomCss.bind(this)], + ['displaySetContentScale', this._onMessageSetContentScale.bind(this)], + ['displayConfigure', this._onMessageConfigure.bind(this)], ['displayVisibilityChanged', this._onMessageVisibilityChanged.bind(this)], ]); this.registerWindowMessageHandlers([ @@ -392,7 +392,7 @@ export class Display extends EventDispatcher { * @param {Error} error */ onError(error) { - if (this._application.webExtension.unloaded) { return; } + if (this._application.webExtension.unloaded) {return;} log.error(error); } @@ -408,7 +408,7 @@ export class Display extends EventDispatcher { * @throws {Error} */ getLanguageSummary() { - if (this._options === null) { throw new Error('Options is null'); } + if (this._options === null) {throw new Error('Options is null');} const language = this._options.general.language; return /** @type {import('language').LanguageSummary} */ (this._languageSummaries.find(({iso}) => iso === language)); } @@ -489,7 +489,7 @@ export class Display extends EventDispatcher { const urlSearchParams = new URLSearchParams(); for (const [key, value] of Object.entries(params)) { - if (typeof value !== 'string') { continue; } + if (typeof value !== 'string') {continue;} urlSearchParams.append(key, value); } const url = `${location.protocol}//${location.host}${location.pathname}?${urlSearchParams.toString()}`; @@ -518,7 +518,7 @@ export class Display extends EventDispatcher { */ setCustomCss(css) { if (this._styleNode === null) { - if (css.length === 0) { return; } + if (css.length === 0) {return;} this._styleNode = document.createElement('style'); } @@ -581,21 +581,21 @@ export class Display extends EventDispatcher { */ searchLast(updateOptionsContext) { const type = this._contentType; - if (type === 'clear') { return; } + if (type === 'clear') {return;} const query = this._query; const {state} = this._history; const hasState = typeof state === 'object' && state !== null; /** @type {import('display').HistoryState} */ const newState = ( hasState ? - clone(state) : - { - focusEntry: 0, - optionsContext: void 0, - url: window.location.href, - sentence: {text: query, offset: 0}, - documentTitle: document.title, - } + clone(state) : + { + focusEntry: 0, + optionsContext: void 0, + url: window.location.href, + sentence: {text: query, offset: 0}, + documentTitle: document.title, + } ); if (!hasState || updateOptionsContext) { newState.optionsContext = clone(this._optionsContext); @@ -649,9 +649,9 @@ export class Display extends EventDispatcher { */ getElementDictionaryEntryIndex(element) { const node = /** @type {?HTMLElement} */ (element.closest('.entry')); - if (node === null) { return -1; } + if (node === null) {return -1;} const {index} = node.dataset; - if (typeof index !== 'string') { return -1; } + if (typeof index !== 'string') {return -1;} const indexNumber = Number.parseInt(index, 10); return Number.isFinite(indexNumber) ? indexNumber : -1; } @@ -716,7 +716,7 @@ export class Display extends EventDispatcher { try { const {action, params} = data2; - const callback = () => {}; // NOP + const callback = () => { }; // NOP invokeApiMapHandler(this._windowApiMap, action, params, [], callback); } catch (e) { // NOP @@ -782,7 +782,7 @@ export class Display extends EventDispatcher { /** */ async _onStateChanged() { - if (this._historyChangeIgnore) { return; } + if (this._historyChangeIgnore) {return;} performance.mark('display:onStateChanged:start'); @@ -808,7 +808,7 @@ export class Display extends EventDispatcher { performance.mark('display:prepare:start'); const urlSearchParams = new URLSearchParams(location.search); let type = urlSearchParams.get('type'); - if (type === null && urlSearchParams.get('query') !== null) { type = 'terms'; } + if (type === null && urlSearchParams.get('query') !== null) {type = 'terms';} const fullVisible = urlSearchParams.get('full-visible'); this._queryParserVisibleOverride = (fullVisible === null ? null : (fullVisible !== 'false')); @@ -851,10 +851,10 @@ export class Display extends EventDispatcher { const historyState = this._history.state; const historyMode = ( eventType === 'click' || - !(typeof historyState === 'object' && historyState !== null) || - historyState.cause !== 'queryParser' ? - 'new' : - 'overwrite' + !(typeof historyState === 'object' && historyState !== null) || + historyState.cause !== 'queryParser' ? + 'new' : + 'overwrite' ); /** @type {import('display').ContentDetails} */ const details = { @@ -877,7 +877,7 @@ export class Display extends EventDispatcher { /** */ _onExtensionUnloaded() { const type = 'unloaded'; - if (this._contentType === type) { return; } + if (this._contentType === type) {return;} const {tabId, frameId} = this._application; /** @type {import('display').ContentDetails} */ const details = { @@ -945,15 +945,15 @@ export class Display extends EventDispatcher { try { e.preventDefault(); const {state} = this._history; - if (!(typeof state === 'object' && state !== null)) { return; } + if (!(typeof state === 'object' && state !== null)) {return;} let {sentence, url, documentTitle} = state; - if (typeof url !== 'string') { url = window.location.href; } - if (typeof documentTitle !== 'string') { documentTitle = document.title; } + if (typeof url !== 'string') {url = window.location.href;} + if (typeof documentTitle !== 'string') {documentTitle = document.title;} const optionsContext = this.getOptionsContext(); const element = /** @type {Element} */ (e.currentTarget); let query = element.textContent; - if (query === null) { query = ''; } + if (query === null) {query = '';} const dictionaryEntries = await this._application.api.kanjiFind(query, optionsContext); /** @type {import('display').ContentDetails} */ const details = { @@ -996,7 +996,7 @@ export class Display extends EventDispatcher { * @param {WheelEvent} e */ _onHistoryWheel(e) { - if (e.altKey) { return; } + if (e.altKey) {return;} const delta = -e.deltaX || e.deltaY; if (delta > 0) { this._sourceTermView(); @@ -1060,12 +1060,12 @@ export class Display extends EventDispatcher { * @param {MouseEvent} e */ _onEntryClick(e) { - if (e.button !== 0) { return; } + if (e.button !== 0) {return;} const node = /** @type {HTMLElement} */ (e.currentTarget); const {index} = node.dataset; - if (typeof index !== 'string') { return; } + if (typeof index !== 'string') {return;} const indexNumber = Number.parseInt(index, 10); - if (!Number.isFinite(indexNumber)) { return; } + if (!Number.isFinite(indexNumber)) {return;} this._entrySetCurrent(indexNumber); } @@ -1133,7 +1133,7 @@ export class Display extends EventDispatcher { */ _showTagNotification(tagNode) { const parent = tagNode.parentNode; - if (parent === null || !(parent instanceof HTMLElement)) { return; } + if (parent === null || !(parent instanceof HTMLElement)) {return;} if (this._tagNotification === null) { this._tagNotification = this.createNotification(true); @@ -1152,7 +1152,7 @@ export class Display extends EventDispatcher { */ _showInflectionNotification(inflectionNode) { const description = inflectionNode.title; - if (!description || !(inflectionNode instanceof HTMLSpanElement)) { return; } + if (!description || !(inflectionNode instanceof HTMLSpanElement)) {return;} if (this._inflectionNotification === null) { this._inflectionNotification = this.createNotification(true); @@ -1166,7 +1166,7 @@ export class Display extends EventDispatcher { * @param {boolean} animate */ _hideTagNotification(animate) { - if (this._tagNotification === null) { return; } + if (this._tagNotification === null) {return;} this._tagNotification.close(animate); } @@ -1174,7 +1174,7 @@ export class Display extends EventDispatcher { * @param {boolean} animate */ _hideInflectionNotification(animate) { - if (this._inflectionNotification === null) { return; } + if (this._inflectionNotification === null) {return;} this._inflectionNotification.close(animate); } @@ -1274,12 +1274,12 @@ export class Display extends EventDispatcher { const {findDetails, source: source2} = this._getFindDetails(source, wildcardsEnabled); if (isKanji) { dictionaryEntries = await this._application.api.kanjiFind(source, optionsContext); - if (dictionaryEntries.length > 0) { return dictionaryEntries; } + if (dictionaryEntries.length > 0) {return dictionaryEntries;} dictionaryEntries = (await this._application.api.termsFind(source2, findDetails, optionsContext)).dictionaryEntries; } else { dictionaryEntries = (await this._application.api.termsFind(source2, findDetails, optionsContext)).dictionaryEntries; - if (dictionaryEntries.length > 0) { return dictionaryEntries; } + if (dictionaryEntries.length > 0) {return dictionaryEntries;} dictionaryEntries = await this._application.api.kanjiFind(source, optionsContext); } @@ -1323,7 +1323,7 @@ export class Display extends EventDispatcher { // Set query performance.mark('display:setQuery:start'); let query = urlSearchParams.get('query'); - if (query === null) { query = ''; } + if (query === null) {query = '';} let queryFull = urlSearchParams.get('full'); queryFull = (queryFull !== null ? queryFull : query); const queryOffsetString = urlSearchParams.get('offset'); @@ -1348,7 +1348,7 @@ export class Display extends EventDispatcher { } let {focusEntry, scrollX, scrollY, optionsContext} = state; - if (typeof focusEntry !== 'number') { focusEntry = 0; } + if (typeof focusEntry !== 'number') {focusEntry = 0;} if (!(typeof optionsContext === 'object' && optionsContext !== null)) { optionsContext = this.getOptionsContext(); state.optionsContext = optionsContext; @@ -1361,7 +1361,7 @@ export class Display extends EventDispatcher { dictionaryEntries = hasEnabledDictionaries && lookup && query.length > 0 ? await this._findDictionaryEntries(type === 'kanji', query, wildcardsEnabled, optionsContext) : []; performance.mark('display:findDictionaryEntries:end'); performance.measure('display:findDictionaryEntries', 'display:findDictionaryEntries:start', 'display:findDictionaryEntries:end'); - if (this._setContentToken !== token) { return; } + if (this._setContentToken !== token) {return;} content.dictionaryEntries = dictionaryEntries; changeHistory = true; } @@ -1382,11 +1382,11 @@ export class Display extends EventDispatcher { } await this._setOptionsContextIfDifferent(optionsContext); - if (this._setContentToken !== token) { return; } + if (this._setContentToken !== token) {return;} if (this._options === null) { await this.updateOptions(); - if (this._setContentToken !== token) { return; } + if (this._setContentToken !== token) {return;} } if (changeHistory) { @@ -1415,13 +1415,13 @@ export class Display extends EventDispatcher { if (i > 0) { await promiseTimeout(1); - if (this._setContentToken !== token) { return; } + if (this._setContentToken !== token) {return;} } const entry = ( dictionaryEntry.type === 'term' ? - await this._displayGenerator.createTermEntry(dictionaryEntry) : - await this._displayGenerator.createKanjiEntry(dictionaryEntry) + await this._displayGenerator.createTermEntry(dictionaryEntry) : + await this._displayGenerator.createKanjiEntry(dictionaryEntry) ); entry.dataset.index = `${i}`; this._dictionaryEntryNodes.push(entry); @@ -1431,7 +1431,7 @@ export class Display extends EventDispatcher { await this._contentManager.executeMediaRequests(); performance.mark('display:waitMedia:end'); performance.measure('display:waitMedia', 'display:waitMedia:start', 'display:waitMedia:end'); - if (this._setContentToken !== token) { return; } + if (this._setContentToken !== token) {return;} container.appendChild(entry); if (focusEntry === i) { @@ -1448,8 +1448,8 @@ export class Display extends EventDispatcher { if (typeof scrollX === 'number' || typeof scrollY === 'number') { let {x, y} = this._windowScroll; - if (typeof scrollX === 'number') { x = scrollX; } - if (typeof scrollY === 'number') { y = scrollY; } + if (typeof scrollX === 'number') {x = scrollX;} + if (typeof scrollY === 'number') {y = scrollY;} this._windowScroll.stop(); this._windowScroll.to(x, y); } @@ -1652,22 +1652,22 @@ export class Display extends EventDispatcher { */ _focusEntryWithDifferentDictionary(offset, smooth) { const sign = Math.sign(offset); - if (sign === 0) { return false; } + if (sign === 0) {return false;} let index = this._index; const count = Math.min(this._dictionaryEntries.length, this._dictionaryEntryNodes.length); - if (index < 0 || index >= count) { return false; } + if (index < 0 || index >= count) {return false;} const dictionaryEntry = this._dictionaryEntries[index]; const visibleDefinitionIndex = this._getDictionaryEntryVisibleDefinitionIndex(index, sign); - if (visibleDefinitionIndex === null) { return false; } + if (visibleDefinitionIndex === null) {return false;} let focusDefinitionIndex = null; if (dictionaryEntry.type === 'term') { const {dictionary} = dictionaryEntry.definitions[visibleDefinitionIndex]; for (let i = index; i >= 0 && i < count; i += sign) { const otherDictionaryEntry = this._dictionaryEntries[i]; - if (otherDictionaryEntry.type !== 'term') { continue; } + if (otherDictionaryEntry.type !== 'term') {continue;} const {definitions} = otherDictionaryEntry; const jj = definitions.length; let j = (i === index ? visibleDefinitionIndex + sign : (sign > 0 ? 0 : jj - 1)); @@ -1682,7 +1682,7 @@ export class Display extends EventDispatcher { } } - if (focusDefinitionIndex === null) { return false; } + if (focusDefinitionIndex === null) {return false;} this._focusEntry(index, focusDefinitionIndex, smooth); return true; @@ -1699,13 +1699,13 @@ export class Display extends EventDispatcher { const {definitions} = this._dictionaryEntries[index]; const nodes = this._getDictionaryEntryDefinitionNodes(index); const definitionCount = Math.min(definitions.length, nodes.length); - if (definitionCount <= 0) { return null; } + if (definitionCount <= 0) {return null;} let visibleIndex = null; let visibleCoverage = 0; for (let i = (sign > 0 ? 0 : definitionCount - 1); i >= 0 && i < definitionCount; i += sign) { const {top, bottom} = nodes[i].getBoundingClientRect(); - if (bottom <= scrollTop || top >= scrollBottom) { continue; } + if (bottom <= scrollTop || top >= scrollBottom) {continue;} const top2 = Math.max(scrollTop, Math.min(scrollBottom, top)); const bottom2 = Math.max(scrollTop, Math.min(scrollBottom, bottom)); const coverage = (bottom2 - top2) / (bottom - top); @@ -1743,8 +1743,8 @@ export class Display extends EventDispatcher { _relativeTermView(next) { return ( next ? - this._history.hasNext() && this._history.forward() : - this._history.hasPrevious() && this._history.back() + this._history.hasNext() && this._history.forward() : + this._history.hasPrevious() && this._history.back() ); } @@ -1770,7 +1770,7 @@ export class Display extends EventDispatcher { /** */ _updateHistoryState() { const {state, content} = this._history; - if (!(typeof state === 'object' && state !== null)) { return; } + if (!(typeof state === 'object' && state !== null)) {return;} state.focusEntry = this._index; state.scrollX = this._windowScroll.x; @@ -1829,8 +1829,8 @@ export class Display extends EventDispatcher { _isQueryParserVisible() { return ( this._queryParserVisibleOverride !== null ? - this._queryParserVisibleOverride : - this._queryParserVisible + this._queryParserVisibleOverride : + this._queryParserVisible ); } @@ -1843,7 +1843,7 @@ export class Display extends EventDispatcher { * @param {import('settings').OptionsContext} optionsContext */ async _setOptionsContextIfDifferent(optionsContext) { - if (deepEqual(this._optionsContext, optionsContext)) { return; } + if (deepEqual(this._optionsContext, optionsContext)) {return;} await this.setOptionsContext(optionsContext); } @@ -1852,7 +1852,7 @@ export class Display extends EventDispatcher { */ _setContentScale(scale) { const body = document.body; - if (body === null) { return; } + if (body === null) {return;} body.style.fontSize = `${scale}em`; } @@ -1861,20 +1861,20 @@ export class Display extends EventDispatcher { */ async _updateNestedFrontend(options) { const {tabId, frameId} = this._application; - if (tabId === null || frameId === null) { return; } + if (tabId === null || frameId === null) {return;} const isSearchPage = (this._pageType === 'search'); const isEnabled = ( this._childrenSupported && ( (isSearchPage) ? - (options.scanning.enableOnSearchPage) : - (this._depth < options.scanning.popupNestingMaxDepth) + (options.scanning.enableOnSearchPage) : + (this._depth < options.scanning.popupNestingMaxDepth) ) ); if (this._frontend === null) { - if (!isEnabled) { return; } + if (!isEnabled) {return;} try { if (this._frontendSetupPromise === null) { @@ -1927,9 +1927,9 @@ export class Display extends EventDispatcher { * @returns {boolean} */ _copyHostSelection() { - if (typeof this._contentOriginFrameId !== 'number') { return false; } + if (typeof this._contentOriginFrameId !== 'number') {return false;} const selection = window.getSelection(); - if (selection !== null && selection.toString().length > 0) { return false; } + if (selection !== null && selection.toString().length > 0) {return false;} void this._copyHostSelectionSafe(); return true; } @@ -1970,7 +1970,7 @@ export class Display extends EventDispatcher { */ _copyText(text) { const parent = document.body; - if (parent === null) { return; } + if (parent === null) {return;} let textarea = this._copyTextarea; if (textarea === null) { @@ -2178,15 +2178,15 @@ export class Display extends EventDispatcher { /** */ async _closeTab() { const tab = await this._getCurrentTab(); - if (tab === null) { return; } + if (tab === null) {return;} const tabId = tab.id; - if (typeof tabId === 'undefined') { return; } + if (typeof tabId === 'undefined') {return;} await this._removeTab(tabId); } /** */ _onHotkeyClose() { - if (this._closeSinglePopupMenu()) { return; } + if (this._closeSinglePopupMenu()) {return;} this.close(); } @@ -2196,7 +2196,7 @@ export class Display extends EventDispatcher { */ _onHotkeyActionMoveRelative(sign, argument) { let count = typeof argument === 'number' ? argument : (typeof argument === 'string' ? Number.parseInt(argument, 10) : 0); - if (!Number.isFinite(count)) { count = 1; } + if (!Number.isFinite(count)) {count = 1;} count = Math.max(0, Math.floor(count)); this._focusEntry(this._index + count * sign, 0, true); } @@ -2223,7 +2223,7 @@ export class Display extends EventDispatcher { * @param {number} index */ async _logDictionaryEntryData(index) { - if (index < 0 || index >= this._dictionaryEntries.length) { return; } + if (index < 0 || index >= this._dictionaryEntries.length) {return;} const dictionaryEntry = this._dictionaryEntries[index]; const result = {dictionaryEntry};