From c4134168be8bf8df4e7ba4860e3d99b3c2256734 Mon Sep 17 00:00:00 2001 From: starxeras Date: Fri, 10 Nov 2023 19:48:27 -0600 Subject: `yomichan` -> `yomitan` --- ext/js/app/content-script-main.js | 8 +- ext/js/app/frontend.js | 34 +-- ext/js/app/popup-factory.js | 6 +- ext/js/app/popup-proxy.js | 6 +- ext/js/app/popup-window.js | 14 +- ext/js/app/popup.js | 10 +- ext/js/background/backend.js | 34 +-- ext/js/background/background-main.js | 4 +- ext/js/background/offscreen.js | 6 +- ext/js/comm/api.js | 6 +- ext/js/comm/cross-frame-api.js | 6 +- ext/js/comm/frame-ancestry-handler.js | 8 +- ext/js/comm/frame-endpoint.js | 6 +- ext/js/comm/frame-offset-forwarder.js | 6 +- ext/js/comm/mecab.js | 8 +- ext/js/data/anki-note-builder.js | 6 +- ext/js/data/options-util.js | 2 +- ext/js/display/display-anki.js | 14 +- ext/js/display/display-audio.js | 4 +- ext/js/display/display-content-manager.js | 4 +- ext/js/display/display-generator.js | 4 +- ext/js/display/display-profile-selection.js | 8 +- ext/js/display/display.js | 30 +-- ext/js/display/option-toggle-hotkey-handler.js | 6 +- ext/js/display/popup-main.js | 8 +- ext/js/display/query-parser.js | 6 +- ext/js/display/search-display-controller.js | 10 +- ext/js/display/search-main.js | 8 +- ext/js/input/hotkey-handler.js | 4 +- ext/js/input/hotkey-help-controller.js | 4 +- ext/js/language/text-scanner.js | 16 +- ext/js/pages/action-popup-main.js | 22 +- ext/js/pages/info-main.js | 10 +- ext/js/pages/permissions-main.js | 6 +- ext/js/pages/settings/anki-controller.js | 6 +- ext/js/pages/settings/anki-templates-controller.js | 6 +- ext/js/pages/settings/backup-controller.js | 20 +- .../settings/collapsible-dictionary-controller.js | 4 +- ext/js/pages/settings/dictionary-controller.js | 8 +- .../pages/settings/dictionary-import-controller.js | 8 +- .../extension-keyboard-shortcuts-controller.js | 4 +- .../settings/keyboard-shortcuts-controller.js | 4 +- ext/js/pages/settings/mecab-controller.js | 4 +- .../settings/persistent-storage-controller.js | 4 +- ext/js/pages/settings/popup-preview-frame-main.js | 6 +- ext/js/pages/settings/popup-preview-frame.js | 6 +- ext/js/pages/settings/popup-window-controller.js | 4 +- ext/js/pages/settings/profile-controller.js | 4 +- ext/js/pages/settings/scan-inputs-controller.js | 4 +- .../settings/scan-inputs-simple-controller.js | 4 +- .../secondary-search-dictionary-controller.js | 4 +- ext/js/pages/settings/settings-controller.js | 16 +- ext/js/pages/settings/settings-main.js | 4 +- .../sort-frequency-dictionary-controller.js | 6 +- ext/js/pages/settings/storage-controller.js | 4 +- ext/js/pages/welcome-main.js | 6 +- ext/js/script/dynamic-loader-sentinel.js | 4 +- ext/js/script/dynamic-loader.js | 14 +- ext/js/yomichan.js | 241 --------------------- ext/js/yomitan.js | 241 +++++++++++++++++++++ 60 files changed, 485 insertions(+), 485 deletions(-) delete mode 100644 ext/js/yomichan.js create mode 100644 ext/js/yomitan.js (limited to 'ext') diff --git a/ext/js/app/content-script-main.js b/ext/js/app/content-script-main.js index d5ae0d93..a042f3bf 100644 --- a/ext/js/app/content-script-main.js +++ b/ext/js/app/content-script-main.js @@ -18,15 +18,15 @@ import {log} from '../core.js'; import {HotkeyHandler} from '../input/hotkey-handler.js'; -import {yomichan} from '../yomichan.js'; +import {yomitan} from '../yomitan.js'; import {Frontend} from './frontend.js'; import {PopupFactory} from './popup-factory.js'; (async () => { try { - await yomichan.prepare(); + await yomitan.prepare(); - const {tabId, frameId} = await yomichan.api.frameInformationGet(); + const {tabId, frameId} = await yomitan.api.frameInformationGet(); if (typeof frameId !== 'number') { throw new Error('Failed to get frameId'); } @@ -51,7 +51,7 @@ import {PopupFactory} from './popup-factory.js'; }); await frontend.prepare(); - yomichan.ready(); + yomitan.ready(); } catch (e) { log.error(e); } diff --git a/ext/js/app/frontend.js b/ext/js/app/frontend.js index acc70667..4c13eac2 100644 --- a/ext/js/app/frontend.js +++ b/ext/js/app/frontend.js @@ -23,7 +23,7 @@ import {TextSourceElement} from '../dom/text-source-element.js'; import {TextSourceRange} from '../dom/text-source-range.js'; import {HotkeyHandler} from '../input/hotkey-handler.js'; import {TextScanner} from '../language/text-scanner.js'; -import {yomichan} from '../yomichan.js'; +import {yomitan} from '../yomitan.js'; import {PopupFactory} from './popup-factory.js'; import {Popup} from './popup.js'; @@ -137,7 +137,7 @@ export class Frontend { async prepare() { await this.updateOptions(); try { - const {zoomFactor} = await yomichan.api.getZoom(); + const {zoomFactor} = await yomitan.api.getZoom(); this._pageZoomFactor = zoomFactor; } catch (e) { // Ignore exceptions which may occur due to being on an unsupported page (e.g. about:blank) @@ -154,15 +154,15 @@ export class Frontend { visualViewport.addEventListener('resize', this._onVisualViewportResize.bind(this)); } - yomichan.on('optionsUpdated', this.updateOptions.bind(this)); - yomichan.on('zoomChanged', this._onZoomChanged.bind(this)); - yomichan.on('closePopups', this._onClosePopups.bind(this)); + yomitan.on('optionsUpdated', this.updateOptions.bind(this)); + yomitan.on('zoomChanged', this._onZoomChanged.bind(this)); + yomitan.on('closePopups', this._onClosePopups.bind(this)); chrome.runtime.onMessage.addListener(this._onRuntimeMessage.bind(this)); this._textScanner.on('clear', this._onTextScannerClear.bind(this)); this._textScanner.on('searched', this._onSearched.bind(this)); - yomichan.crossFrame.registerHandlers([ + yomitan.crossFrame.registerHandlers([ ['Frontend.closePopup', {async: false, handler: this._onApiClosePopup.bind(this)}], ['Frontend.copySelection', {async: false, handler: this._onApiCopySelection.bind(this)}], ['Frontend.getSelectionText', {async: false, handler: this._onApiGetSelectionText.bind(this)}], @@ -208,7 +208,7 @@ export class Frontend { try { await this._updateOptionsInternal(); } catch (e) { - if (!yomichan.isExtensionUnloaded) { + if (!yomitan.isExtensionUnloaded) { throw e; } } @@ -319,7 +319,7 @@ export class Frontend { const scanningOptions = this._options.scanning; if (error !== null) { - if (yomichan.isExtensionUnloaded) { + if (yomitan.isExtensionUnloaded) { if (textSource !== null && !passive) { this._showExtensionUnloaded(textSource); } @@ -388,7 +388,7 @@ export class Frontend { async _updateOptionsInternal() { const optionsContext = await this._getOptionsContext(); - const options = await yomichan.api.optionsGet(optionsContext); + const options = await yomitan.api.optionsGet(optionsContext); const {scanning: scanningOptions, sentenceParsing: sentenceParsingOptions} = options; this._options = options; @@ -520,7 +520,7 @@ export class Frontend { return await this._getDefaultPopup(); } - const {popupId} = await yomichan.crossFrame.invoke(targetFrameId, 'Frontend.getPopupInfo'); + const {popupId} = await yomitan.crossFrame.invoke(targetFrameId, 'Frontend.getPopupInfo'); if (popupId === null) { return null; } @@ -559,7 +559,7 @@ export class Frontend { try { return this._popup !== null && await this._popup.containsPoint(x, y); } catch (e) { - if (!yomichan.isExtensionUnloaded) { + if (!yomitan.isExtensionUnloaded) { throw e; } return false; @@ -625,7 +625,7 @@ export class Frontend { Promise.resolve() ); this._lastShowPromise.catch((error) => { - if (yomichan.isExtensionUnloaded) { return; } + if (yomitan.isExtensionUnloaded) { return; } log.error(error); }); return this._lastShowPromise; @@ -677,9 +677,9 @@ export class Frontend { _signalFrontendReady(targetFrameId=null) { const params = {frameId: this._frameId}; if (targetFrameId === null) { - yomichan.api.broadcastTab('frontendReady', params); + yomitan.api.broadcastTab('frontendReady', params); } else { - yomichan.api.sendMessageToFrame(targetFrameId, 'frontendReady', params); + yomitan.api.sendMessageToFrame(targetFrameId, 'frontendReady', params); } } @@ -716,7 +716,7 @@ export class Frontend { } chrome.runtime.onMessage.addListener(onMessage); - yomichan.api.broadcastTab('Frontend.requestReadyBroadcast', {frameId: this._frameId}); + yomitan.api.broadcastTab('Frontend.requestReadyBroadcast', {frameId: this._frameId}); }); } @@ -742,7 +742,7 @@ export class Frontend { let documentTitle = document.title; if (this._useProxyPopup) { try { - ({url, documentTitle} = await yomichan.crossFrame.invoke(this._parentFrameId, 'Frontend.getPageInfo', {})); + ({url, documentTitle} = await yomitan.crossFrame.invoke(this._parentFrameId, 'Frontend.getPageInfo', {})); } catch (e) { // NOP } @@ -788,7 +788,7 @@ export class Frontend { async _prepareGoogleDocs() { if (typeof GoogleDocsUtil !== 'undefined') { return; } - await yomichan.api.loadExtensionScripts([ + await yomitan.api.loadExtensionScripts([ '/js/accessibility/google-docs-util.js' ]); if (typeof GoogleDocsUtil === 'undefined') { return; } diff --git a/ext/js/app/popup-factory.js b/ext/js/app/popup-factory.js index 7a17c106..e871f7ec 100644 --- a/ext/js/app/popup-factory.js +++ b/ext/js/app/popup-factory.js @@ -18,7 +18,7 @@ import {FrameOffsetForwarder} from '../comm/frame-offset-forwarder.js'; import {generateId} from '../core.js'; -import {yomichan} from '../yomichan.js'; +import {yomitan} from '../yomitan.js'; import {PopupProxy} from './popup-proxy.js'; import {PopupWindow} from './popup-window.js'; import {Popup} from './popup.js'; @@ -43,7 +43,7 @@ export class PopupFactory { */ prepare() { this._frameOffsetForwarder.prepare(); - yomichan.crossFrame.registerHandlers([ + yomitan.crossFrame.registerHandlers([ ['PopupFactory.getOrCreatePopup', {async: true, handler: this._onApiGetOrCreatePopup.bind(this)}], ['PopupFactory.setOptionsContext', {async: true, handler: this._onApiSetOptionsContext.bind(this)}], ['PopupFactory.hide', {async: false, handler: this._onApiHide.bind(this)}], @@ -151,7 +151,7 @@ export class PopupFactory { throw new Error('Invalid frameId'); } const useFrameOffsetForwarder = (parentPopupId === null); - ({id, depth, frameId} = await yomichan.crossFrame.invoke(frameId, 'PopupFactory.getOrCreatePopup', { + ({id, depth, frameId} = await yomitan.crossFrame.invoke(frameId, 'PopupFactory.getOrCreatePopup', { id, parentPopupId, frameId, diff --git a/ext/js/app/popup-proxy.js b/ext/js/app/popup-proxy.js index d16a16f1..3d8b55ba 100644 --- a/ext/js/app/popup-proxy.js +++ b/ext/js/app/popup-proxy.js @@ -18,7 +18,7 @@ import {FrameOffsetForwarder} from '../comm/frame-offset-forwarder.js'; import {EventDispatcher, log} from '../core.js'; -import {yomichan} from '../yomichan.js'; +import {yomitan} from '../yomitan.js'; import {Popup} from './popup.js'; /** @@ -294,14 +294,14 @@ export class PopupProxy extends EventDispatcher { // Private _invoke(action, params={}) { - return yomichan.crossFrame.invoke(this._frameId, action, params); + return yomitan.crossFrame.invoke(this._frameId, action, params); } async _invokeSafe(action, params={}, defaultReturnValue) { try { return await this._invoke(action, params); } catch (e) { - if (!yomichan.isExtensionUnloaded) { throw e; } + if (!yomitan.isExtensionUnloaded) { throw e; } return defaultReturnValue; } } diff --git a/ext/js/app/popup-window.js b/ext/js/app/popup-window.js index b5fd9eb6..88370684 100644 --- a/ext/js/app/popup-window.js +++ b/ext/js/app/popup-window.js @@ -17,7 +17,7 @@ */ import {EventDispatcher} from '../core.js'; -import {yomichan} from '../yomichan.js'; +import {yomitan} from '../yomitan.js'; import {Popup} from './popup.js'; /** @@ -138,7 +138,7 @@ export class PopupWindow extends EventDispatcher { * @returns {Promise} `true` if the popup is visible, `false` otherwise. */ async isVisible() { - return (this._popupTabId !== null && await yomichan.api.isTabSearchPopup(this._popupTabId)); + return (this._popupTabId !== null && await yomitan.api.isTabSearchPopup(this._popupTabId)); } /** @@ -263,16 +263,16 @@ export class PopupWindow extends EventDispatcher { // Private async _invoke(open, action, params={}, defaultReturnValue) { - if (yomichan.isExtensionUnloaded) { + if (yomitan.isExtensionUnloaded) { return defaultReturnValue; } const frameId = 0; if (this._popupTabId !== null) { try { - return await yomichan.crossFrame.invokeTab(this._popupTabId, frameId, 'popupMessage', {action, params}); + return await yomitan.crossFrame.invokeTab(this._popupTabId, frameId, 'popupMessage', {action, params}); } catch (e) { - if (yomichan.isExtensionUnloaded) { + if (yomitan.isExtensionUnloaded) { open = false; } } @@ -283,9 +283,9 @@ export class PopupWindow extends EventDispatcher { return defaultReturnValue; } - const {tabId} = await yomichan.api.getOrCreateSearchPopup({focus: 'ifCreated'}); + const {tabId} = await yomitan.api.getOrCreateSearchPopup({focus: 'ifCreated'}); this._popupTabId = tabId; - return await yomichan.crossFrame.invokeTab(this._popupTabId, frameId, 'popupMessage', {action, params}); + return await yomitan.crossFrame.invokeTab(this._popupTabId, frameId, 'popupMessage', {action, params}); } } diff --git a/ext/js/app/popup.js b/ext/js/app/popup.js index 90f73847..0e2e2493 100644 --- a/ext/js/app/popup.js +++ b/ext/js/app/popup.js @@ -20,7 +20,7 @@ import {FrameClient} from '../comm/frame-client.js'; import {DynamicProperty, EventDispatcher, EventListenerCollection, deepEqual} from '../core.js'; import {DocumentUtil} from '../dom/document-util.js'; import {dynamicLoader} from '../script/dynamic-loader.js'; -import {yomichan} from '../yomichan.js'; +import {yomitan} from '../yomitan.js'; import {ThemeController} from './theme-controller.js'; /** @@ -208,7 +208,7 @@ export class Popup extends EventDispatcher { this._frame.addEventListener('scroll', (e) => e.stopPropagation()); this._frame.addEventListener('load', this._onFrameLoad.bind(this)); this._visible.on('change', this._onVisibleChange.bind(this)); - yomichan.on('extensionUnloaded', this._onExtensionUnloaded.bind(this)); + yomitan.on('extensionUnloaded', this._onExtensionUnloaded.bind(this)); this._onVisibleChange({value: this.isVisibleSync()}); this._themeController.prepare(); } @@ -626,14 +626,14 @@ export class Popup extends EventDispatcher { if (this._frameClient === null || !this._frameClient.isConnected() || contentWindow === null) { return; } const message = this._frameClient.createMessage({action, params}); - return await yomichan.crossFrame.invoke(this._frameClient.frameId, 'popupMessage', message); + return await yomitan.crossFrame.invoke(this._frameClient.frameId, 'popupMessage', message); } async _invokeSafe(action, params={}, defaultReturnValue) { try { return await this._invoke(action, params); } catch (e) { - if (!yomichan.isExtensionUnloaded) { throw e; } + if (!yomitan.isExtensionUnloaded) { throw e; } return defaultReturnValue; } } @@ -884,7 +884,7 @@ export class Popup extends EventDispatcher { async _setOptionsContext(optionsContext) { this._optionsContext = optionsContext; - const options = await yomichan.api.optionsGet(optionsContext); + const options = await yomitan.api.optionsGet(optionsContext); const {general} = options; this._themeController.theme = general.popupTheme; this._themeController.outerTheme = general.popupOuterTheme; diff --git a/ext/js/background/backend.js b/ext/js/background/backend.js index cccfcbb3..e4186d02 100644 --- a/ext/js/background/backend.js +++ b/ext/js/background/backend.js @@ -34,7 +34,7 @@ import {JapaneseUtil} from '../language/sandbox/japanese-util.js'; import {Translator} from '../language/translator.js'; import {AudioDownloader} from '../media/audio-downloader.js'; import {MediaUtil} from '../media/media-util.js'; -import {yomichan} from '../yomichan.js'; +import {yomitan} from '../yomitan.js'; import {ProfileConditionsUtil} from './profile-conditions-util.js'; import {RequestBuilder} from './request-builder.js'; import {ScriptManager} from './script-manager.js'; @@ -225,7 +225,7 @@ export class Backend { }, 1000); this._updateBadge(); - yomichan.on('log', this._onLog.bind(this)); + yomitan.on('log', this._onLog.bind(this)); await this._requestBuilder.prepare(); await this._environment.prepare(); @@ -256,8 +256,8 @@ export class Backend { this._clipboardMonitor.on('change', this._onClipboardTextChange.bind(this)); - this._sendMessageAllTabsIgnoreResponse('Yomichan.backendReady', {}); - this._sendMessageIgnoreResponse({action: 'Yomichan.backendReady', params: {}}); + this._sendMessageAllTabsIgnoreResponse('Yomitan.backendReady', {}); + this._sendMessageIgnoreResponse({action: 'Yomitan.backendReady', params: {}}); } catch (e) { log.error(e); throw e; @@ -344,7 +344,7 @@ export class Backend { } _onZoomChange({tabId, oldZoomFactor, newZoomFactor}) { - this._sendMessageTabIgnoreResponse(tabId, {action: 'Yomichan.zoomChanged', params: {oldZoomFactor, newZoomFactor}}); + this._sendMessageTabIgnoreResponse(tabId, {action: 'Yomitan.zoomChanged', params: {oldZoomFactor, newZoomFactor}}); } _onPermissionsChanged() { @@ -360,7 +360,7 @@ export class Backend { _onApiRequestBackendReadySignal(_params, sender) { // tab ID isn't set in background (e.g. browser_action) - const data = {action: 'Yomichan.backendReady', params: {}}; + const data = {action: 'Yomitan.backendReady', params: {}}; if (typeof sender.tab === 'undefined') { this._sendMessageIgnoreResponse(data); return false; @@ -997,7 +997,7 @@ export class Backend { this._accessibilityController.update(this._getOptionsFull(false)); - this._sendMessageAllTabsIgnoreResponse('Yomichan.optionsUpdated', {source}); + this._sendMessageAllTabsIgnoreResponse('Yomitan.optionsUpdated', {source}); } _getOptionsFull(useSchema=false) { @@ -1328,11 +1328,11 @@ export class Backend { _validatePrivilegedMessageSender(sender) { let {url} = sender; - if (typeof url === 'string' && yomichan.isExtensionUrl(url)) { return; } + if (typeof url === 'string' && yomitan.isExtensionUrl(url)) { return; } const {tab} = url; if (typeof tab === 'object' && tab !== null) { ({url} = tab); - if (typeof url === 'string' && yomichan.isExtensionUrl(url)) { return; } + if (typeof url === 'string' && yomitan.isExtensionUrl(url)) { return; } } throw new Error('Invalid message sender'); } @@ -1432,7 +1432,7 @@ export class Backend { try { const {url} = await this._sendMessageTabPromise( tabId, - {action: 'Yomichan.getUrl', params: {}}, + {action: 'Yomitan.getUrl', params: {}}, {frameId: 0} ); if (typeof url === 'string') { @@ -1568,7 +1568,7 @@ export class Backend { sender.tab.id !== tabId || sender.frameId !== frameId || !isObject(message) || - message.action !== 'yomichanReady' + message.action !== 'yomitanReady' ) { return; } @@ -1589,7 +1589,7 @@ export class Backend { chrome.runtime.onMessage.addListener(onMessage); - this._sendMessageTabPromise(tabId, {action: 'Yomichan.isReady'}, {frameId}) + this._sendMessageTabPromise(tabId, {action: 'Yomitan.isReady'}, {frameId}) .then( (value) => { if (!value) { return; } @@ -1826,7 +1826,7 @@ export class Backend { let extension = MediaUtil.getFileExtensionFromAudioMediaType(contentType); if (extension === null) { extension = '.mp3'; } - let fileName = this._generateAnkiNoteMediaFileName('yomichan_audio', extension, timestamp, definitionDetails); + let fileName = this._generateAnkiNoteMediaFileName('yomitan_audio', extension, timestamp, definitionDetails); fileName = fileName.replace(/\]/g, ''); fileName = await ankiConnect.storeMediaFile(fileName, data); @@ -1843,7 +1843,7 @@ export class Backend { throw new Error('Unknown media type for screenshot image'); } - let fileName = this._generateAnkiNoteMediaFileName('yomichan_browser_screenshot', extension, timestamp, definitionDetails); + let fileName = this._generateAnkiNoteMediaFileName('yomitan_browser_screenshot', extension, timestamp, definitionDetails); fileName = await ankiConnect.storeMediaFile(fileName, data); return fileName; @@ -1861,7 +1861,7 @@ export class Backend { throw new Error('Unknown media type for clipboard image'); } - let fileName = this._generateAnkiNoteMediaFileName('yomichan_clipboard_image', extension, timestamp, definitionDetails); + let fileName = this._generateAnkiNoteMediaFileName('yomitan_clipboard_image', extension, timestamp, definitionDetails); fileName = await ankiConnect.storeMediaFile(fileName, data); return fileName; @@ -1897,7 +1897,7 @@ export class Backend { if (media !== null) { const {content, mediaType} = media; const extension = MediaUtil.getFileExtensionFromImageMediaType(mediaType); - fileName = this._generateAnkiNoteMediaFileName(`yomichan_dictionary_media_${i + 1}`, extension, timestamp, definitionDetails); + fileName = this._generateAnkiNoteMediaFileName(`yomitan_dictionary_media_${i + 1}`, extension, timestamp, definitionDetails); try { fileName = await ankiConnect.storeMediaFile(fileName, content); } catch (e) { @@ -2015,7 +2015,7 @@ export class Backend { _triggerDatabaseUpdated(type, cause) { this._translator.clearDatabaseCaches(); - this._sendMessageAllTabsIgnoreResponse('Yomichan.databaseUpdated', {type, cause}); + this._sendMessageAllTabsIgnoreResponse('Yomitan.databaseUpdated', {type, cause}); } async _saveOptions(source) { diff --git a/ext/js/background/background-main.js b/ext/js/background/background-main.js index 6c30aa7a..8e32a53f 100644 --- a/ext/js/background/background-main.js +++ b/ext/js/background/background-main.js @@ -16,11 +16,11 @@ * along with this program. If not, see . */ -import {yomichan} from '../yomichan.js'; +import {yomitan} from '../yomitan.js'; import {Backend} from './backend.js'; (() => { - yomichan.prepare(true); + yomitan.prepare(true); const backend = new Backend(); backend.prepare(); diff --git a/ext/js/background/offscreen.js b/ext/js/background/offscreen.js index c37cdedc..84ad6141 100644 --- a/ext/js/background/offscreen.js +++ b/ext/js/background/offscreen.js @@ -18,7 +18,7 @@ import {ClipboardReader} from '../comm/clipboard-reader.js'; import {invokeMessageHandler} from '../core.js'; -import {yomichan} from '../yomichan.js'; +import {yomitan} from '../yomitan.js'; /** * This class controls the core logic of the extension, including API calls @@ -63,11 +63,11 @@ export class Offscreen { _validatePrivilegedMessageSender(sender) { let {url} = sender; - if (typeof url === 'string' && yomichan.isExtensionUrl(url)) { return; } + if (typeof url === 'string' && yomitan.isExtensionUrl(url)) { return; } const {tab} = url; if (typeof tab === 'object' && tab !== null) { ({url} = tab); - if (typeof url === 'string' && yomichan.isExtensionUrl(url)) { return; } + if (typeof url === 'string' && yomitan.isExtensionUrl(url)) { return; } } throw new Error('Invalid message sender'); } diff --git a/ext/js/comm/api.js b/ext/js/comm/api.js index 8e5cd5cc..05f95464 100644 --- a/ext/js/comm/api.js +++ b/ext/js/comm/api.js @@ -19,8 +19,8 @@ import {deferPromise, deserializeError, isObject} from '../core.js'; export class API { - constructor(yomichan) { - this._yomichan = yomichan; + constructor(yomitan) { + this._yomitan = yomitan; } optionsGet(optionsContext) { @@ -299,7 +299,7 @@ export class API { const data = {action, params}; return new Promise((resolve, reject) => { try { - this._yomichan.sendMessage(data, (response) => { + this._yomitan.sendMessage(data, (response) => { this._checkLastError(chrome.runtime.lastError); if (response !== null && typeof response === 'object') { if (typeof response.error !== 'undefined') { diff --git a/ext/js/comm/cross-frame-api.js b/ext/js/comm/cross-frame-api.js index c7d9ae68..fe220f21 100644 --- a/ext/js/comm/cross-frame-api.js +++ b/ext/js/comm/cross-frame-api.js @@ -17,7 +17,7 @@ */ import {EventDispatcher, EventListenerCollection, deserializeError, invokeMessageHandler, log, serializeError} from '../core.js'; -import {yomichan} from '../yomichan.js'; +import {yomitan} from '../yomitan.js'; class CrossFrameAPIPort extends EventDispatcher { constructor(otherTabId, otherFrameId, port, messageHandlers) { @@ -233,7 +233,7 @@ export class CrossFrameAPI { async prepare() { chrome.runtime.onConnect.addListener(this._onConnect.bind(this)); - ({tabId: this._tabId, frameId: this._frameId} = await yomichan.api.frameInformationGet()); + ({tabId: this._tabId, frameId: this._frameId} = await yomitan.api.frameInformationGet()); } invoke(targetFrameId, action, params={}) { @@ -304,7 +304,7 @@ export class CrossFrameAPI { } async _createCommPort(otherTabId, otherFrameId) { - await yomichan.api.openCrossFramePort(otherTabId, otherFrameId); + await yomitan.api.openCrossFramePort(otherTabId, otherFrameId); const tabPorts = this._commPorts.get(otherTabId); if (typeof tabPorts !== 'undefined') { diff --git a/ext/js/comm/frame-ancestry-handler.js b/ext/js/comm/frame-ancestry-handler.js index 1934c4ac..eeefac3f 100644 --- a/ext/js/comm/frame-ancestry-handler.js +++ b/ext/js/comm/frame-ancestry-handler.js @@ -17,7 +17,7 @@ */ import {generateId} from '../core.js'; -import {yomichan} from '../yomichan.js'; +import {yomitan} from '../yomitan.js'; /** * This class is used to return the ancestor frame IDs for the current frame. @@ -118,7 +118,7 @@ export class FrameAncestryHandler { clearTimeout(timer); timer = null; } - yomichan.crossFrame.unregisterHandler(responseMessageId); + yomitan.crossFrame.unregisterHandler(responseMessageId); }; const onMessage = (params) => { if (params.nonce !== nonce) { return null; } @@ -148,7 +148,7 @@ export class FrameAncestryHandler { }; // Start - yomichan.crossFrame.registerHandlers([[responseMessageId, {async: false, handler: onMessage}]]); + yomitan.crossFrame.registerHandlers([[responseMessageId, {async: false, handler: onMessage}]]); resetTimeout(); const frameId = this._frameId; this._requestFrameInfo(targetWindow, frameId, frameId, uniqueId, nonce); @@ -187,7 +187,7 @@ export class FrameAncestryHandler { const responseMessageId = `${this._responseMessageIdBase}${uniqueId}`; try { - const response = await yomichan.crossFrame.invoke(originFrameId, responseMessageId, responseParams); + const response = await yomitan.crossFrame.invoke(originFrameId, responseMessageId, responseParams); if (response === null) { return; } nonce = response.nonce; } catch (e) { diff --git a/ext/js/comm/frame-endpoint.js b/ext/js/comm/frame-endpoint.js index 0e8a5c00..5555e60f 100644 --- a/ext/js/comm/frame-endpoint.js +++ b/ext/js/comm/frame-endpoint.js @@ -17,7 +17,7 @@ */ import {EventListenerCollection, generateId, isObject} from '../core.js'; -import {yomichan} from '../yomichan.js'; +import {yomitan} from '../yomitan.js'; export class FrameEndpoint { constructor() { @@ -32,7 +32,7 @@ export class FrameEndpoint { this._eventListeners.addEventListener(window, 'message', this._onMessage.bind(this), false); this._eventListenersSetup = true; } - yomichan.api.broadcastTab('frameEndpointReady', {secret: this._secret}); + yomitan.api.broadcastTab('frameEndpointReady', {secret: this._secret}); } authenticate(message) { @@ -60,6 +60,6 @@ export class FrameEndpoint { this._token = token; this._eventListeners.removeAllEventListeners(); - yomichan.api.sendMessageToFrame(hostFrameId, 'frameEndpointConnected', {secret, token}); + yomitan.api.sendMessageToFrame(hostFrameId, 'frameEndpointConnected', {secret, token}); } } diff --git a/ext/js/comm/frame-offset-forwarder.js b/ext/js/comm/frame-offset-forwarder.js index 5eea2ba6..ef75f1d0 100644 --- a/ext/js/comm/frame-offset-forwarder.js +++ b/ext/js/comm/frame-offset-forwarder.js @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -import {yomichan} from '../yomichan.js'; +import {yomitan} from '../yomitan.js'; import {FrameAncestryHandler} from './frame-ancestry-handler.js'; export class FrameOffsetForwarder { @@ -27,7 +27,7 @@ export class FrameOffsetForwarder { prepare() { this._frameAncestryHandler.prepare(); - yomichan.crossFrame.registerHandlers([ + yomitan.crossFrame.registerHandlers([ ['FrameOffsetForwarder.getChildFrameRect', {async: false, handler: this._onMessageGetChildFrameRect.bind(this)}] ]); } @@ -43,7 +43,7 @@ export class FrameOffsetForwarder { let childFrameId = this._frameId; const promises = []; for (const frameId of ancestorFrameIds) { - promises.push(yomichan.crossFrame.invoke(frameId, 'FrameOffsetForwarder.getChildFrameRect', {frameId: childFrameId})); + promises.push(yomitan.crossFrame.invoke(frameId, 'FrameOffsetForwarder.getChildFrameRect', {frameId: childFrameId})); childFrameId = frameId; } diff --git a/ext/js/comm/mecab.js b/ext/js/comm/mecab.js index 50f13ddf..c7314605 100644 --- a/ext/js/comm/mecab.js +++ b/ext/js/comm/mecab.js @@ -19,7 +19,7 @@ import {EventListenerCollection} from '../core.js'; /** - * This class is used to connect Yomichan to a native component that is + * This class is used to connect Yomitan to a native component that is * used to parse text into individual terms. */ export class Mecab { @@ -99,7 +99,7 @@ export class Mecab { /** * Gets the local API version being used. - * @returns {number} An integer representing the API version that Yomichan uses. + * @returns {number} An integer representing the API version that Yomitan uses. */ getLocalVersion() { return this._version; @@ -219,7 +219,7 @@ export class Mecab { } async _setupPort2() { - const port = chrome.runtime.connectNative('yomichan_mecab'); + const port = chrome.runtime.connectNative('yomitan_mecab'); this._eventListeners.addListener(port.onMessage, this._onMessage.bind(this)); this._eventListeners.addListener(port.onDisconnect, this._onDisconnect.bind(this)); this._port = port; @@ -228,7 +228,7 @@ export class Mecab { const {version} = await this._invoke('get_version', {}); this._remoteVersion = version; if (version !== this._version) { - throw new Error(`Unsupported MeCab native messenger version ${version}. Yomichan supports version ${this._version}.`); + throw new Error(`Unsupported MeCab native messenger version ${version}. Yomitan supports version ${this._version}.`); } } catch (e) { if (this._port === port) { diff --git a/ext/js/data/anki-note-builder.js b/ext/js/data/anki-note-builder.js index 7fbbf03c..398036c0 100644 --- a/ext/js/data/anki-note-builder.js +++ b/ext/js/data/anki-note-builder.js @@ -18,7 +18,7 @@ import {deferPromise, deserializeError} from '../core.js'; import {TemplateRendererProxy} from '../templates/template-renderer-proxy.js'; -import {yomichan} from '../yomichan.js'; +import {yomitan} from '../yomitan.js'; import {AnkiUtil} from './anki-util.js'; export class AnkiNoteBuilder { @@ -345,7 +345,7 @@ export class AnkiNoteBuilder { // Inject media const selectionText = injectSelectionText ? this._getSelectionText() : null; - const injectedMedia = await yomichan.api.injectAnkiNoteMedia( + const injectedMedia = await yomitan.api.injectAnkiNoteMedia( timestamp, dictionaryEntryDetails, audioDetails, @@ -386,7 +386,7 @@ export class AnkiNoteBuilder { async _getTextFurigana(entries, optionsContext, scanLength) { const results = []; for (const {text, readingMode} of entries) { - const parseResults = await yomichan.api.parseText(text, optionsContext, scanLength, true, false); + const parseResults = await yomitan.api.parseText(text, optionsContext, scanLength, true, false); let data = null; for (const {source, content} of parseResults) { if (source !== 'scanning-parser') { continue; } diff --git a/ext/js/data/options-util.js b/ext/js/data/options-util.js index 42e31b5f..3858cb55 100644 --- a/ext/js/data/options-util.js +++ b/ext/js/data/options-util.js @@ -330,7 +330,7 @@ export class OptionsUtil { anki: { enable: false, server: 'http://127.0.0.1:8765', - tags: ['yomichan'], + tags: ['yomitan'], sentenceExt: 200, screenshot: {format: 'png', quality: 92}, terms: {deck: '', model: '', fields: {}}, diff --git a/ext/js/display/display-anki.js b/ext/js/display/display-anki.js index a25008a2..2f94e414 100644 --- a/ext/js/display/display-anki.js +++ b/ext/js/display/display-anki.js @@ -20,7 +20,7 @@ import {EventListenerCollection, deferPromise, isObject} from '../core.js'; import {AnkiNoteBuilder} from '../data/anki-note-builder.js'; import {AnkiUtil} from '../data/anki-util.js'; import {PopupMenu} from '../dom/popup-menu.js'; -import {yomichan} from '../yomichan.js'; +import {yomitan} from '../yomitan.js'; export class DisplayAnki { constructor(display, displayAudio, japaneseUtil) { @@ -377,7 +377,7 @@ export class DisplayAnki { let noteId = null; let addNoteOkay = false; try { - noteId = await yomichan.api.addAnkiNote(note); + noteId = await yomitan.api.addAnkiNote(note); addNoteOkay = true; } catch (e) { allErrors.length = 0; @@ -390,7 +390,7 @@ export class DisplayAnki { } else { if (this._suspendNewCards) { try { - await yomichan.api.suspendAnkiCardsForNote(noteId); + await yomitan.api.suspendAnkiCardsForNote(noteId); } catch (e) { allErrors.push(e); } @@ -475,7 +475,7 @@ export class DisplayAnki { templates = this._ankiFieldTemplatesDefault; if (typeof templates === 'string') { return templates; } - templates = await yomichan.api.getDefaultAnkiFieldTemplates(); + templates = await yomitan.api.getDefaultAnkiFieldTemplates(); this._ankiFieldTemplatesDefault = templates; return templates; } @@ -505,12 +505,12 @@ export class DisplayAnki { let ankiError = null; try { if (forceCanAddValue !== null) { - if (!await yomichan.api.isAnkiConnected()) { + if (!await yomitan.api.isAnkiConnected()) { throw new Error('Anki not connected'); } infos = this._getAnkiNoteInfoForceValue(notes, forceCanAddValue); } else { - infos = await yomichan.api.getAnkiNoteInfo(notes, fetchAdditionalInfo); + infos = await yomitan.api.getAnkiNoteInfo(notes, fetchAdditionalInfo); } } catch (e) { infos = this._getAnkiNoteInfoForceValue(notes, false); @@ -663,7 +663,7 @@ export class DisplayAnki { const noteIds = this._getNodeNoteIds(node); if (noteIds.length === 0) { return; } try { - await yomichan.api.noteView(noteIds[0], this._noteGuiMode, false); + await yomitan.api.noteView(noteIds[0], this._noteGuiMode, false); } catch (e) { const displayErrors = ( e.message === 'Mode not supported' ? diff --git a/ext/js/display/display-audio.js b/ext/js/display/display-audio.js index b829dd1a..faed88bc 100644 --- a/ext/js/display/display-audio.js +++ b/ext/js/display/display-audio.js @@ -19,7 +19,7 @@ import {EventListenerCollection} from '../core.js'; import {PopupMenu} from '../dom/popup-menu.js'; import {AudioSystem} from '../media/audio-system.js'; -import {yomichan} from '../yomichan.js'; +import {yomitan} from '../yomitan.js'; export class DisplayAudio { constructor(display) { @@ -531,7 +531,7 @@ export class DisplayAudio { async _getTermAudioInfoList(source, term, reading) { const sourceData = this._getSourceData(source); - const infoList = await yomichan.api.getTermAudioInfoList(sourceData, term, reading); + const infoList = await yomitan.api.getTermAudioInfoList(sourceData, term, reading); return infoList.map((info) => ({info, audioPromise: null, audioResolved: false, audio: null})); } diff --git a/ext/js/display/display-content-manager.js b/ext/js/display/display-content-manager.js index 6cba1783..fb2e7db5 100644 --- a/ext/js/display/display-content-manager.js +++ b/ext/js/display/display-content-manager.js @@ -18,7 +18,7 @@ import {EventListenerCollection} from '../core.js'; import {ArrayBufferUtil} from '../data/sandbox/array-buffer-util.js'; -import {yomichan} from '../yomichan.js'; +import {yomitan} from '../yomitan.js'; /** * A callback used when a media file has been loaded. @@ -138,7 +138,7 @@ export class DisplayContentManager { async _getMediaData(path, dictionary, cachedData) { const token = this._token; - const data = (await yomichan.api.getMedia([{path, dictionary}]))[0]; + const data = (await yomitan.api.getMedia([{path, dictionary}]))[0]; if (token === this._token && data !== null) { const buffer = ArrayBufferUtil.base64ToArrayBuffer(data.content); const blob = new Blob([buffer], {type: data.mediaType}); diff --git a/ext/js/display/display-generator.js b/ext/js/display/display-generator.js index 25df9745..e8a2104f 100644 --- a/ext/js/display/display-generator.js +++ b/ext/js/display/display-generator.js @@ -19,7 +19,7 @@ import {isObject} from '../core.js'; import {HtmlTemplateCollection} from '../dom/html-template-collection.js'; import {DictionaryDataUtil} from '../language/sandbox/dictionary-data-util.js'; -import {yomichan} from '../yomichan.js'; +import {yomitan} from '../yomitan.js'; import {PronunciationGenerator} from './sandbox/pronunciation-generator.js'; import {StructuredContentGenerator} from './sandbox/structured-content-generator.js'; @@ -34,7 +34,7 @@ export class DisplayGenerator { } async prepare() { - const html = await yomichan.api.getDisplayTemplatesHtml(); + const html = await yomitan.api.getDisplayTemplatesHtml(); this._templates = new HtmlTemplateCollection(html); this.updateHotkeys(); } diff --git a/ext/js/display/display-profile-selection.js b/ext/js/display/display-profile-selection.js index c0b642e8..d8b7185c 100644 --- a/ext/js/display/display-profile-selection.js +++ b/ext/js/display/display-profile-selection.js @@ -18,7 +18,7 @@ import {EventListenerCollection, generateId} from '../core.js'; import {PanelElement} from '../dom/panel-element.js'; -import {yomichan} from '../yomichan.js'; +import {yomitan} from '../yomitan.js'; export class DisplayProfileSelection { constructor(display) { @@ -35,7 +35,7 @@ export class DisplayProfileSelection { } async prepare() { - yomichan.on('optionsUpdated', this._onOptionsUpdated.bind(this)); + yomitan.on('optionsUpdated', this._onOptionsUpdated.bind(this)); this._profileButton.addEventListener('click', this._onProfileButtonClick.bind(this), false); this._profileListNeedsUpdate = true; } @@ -67,7 +67,7 @@ export class DisplayProfileSelection { async _updateProfileList() { this._profileListNeedsUpdate = false; - const options = await yomichan.api.optionsGetFull(); + const options = await yomitan.api.optionsGetFull(); this._eventListeners.removeAllEventListeners(); const displayGenerator = this._display.displayGenerator; @@ -95,7 +95,7 @@ export class DisplayProfileSelection { } async _setProfileCurrent(index) { - await yomichan.api.modifySettings([{ + await yomitan.api.modifySettings([{ action: 'set', path: 'profileCurrent', value: index, diff --git a/ext/js/display/display.js b/ext/js/display/display.js index b86b877d..038a76bb 100644 --- a/ext/js/display/display.js +++ b/ext/js/display/display.js @@ -26,7 +26,7 @@ import {ScrollElement} from '../dom/scroll-element.js'; import {HotkeyHelpController} from '../input/hotkey-help-controller.js'; import {TextScanner} from '../language/text-scanner.js'; import {dynamicLoader} from '../script/dynamic-loader.js'; -import {yomichan} from '../yomichan.js'; +import {yomitan} from '../yomitan.js'; import {DisplayContentManager} from './display-content-manager.js'; import {DisplayGenerator} from './display-generator.js'; import {DisplayHistory} from './display-history.js'; @@ -260,7 +260,7 @@ export class Display extends EventDispatcher { // State setup const {documentElement} = document; - const {browser} = await yomichan.api.getEnvironmentInfo(); + const {browser} = await yomitan.api.getEnvironmentInfo(); this._browser = browser; if (documentElement !== null) { @@ -278,8 +278,8 @@ export class Display extends EventDispatcher { this._history.on('stateChanged', this._onStateChanged.bind(this)); this._queryParser.on('searched', this._onQueryParserSearch.bind(this)); this._progressIndicatorVisible.on('change', this._onProgressIndicatorVisibleChanged.bind(this)); - yomichan.on('extensionUnloaded', this._onExtensionUnloaded.bind(this)); - yomichan.crossFrame.registerHandlers([ + yomitan.on('extensionUnloaded', this._onExtensionUnloaded.bind(this)); + yomitan.crossFrame.registerHandlers([ ['popupMessage', {async: 'dynamic', handler: this._onDirectMessage.bind(this)}] ]); window.addEventListener('message', this._onWindowMessage.bind(this), false); @@ -326,7 +326,7 @@ export class Display extends EventDispatcher { } onError(error) { - if (yomichan.isExtensionUnloaded) { return; } + if (yomitan.isExtensionUnloaded) { return; } log.error(error); } @@ -344,7 +344,7 @@ export class Display extends EventDispatcher { } async updateOptions() { - const options = await yomichan.api.optionsGet(this.getOptionsContext()); + const options = await yomitan.api.optionsGet(this.getOptionsContext()); const {scanning: scanningOptions, sentenceParsing: sentenceParsingOptions} = options; this._options = options; @@ -494,14 +494,14 @@ export class Display extends EventDispatcher { if (this._contentOriginTabId === this._tabId && this._contentOriginFrameId === this._frameId) { throw new Error('Content origin is same page'); } - return await yomichan.crossFrame.invokeTab(this._contentOriginTabId, this._contentOriginFrameId, action, params); + return await yomitan.crossFrame.invokeTab(this._contentOriginTabId, this._contentOriginFrameId, action, params); } async invokeParentFrame(action, params={}) { if (this._parentFrameId === null || this._parentFrameId === this._frameId) { throw new Error('Invalid parent frame'); } - return await yomichan.crossFrame.invoke(this._parentFrameId, action, params); + return await yomitan.crossFrame.invoke(this._parentFrameId, action, params); } getElementDictionaryEntryIndex(element) { @@ -586,8 +586,8 @@ export class Display extends EventDispatcher { } _onMessageExtensionUnloaded() { - if (yomichan.isExtensionUnloaded) { return; } - yomichan.triggerExtensionUnloaded(); + if (yomitan.isExtensionUnloaded) { return; } + yomitan.triggerExtensionUnloaded(); } // Private @@ -736,7 +736,7 @@ export class Display extends EventDispatcher { if (typeof documentTitle !== 'string') { documentTitle = document.title; } const optionsContext = this.getOptionsContext(); const query = e.currentTarget.textContent; - const dictionaryEntries = await yomichan.api.kanjiFind(query, optionsContext); + const dictionaryEntries = await yomitan.api.kanjiFind(query, optionsContext); const details = { focus: false, historyMode: 'new', @@ -914,7 +914,7 @@ export class Display extends EventDispatcher { async _findDictionaryEntries(isKanji, source, wildcardsEnabled, optionsContext) { if (isKanji) { - const dictionaryEntries = await yomichan.api.kanjiFind(source, optionsContext); + const dictionaryEntries = await yomitan.api.kanjiFind(source, optionsContext); return dictionaryEntries; } else { const findDetails = {}; @@ -932,7 +932,7 @@ export class Display extends EventDispatcher { } } - const {dictionaryEntries} = await yomichan.api.termsFind(source, findDetails, optionsContext); + const {dictionaryEntries} = await yomitan.api.termsFind(source, findDetails, optionsContext); return dictionaryEntries; } } @@ -1334,7 +1334,7 @@ export class Display extends EventDispatcher { } _closePopups() { - yomichan.trigger('closePopups'); + yomitan.trigger('closePopups'); } async _setOptionsContextIfDifferent(optionsContext) { @@ -1549,7 +1549,7 @@ export class Display extends EventDispatcher { } _onContentTextScannerSearched({type, dictionaryEntries, sentence, textSource, optionsContext, error}) { - if (error !== null && !yomichan.isExtensionUnloaded) { + if (error !== null && !yomitan.isExtensionUnloaded) { log.error(error); } diff --git a/ext/js/display/option-toggle-hotkey-handler.js b/ext/js/display/option-toggle-hotkey-handler.js index 360b0894..1f8de939 100644 --- a/ext/js/display/option-toggle-hotkey-handler.js +++ b/ext/js/display/option-toggle-hotkey-handler.js @@ -17,7 +17,7 @@ */ import {deserializeError} from '../core.js'; -import {yomichan} from '../yomichan.js'; +import {yomitan} from '../yomitan.js'; export class OptionToggleHotkeyHandler { constructor(display) { @@ -52,7 +52,7 @@ export class OptionToggleHotkeyHandler { try { const optionsContext = this._display.getOptionsContext(); - const result = (await yomichan.api.getSettings([{ + const result = (await yomitan.api.getSettings([{ scope: 'profile', path, optionsContext @@ -69,7 +69,7 @@ export class OptionToggleHotkeyHandler { value = !value; - const result2 = (await yomichan.api.modifySettings([{ + const result2 = (await yomitan.api.modifySettings([{ scope: 'profile', action: 'set', path, diff --git a/ext/js/display/popup-main.js b/ext/js/display/popup-main.js index b82458fa..6b07b63f 100644 --- a/ext/js/display/popup-main.js +++ b/ext/js/display/popup-main.js @@ -20,7 +20,7 @@ import {log} from '../core.js'; import {DocumentFocusController} from '../dom/document-focus-controller.js'; import {HotkeyHandler} from '../input/hotkey-handler.js'; import {JapaneseUtil} from '../language/sandbox/japanese-util.js'; -import {yomichan} from '../yomichan.js'; +import {yomitan} from '../yomitan.js'; import {DisplayAnki} from './display-anki.js'; import {DisplayAudio} from './display-audio.js'; import {DisplayProfileSelection} from './display-profile-selection.js'; @@ -32,9 +32,9 @@ import {Display} from './display.js'; const documentFocusController = new DocumentFocusController(); documentFocusController.prepare(); - await yomichan.prepare(); + await yomitan.prepare(); - const {tabId, frameId} = await yomichan.api.frameInformationGet(); + const {tabId, frameId} = await yomitan.api.frameInformationGet(); const japaneseUtil = new JapaneseUtil(null); @@ -60,7 +60,7 @@ import {Display} from './display.js'; document.documentElement.dataset.loaded = 'true'; - yomichan.ready(); + yomitan.ready(); } catch (e) { log.error(e); } diff --git a/ext/js/display/query-parser.js b/ext/js/display/query-parser.js index 6eee55b2..85ec3031 100644 --- a/ext/js/display/query-parser.js +++ b/ext/js/display/query-parser.js @@ -18,7 +18,7 @@ import {EventDispatcher, log} from '../core.js'; import {TextScanner} from '../language/text-scanner.js'; -import {yomichan} from '../yomichan.js'; +import {yomitan} from '../yomitan.js'; export class QueryParser extends EventDispatcher { constructor({getSearchContext, japaneseUtil}) { @@ -93,7 +93,7 @@ export class QueryParser extends EventDispatcher { const token = {}; this._setTextToken = token; - this._parseResults = await yomichan.api.parseText(text, this._getOptionsContext(), this._scanLength, this._useInternalParser, this._useMecabParser); + this._parseResults = await yomitan.api.parseText(text, this._getOptionsContext(), this._scanLength, this._useInternalParser, this._useMecabParser); if (this._setTextToken !== token) { return; } this._refreshSelectedParser(); @@ -139,7 +139,7 @@ export class QueryParser extends EventDispatcher { _setSelectedParser(value) { const optionsContext = this._getOptionsContext(); - yomichan.api.modifySettings([{ + yomitan.api.modifySettings([{ action: 'set', path: 'parsing.selectedParser', value, diff --git a/ext/js/display/search-display-controller.js b/ext/js/display/search-display-controller.js index 9e190c85..e31bd239 100644 --- a/ext/js/display/search-display-controller.js +++ b/ext/js/display/search-display-controller.js @@ -19,7 +19,7 @@ import * as wanakana from '../../lib/wanakana.js'; import {ClipboardMonitor} from '../comm/clipboard-monitor.js'; import {EventListenerCollection, invokeMessageHandler} from '../core.js'; -import {yomichan} from '../yomichan.js'; +import {yomitan} from '../yomitan.js'; export class SearchDisplayController { constructor(tabId, frameId, display, displayAudio, japaneseUtil, searchPersistentStateController) { @@ -44,7 +44,7 @@ export class SearchDisplayController { this._clipboardMonitor = new ClipboardMonitor({ japaneseUtil, clipboardReader: { - getText: yomichan.api.clipboardGet.bind(yomichan.api) + getText: yomitan.api.clipboardGet.bind(yomitan.api) } }); this._messageHandlers = new Map(); @@ -56,7 +56,7 @@ export class SearchDisplayController { this._searchPersistentStateController.on('modeChange', this._onModeChange.bind(this)); chrome.runtime.onMessage.addListener(this._onMessage.bind(this)); - yomichan.on('optionsUpdated', this._onOptionsUpdated.bind(this)); + yomitan.on('optionsUpdated', this._onOptionsUpdated.bind(this)); this._display.on('optionsUpdated', this._onDisplayOptionsUpdated.bind(this)); this._display.on('contentUpdateStart', this._onContentUpdateStart.bind(this)); @@ -225,7 +225,7 @@ export class SearchDisplayController { _onWanakanaEnableChange(e) { const value = e.target.checked; this._setWanakanaEnabled(value); - yomichan.api.modifySettings([{ + yomitan.api.modifySettings([{ action: 'set', path: 'general.enableWanakana', value, @@ -335,7 +335,7 @@ export class SearchDisplayController { if (!modify) { return; } - await yomichan.api.modifySettings([{ + await yomitan.api.modifySettings([{ action: 'set', path: 'clipboard.enableSearchPageMonitor', value, diff --git a/ext/js/display/search-main.js b/ext/js/display/search-main.js index 67552229..5eee08d1 100644 --- a/ext/js/display/search-main.js +++ b/ext/js/display/search-main.js @@ -21,7 +21,7 @@ import {log} from '../core.js'; import {DocumentFocusController} from '../dom/document-focus-controller.js'; import {HotkeyHandler} from '../input/hotkey-handler.js'; import {JapaneseUtil} from '../language/sandbox/japanese-util.js'; -import {yomichan} from '../yomichan.js'; +import {yomitan} from '../yomitan.js'; import {DisplayAnki} from './display-anki.js'; import {DisplayAudio} from './display-audio.js'; import {Display} from './display.js'; @@ -40,9 +40,9 @@ import {SearchPersistentStateController} from './search-persistent-state-control const searchActionPopupController = new SearchActionPopupController(searchPersistentStateController); searchActionPopupController.prepare(); - await yomichan.prepare(); + await yomitan.prepare(); - const {tabId, frameId} = await yomichan.api.frameInformationGet(); + const {tabId, frameId} = await yomitan.api.frameInformationGet(); const japaneseUtil = new JapaneseUtil(wanakana); @@ -65,7 +65,7 @@ import {SearchPersistentStateController} from './search-persistent-state-control document.documentElement.dataset.loaded = 'true'; - yomichan.ready(); + yomitan.ready(); } catch (e) { log.error(e); } diff --git a/ext/js/input/hotkey-handler.js b/ext/js/input/hotkey-handler.js index f05351bb..2fd35a5c 100644 --- a/ext/js/input/hotkey-handler.js +++ b/ext/js/input/hotkey-handler.js @@ -18,7 +18,7 @@ import {EventDispatcher, EventListenerCollection} from '../core.js'; import {DocumentUtil} from '../dom/document-util.js'; -import {yomichan} from '../yomichan.js'; +import {yomitan} from '../yomitan.js'; /** * Class which handles hotkey events and actions. @@ -53,7 +53,7 @@ export class HotkeyHandler extends EventDispatcher { prepare() { this._isPrepared = true; this._updateEventHandlers(); - yomichan.crossFrame.registerHandlers([ + yomitan.crossFrame.registerHandlers([ ['HotkeyHandler.forwardHotkey', {async: false, handler: this._onMessageForwardHotkey.bind(this)}] ]); } diff --git a/ext/js/input/hotkey-help-controller.js b/ext/js/input/hotkey-help-controller.js index 67df9f84..51ec8fac 100644 --- a/ext/js/input/hotkey-help-controller.js +++ b/ext/js/input/hotkey-help-controller.js @@ -17,7 +17,7 @@ */ import {isObject} from '../core.js'; -import {yomichan} from '../yomichan.js'; +import {yomitan} from '../yomitan.js'; import {HotkeyUtil} from './hotkey-util.js'; export class HotkeyHelpController { @@ -29,7 +29,7 @@ export class HotkeyHelpController { } async prepare() { - const {platform: {os}} = await yomichan.api.getEnvironmentInfo(); + const {platform: {os}} = await yomitan.api.getEnvironmentInfo(); this._hotkeyUtil.os = os; await this._setupGlobalCommands(this._globalActionHotkeys); } diff --git a/ext/js/language/text-scanner.js b/ext/js/language/text-scanner.js index bd5b0fbe..ac7ef3d9 100644 --- a/ext/js/language/text-scanner.js +++ b/ext/js/language/text-scanner.js @@ -18,7 +18,7 @@ import {EventDispatcher, EventListenerCollection, clone, isObject, log, promiseTimeout} from '../core.js'; import {DocumentUtil} from '../dom/document-util.js'; -import {yomichan} from '../yomichan.js'; +import {yomitan} from '../yomitan.js'; export class TextScanner extends EventDispatcher { constructor({ @@ -89,7 +89,7 @@ export class TextScanner extends EventDispatcher { this._canClearSelection = true; this._textSelectionTimer = null; - this._yomichanIsChangingTextSelectionNow = false; + this._yomitanIsChangingTextSelectionNow = false; this._userHasNotSelectedAnythingManually = true; } @@ -270,13 +270,13 @@ export class TextScanner extends EventDispatcher { setCurrentTextSource(textSource) { this._textSourceCurrent = textSource; if (this._selectText && this._userHasNotSelectedAnythingManually) { - this._yomichanIsChangingTextSelectionNow = true; + this._yomitanIsChangingTextSelectionNow = true; this._textSourceCurrent.select(); if (this._textSelectionTimer !== null) { clearTimeout(this._textSelectionTimer); } // This timeout uses a 50ms delay to ensure that the selectionchange event has time to occur. // If the delay is 0ms, the timeout will sometimes complete before the event. this._textSelectionTimer = setTimeout(() => { - this._yomichanIsChangingTextSelectionNow = false; + this._yomitanIsChangingTextSelectionNow = false; this._textSelectionTimer = null; }, 50); this._textSourceCurrentSelected = true; @@ -390,7 +390,7 @@ export class TextScanner extends EventDispatcher { } _onSelectionChangeCheckUserSelection() { - if (this._yomichanIsChangingTextSelectionNow) { return; } + if (this._yomitanIsChangingTextSelectionNow) { return; } this._userHasNotSelectedAnythingManually = window.getSelection().isCollapsed; } @@ -881,7 +881,7 @@ export class TextScanner extends EventDispatcher { const details = {}; if (this._matchTypePrefix) { details.matchType = 'prefix'; } - const {dictionaryEntries, originalTextLength} = await yomichan.api.termsFind(searchText, details, optionsContext); + const {dictionaryEntries, originalTextLength} = await yomitan.api.termsFind(searchText, details, optionsContext); if (dictionaryEntries.length === 0) { return null; } textSource.setEndOffset(originalTextLength, false, layoutAwareScan); @@ -908,7 +908,7 @@ export class TextScanner extends EventDispatcher { const searchText = this.getTextSourceContent(textSource, 1, layoutAwareScan); if (searchText.length === 0) { return null; } - const dictionaryEntries = await yomichan.api.kanjiFind(searchText, optionsContext); + const dictionaryEntries = await yomitan.api.kanjiFind(searchText, optionsContext); if (dictionaryEntries.length === 0) { return null; } textSource.setEndOffset(1, false, layoutAwareScan); @@ -1145,7 +1145,7 @@ export class TextScanner extends EventDispatcher { async _hasJapanese(text) { try { - return await yomichan.api.textHasJapaneseCharacters(text); + return await yomitan.api.textHasJapaneseCharacters(text); } catch (e) { return false; } diff --git a/ext/js/pages/action-popup-main.js b/ext/js/pages/action-popup-main.js index 163c226a..32bfcb7f 100644 --- a/ext/js/pages/action-popup-main.js +++ b/ext/js/pages/action-popup-main.js @@ -18,7 +18,7 @@ import {PermissionsUtil} from '../data/permissions-util.js'; import {HotkeyHelpController} from '../input/hotkey-help-controller.js'; -import {yomichan} from '../yomichan.js'; +import {yomitan} from '../yomitan.js'; export class DisplayController { constructor() { @@ -34,7 +34,7 @@ export class DisplayController { this._setupButtonEvents('.action-open-search', 'openSearchPage', chrome.runtime.getURL('/search.html'), this._onSearchClick.bind(this)); this._setupButtonEvents('.action-open-info', 'openInfoPage', chrome.runtime.getURL('/info.html')); - const optionsFull = await yomichan.api.optionsGetFull(); + const optionsFull = await yomitan.api.optionsGetFull(); this._optionsFull = optionsFull; this._setupHotkeys(); @@ -84,12 +84,12 @@ export class DisplayController { const result = customHandler(e); if (typeof result !== 'undefined') { return; } } - yomichan.api.commandExec(command, {mode: e.ctrlKey ? 'newTab' : 'existingOrNewTab'}); + yomitan.api.commandExec(command, {mode: e.ctrlKey ? 'newTab' : 'existingOrNewTab'}); e.preventDefault(); }, false); node.addEventListener('auxclick', (e) => { if (e.button !== 1) { return; } - yomichan.api.commandExec(command, {mode: 'newTab'}); + yomitan.api.commandExec(command, {mode: 'newTab'}); e.preventDefault(); }, false); } @@ -144,7 +144,7 @@ export class DisplayController { _setupOptions({options}) { const extensionEnabled = options.general.enable; - const onToggleChanged = () => yomichan.api.commandExec('toggleTextScanning'); + const onToggleChanged = () => yomitan.api.commandExec('toggleTextScanning'); for (const toggle of document.querySelectorAll('#enable-search,#enable-search2')) { toggle.checked = extensionEnabled; toggle.addEventListener('change', onToggleChanged, false); @@ -192,7 +192,7 @@ export class DisplayController { } async _setPrimaryProfileIndex(value) { - return await yomichan.api.modifySettings( + return await yomitan.api.modifySettings( [{ action: 'set', path: 'profileCurrent', @@ -204,7 +204,7 @@ export class DisplayController { async _updateDictionariesEnabledWarnings(options) { const noDictionariesEnabledWarnings = document.querySelectorAll('.no-dictionaries-enabled-warning'); - const dictionaries = await yomichan.api.getDictionaryInfo(); + const dictionaries = await yomitan.api.getDictionaryInfo(); const enabledDictionaries = new Set(); for (const {name, enabled} of options.dictionaries) { @@ -237,18 +237,18 @@ export class DisplayController { } async _isSafari() { - const {browser} = await yomichan.api.getEnvironmentInfo(); + const {browser} = await yomitan.api.getEnvironmentInfo(); return browser === 'safari'; } } (async () => { - await yomichan.prepare(); + await yomitan.prepare(); - yomichan.api.logIndicatorClear(); + yomitan.api.logIndicatorClear(); const displayController = new DisplayController(); displayController.prepare(); - yomichan.ready(); + yomitan.ready(); })(); diff --git a/ext/js/pages/info-main.js b/ext/js/pages/info-main.js index 58366d4c..7c6bc993 100644 --- a/ext/js/pages/info-main.js +++ b/ext/js/pages/info-main.js @@ -18,7 +18,7 @@ import {log, promiseTimeout} from '../core.js'; import {DocumentFocusController} from '../dom/document-focus-controller.js'; -import {yomichan} from '../yomichan.js'; +import {yomitan} from '../yomitan.js'; import {BackupController} from './settings/backup-controller.js'; import {SettingsController} from './settings/settings-controller.js'; @@ -54,11 +54,11 @@ function getOperatingSystemDisplayName(os) { const manifest = chrome.runtime.getManifest(); const language = chrome.i18n.getUILanguage(); - await yomichan.prepare(); + await yomitan.prepare(); const {userAgent} = navigator; const {name, version} = manifest; - const {browser, platform: {os}} = await yomichan.api.getEnvironmentInfo(); + const {browser, platform: {os}} = await yomitan.api.getEnvironmentInfo(); const thisVersionLink = document.querySelector('#release-notes-this-version-link'); thisVersionLink.href = thisVersionLink.dataset.hrefFormat.replace(/\{version\}/g, version); @@ -72,7 +72,7 @@ function getOperatingSystemDisplayName(os) { (async () => { let ankiConnectVersion = null; try { - ankiConnectVersion = await yomichan.api.getAnkiConnectVersion(); + ankiConnectVersion = await yomitan.api.getAnkiConnectVersion(); } catch (e) { // NOP } @@ -85,7 +85,7 @@ function getOperatingSystemDisplayName(os) { (async () => { let dictionaryInfos; try { - dictionaryInfos = await yomichan.api.getDictionaryInfo(); + dictionaryInfos = await yomitan.api.getDictionaryInfo(); } catch (e) { return; } diff --git a/ext/js/pages/permissions-main.js b/ext/js/pages/permissions-main.js index b242ff63..ff614880 100644 --- a/ext/js/pages/permissions-main.js +++ b/ext/js/pages/permissions-main.js @@ -18,7 +18,7 @@ import {log, promiseTimeout} from '../core.js'; import {DocumentFocusController} from '../dom/document-focus-controller.js'; -import {yomichan} from '../yomichan.js'; +import {yomitan} from '../yomitan.js'; import {ExtensionContentController} from './common/extension-content-controller.js'; import {ModalController} from './settings/modal-controller.js'; import {PermissionsOriginController} from './settings/permissions-origin-controller.js'; @@ -29,7 +29,7 @@ import {SettingsDisplayController} from './settings/settings-display-controller. async function setupEnvironmentInfo() { const {manifest_version: manifestVersion} = chrome.runtime.getManifest(); - const {browser, platform} = await yomichan.api.getEnvironmentInfo(); + const {browser, platform} = await yomitan.api.getEnvironmentInfo(); document.documentElement.dataset.browser = browser; document.documentElement.dataset.os = platform.os; document.documentElement.dataset.manifestVersion = `${manifestVersion}`; @@ -73,7 +73,7 @@ function setupPermissionsToggles() { setupPermissionsToggles(); - await yomichan.prepare(); + await yomitan.prepare(); setupEnvironmentInfo(); diff --git a/ext/js/pages/settings/anki-controller.js b/ext/js/pages/settings/anki-controller.js index 0ad047aa..8164b8f6 100644 --- a/ext/js/pages/settings/anki-controller.js +++ b/ext/js/pages/settings/anki-controller.js @@ -21,7 +21,7 @@ import {EventListenerCollection, log} from '../../core.js'; import {AnkiUtil} from '../../data/anki-util.js'; import {SelectorObserver} from '../../dom/selector-observer.js'; import {ObjectPropertyAccessor} from '../../general/object-property-accessor.js'; -import {yomichan} from '../../yomichan.js'; +import {yomitan} from '../../yomitan.js'; export class AnkiController { constructor(settingsController) { @@ -394,7 +394,7 @@ export class AnkiController { let noteId = null; for (const query of queries) { - const notes = await yomichan.api.findAnkiNotes(query); + const notes = await yomitan.api.findAnkiNotes(query); if (notes.length > 0) { noteId = notes[0]; break; @@ -405,7 +405,7 @@ export class AnkiController { throw new Error('Could not find a note to test with'); } - await yomichan.api.noteView(noteId, mode, false); + await yomitan.api.noteView(noteId, mode, false); } _setAnkiNoteViewerStatus(visible, error) { diff --git a/ext/js/pages/settings/anki-templates-controller.js b/ext/js/pages/settings/anki-templates-controller.js index 83b1b0bb..ac8a0205 100644 --- a/ext/js/pages/settings/anki-templates-controller.js +++ b/ext/js/pages/settings/anki-templates-controller.js @@ -19,7 +19,7 @@ import {isObject} from '../../core.js'; import {AnkiNoteBuilder} from '../../data/anki-note-builder.js'; import {JapaneseUtil} from '../../language/sandbox/japanese-util.js'; -import {yomichan} from '../../yomichan.js'; +import {yomitan} from '../../yomitan.js'; export class AnkiTemplatesController { constructor(settingsController, modalController, ankiController) { @@ -38,7 +38,7 @@ export class AnkiTemplatesController { } async prepare() { - this._defaultFieldTemplates = await yomichan.api.getDefaultAnkiFieldTemplates(); + this._defaultFieldTemplates = await yomitan.api.getDefaultAnkiFieldTemplates(); this._fieldTemplatesTextarea = document.querySelector('#anki-card-templates-textarea'); this._compileResultInfo = document.querySelector('#anki-card-templates-compile-result'); @@ -136,7 +136,7 @@ export class AnkiTemplatesController { async _getDictionaryEntry(text, optionsContext) { if (this._cachedDictionaryEntryText !== text) { - const {dictionaryEntries} = await yomichan.api.termsFind(text, {}, optionsContext); + const {dictionaryEntries} = await yomitan.api.termsFind(text, {}, optionsContext); if (dictionaryEntries.length === 0) { return null; } this._cachedDictionaryEntryValue = dictionaryEntries[0]; diff --git a/ext/js/pages/settings/backup-controller.js b/ext/js/pages/settings/backup-controller.js index e429f9c7..c41d4315 100644 --- a/ext/js/pages/settings/backup-controller.js +++ b/ext/js/pages/settings/backup-controller.js @@ -17,11 +17,11 @@ */ import * as Dexie from '../../../lib/dexie.js'; -import {isObject, log} from '../../core.js'; -import {OptionsUtil} from '../../data/options-util.js'; -import {ArrayBufferUtil} from '../../data/sandbox/array-buffer-util.js'; -import {yomichan} from '../../yomichan.js'; -import {DictionaryController} from './dictionary-controller.js'; +import { isObject, log } from '../../core.js'; +import { OptionsUtil } from '../../data/options-util.js'; +import { ArrayBufferUtil } from '../../data/sandbox/array-buffer-util.js'; +import { yomitan } from '../../yomitan.js'; +import { DictionaryController } from './dictionary-controller.js'; export class BackupController { constructor(settingsController, modalController) { @@ -95,8 +95,8 @@ export class BackupController { async _getSettingsExportData(date) { const optionsFull = await this._settingsController.getOptionsFull(); - const environment = await yomichan.api.getEnvironmentInfo(); - const fieldTemplatesDefault = await yomichan.api.getDefaultAnkiFieldTemplates(); + const environment = await yomitan.api.getEnvironmentInfo(); + const fieldTemplatesDefault = await yomitan.api.getDefaultAnkiFieldTemplates(); const permissions = await this._settingsController.permissionsUtil.getAllPermissions(); // Format options @@ -503,10 +503,10 @@ export class BackupController { } async _importDatabase(databaseName, file) { - await yomichan.api.purgeDatabase(); + await yomitan.api.purgeDatabase(); await Dexie.import(file, {progressCallback: this._databaseImportProgressCallback}); - yomichan.api.triggerDatabaseUpdated('dictionary', 'import'); - yomichan.trigger('storageChanged'); + yomitan.api.triggerDatabaseUpdated('dictionary', 'import'); + yomitan.trigger('storageChanged'); } _onSettingsImportDatabaseClick() { diff --git a/ext/js/pages/settings/collapsible-dictionary-controller.js b/ext/js/pages/settings/collapsible-dictionary-controller.js index 37d5e6c9..c8ce5e4f 100644 --- a/ext/js/pages/settings/collapsible-dictionary-controller.js +++ b/ext/js/pages/settings/collapsible-dictionary-controller.js @@ -17,7 +17,7 @@ */ import {EventListenerCollection} from '../../core.js'; -import {yomichan} from '../../yomichan.js'; +import {yomitan} from '../../yomitan.js'; export class CollapsibleDictionaryController { constructor(settingsController) { @@ -35,7 +35,7 @@ export class CollapsibleDictionaryController { await this._onDatabaseUpdated(); - yomichan.on('databaseUpdated', this._onDatabaseUpdated.bind(this)); + yomitan.on('databaseUpdated', this._onDatabaseUpdated.bind(this)); this._settingsController.on('optionsChanged', this._onOptionsChanged.bind(this)); this._settingsController.on('dictionarySettingsReordered', this._onDictionarySettingsReordered.bind(this)); } diff --git a/ext/js/pages/settings/dictionary-controller.js b/ext/js/pages/settings/dictionary-controller.js index 05f4f396..155ce55e 100644 --- a/ext/js/pages/settings/dictionary-controller.js +++ b/ext/js/pages/settings/dictionary-controller.js @@ -18,7 +18,7 @@ import {EventListenerCollection, log} from '../../core.js'; import {DictionaryWorker} from '../../language/dictionary-worker.js'; -import {yomichan} from '../../yomichan.js'; +import {yomitan} from '../../yomitan.js'; class DictionaryEntry { constructor(dictionaryController, fragment, index, dictionaryInfo) { @@ -284,7 +284,7 @@ export class DictionaryController { this._deleteDictionaryModal = this._modalController.getModal('dictionary-confirm-delete'); this._allCheckbox = document.querySelector('#all-dictionaries-enabled'); - yomichan.on('databaseUpdated', this._onDatabaseUpdated.bind(this)); + yomitan.on('databaseUpdated', this._onDatabaseUpdated.bind(this)); this._settingsController.on('optionsChanged', this._onOptionsChanged.bind(this)); this._allCheckbox.addEventListener('change', this._onAllCheckboxChange.bind(this), false); document.querySelector('#dictionary-confirm-delete-button').addEventListener('click', this._onDictionaryConfirmDelete.bind(this), false); @@ -681,7 +681,7 @@ export class DictionaryController { async _deleteDictionaryInternal(dictionaryTitle, onProgress) { await new DictionaryWorker().deleteDictionary(dictionaryTitle, onProgress); - yomichan.api.triggerDatabaseUpdated('dictionary', 'delete'); + yomitan.api.triggerDatabaseUpdated('dictionary', 'delete'); } async _deleteDictionarySettings(dictionaryTitle) { @@ -706,7 +706,7 @@ export class DictionaryController { } _triggerStorageChanged() { - yomichan.trigger('storageChanged'); + yomitan.trigger('storageChanged'); } _updateDictionaryEntryCount() { diff --git a/ext/js/pages/settings/dictionary-import-controller.js b/ext/js/pages/settings/dictionary-import-controller.js index 57fe1cd4..12d29a6f 100644 --- a/ext/js/pages/settings/dictionary-import-controller.js +++ b/ext/js/pages/settings/dictionary-import-controller.js @@ -18,7 +18,7 @@ import {deserializeError, log} from '../../core.js'; import {DictionaryWorker} from '../../language/dictionary-worker.js'; -import {yomichan} from '../../yomichan.js'; +import {yomitan} from '../../yomitan.js'; import {DictionaryController} from './dictionary-controller.js'; export class DictionaryImportController { @@ -99,7 +99,7 @@ export class DictionaryImportController { this._setSpinnerVisible(true); if (purgeNotification !== null) { purgeNotification.hidden = false; } - await yomichan.api.purgeDatabase(); + await yomitan.api.purgeDatabase(); const errors = await this._clearDictionarySettings(); if (errors.length > 0) { @@ -215,7 +215,7 @@ export class DictionaryImportController { async _importDictionary(file, importDetails, onProgress) { const archiveContent = await this._readFile(file); const {result, errors} = await new DictionaryWorker().importDictionary(archiveContent, importDetails, onProgress); - yomichan.api.triggerDatabaseUpdated('dictionary', 'import'); + yomitan.api.triggerDatabaseUpdated('dictionary', 'import'); const errors2 = await this._addDictionarySettings(result.sequenced, result.title); if (errors.length > 0) { @@ -346,6 +346,6 @@ export class DictionaryImportController { } _triggerStorageChanged() { - yomichan.trigger('storageChanged'); + yomitan.trigger('storageChanged'); } } diff --git a/ext/js/pages/settings/extension-keyboard-shortcuts-controller.js b/ext/js/pages/settings/extension-keyboard-shortcuts-controller.js index 6e84fa0e..4f3ed569 100644 --- a/ext/js/pages/settings/extension-keyboard-shortcuts-controller.js +++ b/ext/js/pages/settings/extension-keyboard-shortcuts-controller.js @@ -18,7 +18,7 @@ import {EventListenerCollection, isObject} from '../../core.js'; import {HotkeyUtil} from '../../input/hotkey-util.js'; -import {yomichan} from '../../yomichan.js'; +import {yomitan} from '../../yomitan.js'; import {KeyboardMouseInputField} from './keyboard-mouse-input-field.js'; export class ExtensionKeyboardShortcutController { @@ -53,7 +53,7 @@ export class ExtensionKeyboardShortcutController { this._clearButton.addEventListener('click', this._onClearClick.bind(this)); } - const {platform: {os}} = await yomichan.api.getEnvironmentInfo(); + const {platform: {os}} = await yomitan.api.getEnvironmentInfo(); this._os = os; this._hotkeyUtil.os = os; diff --git a/ext/js/pages/settings/keyboard-shortcuts-controller.js b/ext/js/pages/settings/keyboard-shortcuts-controller.js index 3f91d2f9..e7ad4d15 100644 --- a/ext/js/pages/settings/keyboard-shortcuts-controller.js +++ b/ext/js/pages/settings/keyboard-shortcuts-controller.js @@ -19,7 +19,7 @@ import {EventListenerCollection} from '../../core.js'; import {DocumentUtil} from '../../dom/document-util.js'; import {ObjectPropertyAccessor} from '../../general/object-property-accessor.js'; -import {yomichan} from '../../yomichan.js'; +import {yomitan} from '../../yomitan.js'; import {KeyboardMouseInputField} from './keyboard-mouse-input-field.js'; export class KeyboardShortcutController { @@ -63,7 +63,7 @@ export class KeyboardShortcutController { } async prepare() { - const {platform: {os}} = await yomichan.api.getEnvironmentInfo(); + const {platform: {os}} = await yomitan.api.getEnvironmentInfo(); this._os = os; this._addButton = document.querySelector('#hotkey-list-add'); diff --git a/ext/js/pages/settings/mecab-controller.js b/ext/js/pages/settings/mecab-controller.js index 6f9f15ed..a839fc21 100644 --- a/ext/js/pages/settings/mecab-controller.js +++ b/ext/js/pages/settings/mecab-controller.js @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -import {yomichan} from '../../yomichan.js'; +import {yomitan} from '../../yomitan.js'; export class MecabController { constructor(settingsController) { @@ -48,7 +48,7 @@ export class MecabController { this._testButton.disabled = true; this._resultsContainer.textContent = ''; this._resultsContainer.hidden = true; - await yomichan.api.testMecab(); + await yomitan.api.testMecab(); this._setStatus('Connection was successful', false); } catch (e) { this._setStatus(e.message, true); diff --git a/ext/js/pages/settings/persistent-storage-controller.js b/ext/js/pages/settings/persistent-storage-controller.js index 1c3bc276..aa060c14 100644 --- a/ext/js/pages/settings/persistent-storage-controller.js +++ b/ext/js/pages/settings/persistent-storage-controller.js @@ -17,7 +17,7 @@ */ import {isObject} from '../../core.js'; -import {yomichan} from '../../yomichan.js'; +import {yomitan} from '../../yomitan.js'; export class PersistentStorageController { constructor() { @@ -71,7 +71,7 @@ export class PersistentStorageController { const node = document.querySelector('#storage-persistent-fail-warning'); if (node !== null) { node.hidden = isStoragePeristent; } - yomichan.trigger('storageChanged'); + yomitan.trigger('storageChanged'); } _isPersistentStorageSupported() { diff --git a/ext/js/pages/settings/popup-preview-frame-main.js b/ext/js/pages/settings/popup-preview-frame-main.js index 0b69fea0..59e409c5 100644 --- a/ext/js/pages/settings/popup-preview-frame-main.js +++ b/ext/js/pages/settings/popup-preview-frame-main.js @@ -19,14 +19,14 @@ import {PopupFactory} from '../../app/popup-factory.js'; import {log} from '../../core.js'; import {HotkeyHandler} from '../../input/hotkey-handler.js'; -import {yomichan} from '../../yomichan.js'; +import {yomitan} from '../../yomitan.js'; import {PopupPreviewFrame} from './popup-preview-frame.js'; (async () => { try { - await yomichan.prepare(); + await yomitan.prepare(); - const {tabId, frameId} = await yomichan.api.frameInformationGet(); + const {tabId, frameId} = await yomitan.api.frameInformationGet(); const hotkeyHandler = new HotkeyHandler(); hotkeyHandler.prepare(); diff --git a/ext/js/pages/settings/popup-preview-frame.js b/ext/js/pages/settings/popup-preview-frame.js index c0d4358d..7a1a0b3a 100644 --- a/ext/js/pages/settings/popup-preview-frame.js +++ b/ext/js/pages/settings/popup-preview-frame.js @@ -19,7 +19,7 @@ import * as wanakana from '../../../lib/wanakana.js'; import {Frontend} from '../../app/frontend.js'; import {TextSourceRange} from '../../dom/text-source-range.js'; -import {yomichan} from '../../yomichan.js'; +import {yomitan} from '../../yomitan.js'; export class PopupPreviewFrame { constructor(tabId, frameId, popupFactory, hotkeyHandler) { @@ -62,8 +62,8 @@ export class PopupPreviewFrame { this._exampleTextInput.addEventListener('input', this._onExampleTextInputInput.bind(this), false); // Overwrite API functions - this._apiOptionsGetOld = yomichan.api.optionsGet.bind(yomichan.api); - yomichan.api.optionsGet = this._apiOptionsGet.bind(this); + this._apiOptionsGetOld = yomitan.api.optionsGet.bind(yomitan.api); + yomitan.api.optionsGet = this._apiOptionsGet.bind(this); // Overwrite frontend this._frontend = new Frontend({ diff --git a/ext/js/pages/settings/popup-window-controller.js b/ext/js/pages/settings/popup-window-controller.js index 6f4d9ec3..9b6708d5 100644 --- a/ext/js/pages/settings/popup-window-controller.js +++ b/ext/js/pages/settings/popup-window-controller.js @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -import {yomichan} from '../../yomichan.js'; +import {yomitan} from '../../yomitan.js'; export class PopupWindowController { prepare() { @@ -32,6 +32,6 @@ export class PopupWindowController { } async _testWindowOpen() { - await yomichan.api.getOrCreateSearchPopup({focus: true}); + await yomitan.api.getOrCreateSearchPopup({focus: true}); } } diff --git a/ext/js/pages/settings/profile-controller.js b/ext/js/pages/settings/profile-controller.js index a4a64e60..a5bf41b3 100644 --- a/ext/js/pages/settings/profile-controller.js +++ b/ext/js/pages/settings/profile-controller.js @@ -17,7 +17,7 @@ */ import {clone, EventListenerCollection} from '../../core.js'; -import {yomichan} from '../../yomichan.js'; +import {yomitan} from '../../yomitan.js'; import {ProfileConditionsUI} from './profile-conditions-ui.js'; export class ProfileController { @@ -53,7 +53,7 @@ export class ProfileController { } async prepare() { - const {platform: {os}} = await yomichan.api.getEnvironmentInfo(); + const {platform: {os}} = await yomitan.api.getEnvironmentInfo(); this._profileConditionsUI.os = os; this._profileActiveSelect = document.querySelector('#profile-active-select'); diff --git a/ext/js/pages/settings/scan-inputs-controller.js b/ext/js/pages/settings/scan-inputs-controller.js index ea8d500a..252e7238 100644 --- a/ext/js/pages/settings/scan-inputs-controller.js +++ b/ext/js/pages/settings/scan-inputs-controller.js @@ -17,7 +17,7 @@ */ import {EventListenerCollection} from '../../core.js'; -import {yomichan} from '../../yomichan.js'; +import {yomitan} from '../../yomitan.js'; import {KeyboardMouseInputField} from './keyboard-mouse-input-field.js'; export class ScanInputsController { @@ -31,7 +31,7 @@ export class ScanInputsController { } async prepare() { - const {platform: {os}} = await yomichan.api.getEnvironmentInfo(); + const {platform: {os}} = await yomitan.api.getEnvironmentInfo(); this._os = os; this._container = document.querySelector('#scan-input-list'); diff --git a/ext/js/pages/settings/scan-inputs-simple-controller.js b/ext/js/pages/settings/scan-inputs-simple-controller.js index 79ffb773..112c03a9 100644 --- a/ext/js/pages/settings/scan-inputs-simple-controller.js +++ b/ext/js/pages/settings/scan-inputs-simple-controller.js @@ -17,7 +17,7 @@ */ import {HotkeyUtil} from '../../input/hotkey-util.js'; -import {yomichan} from '../../yomichan.js'; +import {yomitan} from '../../yomitan.js'; import {ScanInputsController} from './scan-inputs-controller.js'; export class ScanInputsSimpleController { @@ -33,7 +33,7 @@ export class ScanInputsSimpleController { this._middleMouseButtonScan = document.querySelector('#middle-mouse-button-scan'); this._mainScanModifierKeyInput = document.querySelector('#main-scan-modifier-key'); - const {platform: {os}} = await yomichan.api.getEnvironmentInfo(); + const {platform: {os}} = await yomitan.api.getEnvironmentInfo(); this._hotkeyUtil.os = os; this._mainScanModifierKeyInputHasOther = false; diff --git a/ext/js/pages/settings/secondary-search-dictionary-controller.js b/ext/js/pages/settings/secondary-search-dictionary-controller.js index 30575526..cc873901 100644 --- a/ext/js/pages/settings/secondary-search-dictionary-controller.js +++ b/ext/js/pages/settings/secondary-search-dictionary-controller.js @@ -17,7 +17,7 @@ */ import {EventListenerCollection} from '../../core.js'; -import {yomichan} from '../../yomichan.js'; +import {yomitan} from '../../yomitan.js'; export class SecondarySearchDictionaryController { constructor(settingsController) { @@ -33,7 +33,7 @@ export class SecondarySearchDictionaryController { await this._onDatabaseUpdated(); - yomichan.on('databaseUpdated', this._onDatabaseUpdated.bind(this)); + yomitan.on('databaseUpdated', this._onDatabaseUpdated.bind(this)); this._settingsController.on('optionsChanged', this._onOptionsChanged.bind(this)); this._settingsController.on('dictionarySettingsReordered', this._onDictionarySettingsReordered.bind(this)); } diff --git a/ext/js/pages/settings/settings-controller.js b/ext/js/pages/settings/settings-controller.js index 6f83c4c0..83ccdb39 100644 --- a/ext/js/pages/settings/settings-controller.js +++ b/ext/js/pages/settings/settings-controller.js @@ -20,7 +20,7 @@ import {EventDispatcher, EventListenerCollection, generateId, isObject} from '.. import {OptionsUtil} from '../../data/options-util.js'; import {PermissionsUtil} from '../../data/permissions-util.js'; import {HtmlTemplateCollection} from '../../dom/html-template-collection.js'; -import {yomichan} from '../../yomichan.js'; +import {yomitan} from '../../yomitan.js'; export class SettingsController extends EventDispatcher { constructor() { @@ -51,7 +51,7 @@ export class SettingsController extends EventDispatcher { } async prepare() { - yomichan.on('optionsUpdated', this._onOptionsUpdated.bind(this)); + yomitan.on('optionsUpdated', this._onOptionsUpdated.bind(this)); if (this._canObservePermissionsChanges()) { chrome.permissions.onAdded.addListener(this._onPermissionsChanged.bind(this)); chrome.permissions.onRemoved.addListener(this._onPermissionsChanged.bind(this)); @@ -69,16 +69,16 @@ export class SettingsController extends EventDispatcher { async getOptions() { const optionsContext = this.getOptionsContext(); - return await yomichan.api.optionsGet(optionsContext); + return await yomitan.api.optionsGet(optionsContext); } async getOptionsFull() { - return await yomichan.api.optionsGetFull(); + return await yomitan.api.optionsGetFull(); } async setAllSettings(value) { const profileIndex = value.profileCurrent; - await yomichan.api.setAllSettings(value, this._source); + await yomitan.api.setAllSettings(value, this._source); this._setProfileIndex(profileIndex, true); } @@ -115,7 +115,7 @@ export class SettingsController extends EventDispatcher { } async getDictionaryInfo() { - return await yomichan.api.getDictionaryInfo(); + return await yomitan.api.getDictionaryInfo(); } getOptionsContext() { @@ -186,12 +186,12 @@ export class SettingsController extends EventDispatcher { async _getSettings(targets, extraFields) { targets = this._setupTargets(targets, extraFields); - return await yomichan.api.getSettings(targets); + return await yomitan.api.getSettings(targets); } async _modifySettings(targets, extraFields) { targets = this._setupTargets(targets, extraFields); - return await yomichan.api.modifySettings(targets, this._source); + return await yomitan.api.modifySettings(targets, this._source); } _onBeforeUnload(e) { diff --git a/ext/js/pages/settings/settings-main.js b/ext/js/pages/settings/settings-main.js index 1cd0b0a9..f9ea0aa1 100644 --- a/ext/js/pages/settings/settings-main.js +++ b/ext/js/pages/settings/settings-main.js @@ -18,7 +18,7 @@ import {log} from '../../core.js'; import {DocumentFocusController} from '../../dom/document-focus-controller.js'; -import {yomichan} from '../../yomichan.js'; +import {yomitan} from '../../yomitan.js'; import {ExtensionContentController} from '../common/extension-content-controller.js'; import {AnkiController} from './anki-controller.js'; import {AnkiTemplatesController} from './anki-templates-controller.js'; @@ -70,7 +70,7 @@ async function setupGenericSettingsController(genericSettingController) { document.documentElement.dataset.loadingStalled = 'true'; }, 1000); - await yomichan.prepare(); + await yomitan.prepare(); if (prepareTimer !== null) { clearTimeout(prepareTimer); diff --git a/ext/js/pages/settings/sort-frequency-dictionary-controller.js b/ext/js/pages/settings/sort-frequency-dictionary-controller.js index c946400f..53104085 100644 --- a/ext/js/pages/settings/sort-frequency-dictionary-controller.js +++ b/ext/js/pages/settings/sort-frequency-dictionary-controller.js @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -import {yomichan} from '../../yomichan.js'; +import {yomitan} from '../../yomitan.js'; export class SortFrequencyDictionaryController { constructor(settingsController) { @@ -36,7 +36,7 @@ export class SortFrequencyDictionaryController { await this._onDatabaseUpdated(); - yomichan.on('databaseUpdated', this._onDatabaseUpdated.bind(this)); + yomitan.on('databaseUpdated', this._onDatabaseUpdated.bind(this)); this._settingsController.on('optionsChanged', this._onOptionsChanged.bind(this)); this._sortFrequencyDictionarySelect.addEventListener('change', this._onSortFrequencyDictionarySelectChange.bind(this)); this._sortFrequencyDictionaryOrderSelect.addEventListener('change', this._onSortFrequencyDictionaryOrderSelectChange.bind(this)); @@ -124,7 +124,7 @@ export class SortFrequencyDictionaryController { const lessCommonTerms = ['行なう', '論じる', '過す', '行方', '人口', '猫', '犬', '滝', '理', '暁']; const terms = [...moreCommonTerms, ...lessCommonTerms]; - const frequencies = await yomichan.api.getTermFrequencies( + const frequencies = await yomitan.api.getTermFrequencies( terms.map((term) => ({term, reading: null})), [dictionary] ); diff --git a/ext/js/pages/settings/storage-controller.js b/ext/js/pages/settings/storage-controller.js index 8bc63725..ba1145b8 100644 --- a/ext/js/pages/settings/storage-controller.js +++ b/ext/js/pages/settings/storage-controller.js @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -import {yomichan} from '../../yomichan.js'; +import {yomitan} from '../../yomitan.js'; export class StorageController { constructor(persistentStorageController) { @@ -41,7 +41,7 @@ export class StorageController { this._storageUseInvalidNodes = document.querySelectorAll('.storage-use-invalid'); document.querySelector('#storage-refresh').addEventListener('click', this._onStorageRefreshButtonClick.bind(this), false); - yomichan.on('storageChanged', this._onStorageChanged.bind(this)); + yomitan.on('storageChanged', this._onStorageChanged.bind(this)); this._updateStats(); } diff --git a/ext/js/pages/welcome-main.js b/ext/js/pages/welcome-main.js index d2596921..b1438187 100644 --- a/ext/js/pages/welcome-main.js +++ b/ext/js/pages/welcome-main.js @@ -18,7 +18,7 @@ import {log} from '../core.js'; import {DocumentFocusController} from '../dom/document-focus-controller.js'; -import {yomichan} from '../yomichan.js'; +import {yomitan} from '../yomitan.js'; import {ExtensionContentController} from './common/extension-content-controller.js'; import {DictionaryController} from './settings/dictionary-controller.js'; import {DictionaryImportController} from './settings/dictionary-import-controller.js'; @@ -32,7 +32,7 @@ import {StatusFooter} from './settings/status-footer.js'; async function setupEnvironmentInfo() { const {manifest_version: manifestVersion} = chrome.runtime.getManifest(); - const {browser, platform} = await yomichan.api.getEnvironmentInfo(); + const {browser, platform} = await yomitan.api.getEnvironmentInfo(); document.documentElement.dataset.browser = browser; document.documentElement.dataset.os = platform.os; document.documentElement.dataset.manifestVersion = `${manifestVersion}`; @@ -54,7 +54,7 @@ async function setupGenericSettingsController(genericSettingController) { const statusFooter = new StatusFooter(document.querySelector('.status-footer-container')); statusFooter.prepare(); - await yomichan.prepare(); + await yomitan.prepare(); setupEnvironmentInfo(); diff --git a/ext/js/script/dynamic-loader-sentinel.js b/ext/js/script/dynamic-loader-sentinel.js index 7f08c503..cb03b0b9 100644 --- a/ext/js/script/dynamic-loader-sentinel.js +++ b/ext/js/script/dynamic-loader-sentinel.js @@ -16,6 +16,6 @@ * along with this program. If not, see . */ -import {yomichan} from '../yomichan.js'; +import {yomitan} from '../yomitan.js'; -yomichan.trigger('dynamicLoaderSentinel', {script: document.currentScript}); +yomitan.trigger('dynamicLoaderSentinel', {script: document.currentScript}); diff --git a/ext/js/script/dynamic-loader.js b/ext/js/script/dynamic-loader.js index 2eced077..ec95ff03 100644 --- a/ext/js/script/dynamic-loader.js +++ b/ext/js/script/dynamic-loader.js @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -import {yomichan} from '../yomichan.js'; +import {yomitan} from '../yomitan.js'; export const dynamicLoader = (() => { const injectedStylesheets = new Map(); @@ -44,7 +44,7 @@ export const dynamicLoader = (() => { } async function loadStyle(id, type, value, useWebExtensionApi=false, parentNode=null) { - if (useWebExtensionApi && yomichan.isExtensionUrl(window.location.href)) { + if (useWebExtensionApi && yomitan.isExtensionUrl(window.location.href)) { // Permissions error will occur if trying to use the WebExtension API to inject into an extension page useWebExtensionApi = false; } @@ -60,7 +60,7 @@ export const dynamicLoader = (() => { } if (type === 'file-content') { - value = await yomichan.api.getStylesheetContent(value); + value = await yomitan.api.getStylesheetContent(value); type = 'code'; useWebExtensionApi = false; } @@ -72,7 +72,7 @@ export const dynamicLoader = (() => { } setInjectedStylesheet(id, parentNode, null); - await yomichan.api.injectStylesheet(type, value); + await yomitan.api.injectStylesheet(type, value); return null; } @@ -141,11 +141,11 @@ export const dynamicLoader = (() => { const sentinelEventName = 'dynamicLoaderSentinel'; const sentinelEventCallback = (e) => { if (e.script !== script) { return; } - yomichan.off(sentinelEventName, sentinelEventCallback); + yomitan.off(sentinelEventName, sentinelEventCallback); parent.removeChild(script); resolve(); }; - yomichan.on(sentinelEventName, sentinelEventCallback); + yomitan.on(sentinelEventName, sentinelEventCallback); try { script.type = 'module'; @@ -153,7 +153,7 @@ export const dynamicLoader = (() => { script.src = '/js/script/dynamic-loader-sentinel.js'; parent.appendChild(script); } catch (e) { - yomichan.off(sentinelEventName, sentinelEventCallback); + yomitan.off(sentinelEventName, sentinelEventCallback); reject(e); } } diff --git a/ext/js/yomichan.js b/ext/js/yomichan.js deleted file mode 100644 index 985e3f5b..00000000 --- a/ext/js/yomichan.js +++ /dev/null @@ -1,241 +0,0 @@ -/* - * Copyright (C) 2023 Yomitan Authors - * Copyright (C) 2020-2022 Yomichan Authors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -import {API} from './comm/api.js'; -import {CrossFrameAPI} from './comm/cross-frame-api.js'; -import {EventDispatcher, deferPromise, invokeMessageHandler, log, serializeError} from './core.js'; - -// Set up chrome alias if it's not available (Edge Legacy) -if ((() => { - let hasChrome = false; - let hasBrowser = false; - try { - hasChrome = (typeof chrome === 'object' && chrome !== null && typeof chrome.runtime !== 'undefined'); - } catch (e) { - // NOP - } - try { - hasBrowser = (typeof browser === 'object' && browser !== null && typeof browser.runtime !== 'undefined'); - } catch (e) { - // NOP - } - return (hasBrowser && !hasChrome); -})()) { - chrome = browser; -} - -/** - * The Yomichan class is a core component through which various APIs are handled and invoked. - */ -class Yomichan extends EventDispatcher { - /** - * Creates a new instance. The instance should not be used until it has been fully prepare()'d. - */ - constructor() { - super(); - - try { - const manifest = chrome.runtime.getManifest(); - this._extensionName = `${manifest.name} v${manifest.version}`; - } catch (e) { - this._extensionName = 'Yomichan'; - } - - try { - this._extensionUrlBase = chrome.runtime.getURL('/'); - } catch (e) { - this._extensionUrlBase = null; - } - - this._isBackground = null; - this._api = null; - this._crossFrame = null; - this._isExtensionUnloaded = false; - this._isTriggeringExtensionUnloaded = false; - this._isReady = false; - - const {promise, resolve} = deferPromise(); - this._isBackendReadyPromise = promise; - this._isBackendReadyPromiseResolve = resolve; - - this._messageHandlers = new Map([ - ['Yomichan.isReady', {async: false, handler: this._onMessageIsReady.bind(this)}], - ['Yomichan.backendReady', {async: false, handler: this._onMessageBackendReady.bind(this)}], - ['Yomichan.getUrl', {async: false, handler: this._onMessageGetUrl.bind(this)}], - ['Yomichan.optionsUpdated', {async: false, handler: this._onMessageOptionsUpdated.bind(this)}], - ['Yomichan.databaseUpdated', {async: false, handler: this._onMessageDatabaseUpdated.bind(this)}], - ['Yomichan.zoomChanged', {async: false, handler: this._onMessageZoomChanged.bind(this)}] - ]); - } - - /** - * Whether the current frame is the background page/service worker or not. - * @type {boolean} - */ - get isBackground() { - return this._isBackground; - } - - /** - * Whether or not the extension is unloaded. - * @type {boolean} - */ - get isExtensionUnloaded() { - return this._isExtensionUnloaded; - } - - /** - * Gets the API instance for communicating with the backend. - * This value will be null on the background page/service worker. - * @type {API} - */ - get api() { - return this._api; - } - - /** - * Gets the CrossFrameAPI instance for communicating with different frames. - * This value will be null on the background page/service worker. - * @type {CrossFrameAPI} - */ - get crossFrame() { - return this._crossFrame; - } - - /** - * Prepares the instance for use. - * @param {boolean} [isBackground=false] Assigns whether this instance is being used from the background page/service worker. - */ - async prepare(isBackground=false) { - this._isBackground = isBackground; - chrome.runtime.onMessage.addListener(this._onMessage.bind(this)); - - if (!isBackground) { - this._api = new API(this); - - this.sendMessage({action: 'requestBackendReadySignal'}); - await this._isBackendReadyPromise; - - this._crossFrame = new CrossFrameAPI(); - await this._crossFrame.prepare(); - - log.on('log', this._onForwardLog.bind(this)); - } - } - - /** - * Sends a message to the backend indicating that the frame is ready and all script - * setup has completed. - */ - ready() { - this._isReady = true; - this.sendMessage({action: 'yomichanReady'}); - } - - /** - * Checks whether or not a URL is an extension URL. - * @param {string} url The URL to check. - * @returns {boolean} `true` if the URL is an extension URL, `false` otherwise. - */ - isExtensionUrl(url) { - return this._extensionUrlBase !== null && url.startsWith(this._extensionUrlBase); - } - - /** - * Runs `chrome.runtime.sendMessage()` with additional exception handling events. - * @param {...*} args The arguments to be passed to `chrome.runtime.sendMessage()`. - * @returns {void} The result of the `chrome.runtime.sendMessage()` call. - * @throws {Error} Errors thrown by `chrome.runtime.sendMessage()` are re-thrown. - */ - sendMessage(...args) { - try { - return chrome.runtime.sendMessage(...args); - } catch (e) { - this.triggerExtensionUnloaded(); - throw e; - } - } - - triggerExtensionUnloaded() { - this._isExtensionUnloaded = true; - if (this._isTriggeringExtensionUnloaded) { return; } - try { - this._isTriggeringExtensionUnloaded = true; - this.trigger('extensionUnloaded'); - } finally { - this._isTriggeringExtensionUnloaded = false; - } - } - - // Private - - _getUrl() { - return location.href; - } - - _getLogContext() { - return {url: this._getUrl()}; - } - - _onMessage({action, params}, sender, callback) { - const messageHandler = this._messageHandlers.get(action); - if (typeof messageHandler === 'undefined') { return false; } - return invokeMessageHandler(messageHandler, params, callback, sender); - } - - _onMessageIsReady() { - return this._isReady; - } - - _onMessageBackendReady() { - if (this._isBackendReadyPromiseResolve === null) { return; } - this._isBackendReadyPromiseResolve(); - this._isBackendReadyPromiseResolve = null; - } - - _onMessageGetUrl() { - return {url: this._getUrl()}; - } - - _onMessageOptionsUpdated({source}) { - if (source !== 'background') { - this.trigger('optionsUpdated', {source}); - } - } - - _onMessageDatabaseUpdated({type, cause}) { - this.trigger('databaseUpdated', {type, cause}); - } - - _onMessageZoomChanged({oldZoomFactor, newZoomFactor}) { - this.trigger('zoomChanged', {oldZoomFactor, newZoomFactor}); - } - - async _onForwardLog({error, level, context}) { - try { - await this._api.log(serializeError(error), level, context); - } catch (e) { - // NOP - } - } -} - -/** - * The default Yomichan class instance. - */ -export const yomichan = new Yomichan(); diff --git a/ext/js/yomitan.js b/ext/js/yomitan.js new file mode 100644 index 00000000..5535aeb6 --- /dev/null +++ b/ext/js/yomitan.js @@ -0,0 +1,241 @@ +/* + * Copyright (C) 2023 Yomitan Authors + * Copyright (C) 2020-2022 Yomichan Authors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +import {API} from './comm/api.js'; +import {CrossFrameAPI} from './comm/cross-frame-api.js'; +import {EventDispatcher, deferPromise, invokeMessageHandler, log, serializeError} from './core.js'; + +// Set up chrome alias if it's not available (Edge Legacy) +if ((() => { + let hasChrome = false; + let hasBrowser = false; + try { + hasChrome = (typeof chrome === 'object' && chrome !== null && typeof chrome.runtime !== 'undefined'); + } catch (e) { + // NOP + } + try { + hasBrowser = (typeof browser === 'object' && browser !== null && typeof browser.runtime !== 'undefined'); + } catch (e) { + // NOP + } + return (hasBrowser && !hasChrome); +})()) { + chrome = browser; +} + +/** + * The Yomitan class is a core component through which various APIs are handled and invoked. + */ +class Yomitan extends EventDispatcher { + /** + * Creates a new instance. The instance should not be used until it has been fully prepare()'d. + */ + constructor() { + super(); + + try { + const manifest = chrome.runtime.getManifest(); + this._extensionName = `${manifest.name} v${manifest.version}`; + } catch (e) { + this._extensionName = 'Yomitan'; + } + + try { + this._extensionUrlBase = chrome.runtime.getURL('/'); + } catch (e) { + this._extensionUrlBase = null; + } + + this._isBackground = null; + this._api = null; + this._crossFrame = null; + this._isExtensionUnloaded = false; + this._isTriggeringExtensionUnloaded = false; + this._isReady = false; + + const {promise, resolve} = deferPromise(); + this._isBackendReadyPromise = promise; + this._isBackendReadyPromiseResolve = resolve; + + this._messageHandlers = new Map([ + ['Yomitan.isReady', {async: false, handler: this._onMessageIsReady.bind(this)}], + ['Yomitan.backendReady', {async: false, handler: this._onMessageBackendReady.bind(this)}], + ['Yomitan.getUrl', {async: false, handler: this._onMessageGetUrl.bind(this)}], + ['Yomitan.optionsUpdated', {async: false, handler: this._onMessageOptionsUpdated.bind(this)}], + ['Yomitan.databaseUpdated', {async: false, handler: this._onMessageDatabaseUpdated.bind(this)}], + ['Yomitan.zoomChanged', {async: false, handler: this._onMessageZoomChanged.bind(this)}] + ]); + } + + /** + * Whether the current frame is the background page/service worker or not. + * @type {boolean} + */ + get isBackground() { + return this._isBackground; + } + + /** + * Whether or not the extension is unloaded. + * @type {boolean} + */ + get isExtensionUnloaded() { + return this._isExtensionUnloaded; + } + + /** + * Gets the API instance for communicating with the backend. + * This value will be null on the background page/service worker. + * @type {API} + */ + get api() { + return this._api; + } + + /** + * Gets the CrossFrameAPI instance for communicating with different frames. + * This value will be null on the background page/service worker. + * @type {CrossFrameAPI} + */ + get crossFrame() { + return this._crossFrame; + } + + /** + * Prepares the instance for use. + * @param {boolean} [isBackground=false] Assigns whether this instance is being used from the background page/service worker. + */ + async prepare(isBackground=false) { + this._isBackground = isBackground; + chrome.runtime.onMessage.addListener(this._onMessage.bind(this)); + + if (!isBackground) { + this._api = new API(this); + + this.sendMessage({action: 'requestBackendReadySignal'}); + await this._isBackendReadyPromise; + + this._crossFrame = new CrossFrameAPI(); + await this._crossFrame.prepare(); + + log.on('log', this._onForwardLog.bind(this)); + } + } + + /** + * Sends a message to the backend indicating that the frame is ready and all script + * setup has completed. + */ + ready() { + this._isReady = true; + this.sendMessage({action: 'yomitanReady'}); + } + + /** + * Checks whether or not a URL is an extension URL. + * @param {string} url The URL to check. + * @returns {boolean} `true` if the URL is an extension URL, `false` otherwise. + */ + isExtensionUrl(url) { + return this._extensionUrlBase !== null && url.startsWith(this._extensionUrlBase); + } + + /** + * Runs `chrome.runtime.sendMessage()` with additional exception handling events. + * @param {...*} args The arguments to be passed to `chrome.runtime.sendMessage()`. + * @returns {void} The result of the `chrome.runtime.sendMessage()` call. + * @throws {Error} Errors thrown by `chrome.runtime.sendMessage()` are re-thrown. + */ + sendMessage(...args) { + try { + return chrome.runtime.sendMessage(...args); + } catch (e) { + this.triggerExtensionUnloaded(); + throw e; + } + } + + triggerExtensionUnloaded() { + this._isExtensionUnloaded = true; + if (this._isTriggeringExtensionUnloaded) { return; } + try { + this._isTriggeringExtensionUnloaded = true; + this.trigger('extensionUnloaded'); + } finally { + this._isTriggeringExtensionUnloaded = false; + } + } + + // Private + + _getUrl() { + return location.href; + } + + _getLogContext() { + return {url: this._getUrl()}; + } + + _onMessage({action, params}, sender, callback) { + const messageHandler = this._messageHandlers.get(action); + if (typeof messageHandler === 'undefined') { return false; } + return invokeMessageHandler(messageHandler, params, callback, sender); + } + + _onMessageIsReady() { + return this._isReady; + } + + _onMessageBackendReady() { + if (this._isBackendReadyPromiseResolve === null) { return; } + this._isBackendReadyPromiseResolve(); + this._isBackendReadyPromiseResolve = null; + } + + _onMessageGetUrl() { + return {url: this._getUrl()}; + } + + _onMessageOptionsUpdated({source}) { + if (source !== 'background') { + this.trigger('optionsUpdated', {source}); + } + } + + _onMessageDatabaseUpdated({type, cause}) { + this.trigger('databaseUpdated', {type, cause}); + } + + _onMessageZoomChanged({oldZoomFactor, newZoomFactor}) { + this.trigger('zoomChanged', {oldZoomFactor, newZoomFactor}); + } + + async _onForwardLog({error, level, context}) { + try { + await this._api.log(serializeError(error), level, context); + } catch (e) { + // NOP + } + } +} + +/** + * The default Yomitan class instance. + */ +export const yomitan = new Yomitan(); -- cgit v1.2.3