From b7c9fa105764eb2cd5befea86c98fe49f5763a1d Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Tue, 12 Jan 2021 18:04:26 -0500 Subject: Refactor note document title (#1227) * Pass url into setContent * Update where url is checked from * Add documentTitle to state information * Update how _getNoteContext gets the document title * Update how url is fetched for options context * Pass document title in to 'searched' event --- ext/fg/js/frontend.js | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'ext/fg') diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js index e6f72689..8b2df1b0 100644 --- a/ext/fg/js/frontend.js +++ b/ext/fg/js/frontend.js @@ -114,12 +114,11 @@ class Frontend { this._textScanner.on('searched', this._onSearched.bind(this)); api.crossFrame.registerHandlers([ - ['getUrl', {async: false, handler: this._onApiGetUrl.bind(this)}], ['closePopup', {async: false, handler: this._onApiClosePopup.bind(this)}], ['copySelection', {async: false, handler: this._onApiCopySelection.bind(this)}], ['getSelectionText', {async: false, handler: this._onApiGetSelectionText.bind(this)}], ['getPopupInfo', {async: false, handler: this._onApiGetPopupInfo.bind(this)}], - ['getDocumentInformation', {async: false, handler: this._onApiGetDocumentInformation.bind(this)}], + ['getPageInfo', {async: false, handler: this._onApiGetPageInfo.bind(this)}], ['getFrameSize', {async: true, handler: this._onApiGetFrameSize.bind(this)}], ['setFrameSize', {async: true, handler: this._onApiSetFrameSize.bind(this)}] ]); @@ -187,9 +186,10 @@ class Frontend { }; } - _onApiGetDocumentInformation() { + _onApiGetPageInfo() { return { - title: document.title + url: window.location.href, + documentTitle: document.title }; } @@ -251,7 +251,7 @@ class Frontend { } } - _onSearched({type, definitions, sentence, inputInfo: {cause, empty}, textSource, optionsContext, error}) { + _onSearched({type, definitions, sentence, inputInfo: {cause, empty}, textSource, optionsContext, detail: {documentTitle}, error}) { const scanningOptions = this._options.scanning; if (error !== null) { @@ -265,7 +265,7 @@ class Frontend { } if (type !== null) { this._stopClearSelectionDelayed(); const focus = (cause === 'mouseMove'); - this._showContent(textSource, focus, definitions, type, sentence, optionsContext); + this._showContent(textSource, focus, definitions, type, sentence, documentTitle, optionsContext); } else { if (scanningOptions.autoHideResults) { this._clearSelectionDelayed(scanningOptions.hideDelay, false); @@ -497,8 +497,9 @@ class Frontend { this._showPopupContent(textSource, null); } - _showContent(textSource, focus, definitions, type, sentence, optionsContext) { + _showContent(textSource, focus, definitions, type, sentence, documentTitle, optionsContext) { const query = textSource.text(); + const {url} = optionsContext; const details = { focus, history: false, @@ -509,8 +510,10 @@ class Frontend { }, state: { focusEntry: 0, + optionsContext, + url, sentence, - optionsContext + documentTitle }, content: { definitions @@ -624,15 +627,19 @@ class Frontend { } let url = window.location.href; + let documentTitle = document.title; if (this._useProxyPopup) { try { - url = await api.crossFrame.invoke(this._parentFrameId, 'getUrl', {}); + ({url, documentTitle} = await api.crossFrame.invoke(this._parentFrameId, 'getPageInfo', {})); } catch (e) { // NOP } } const depth = this._depth; - return {optionsContext: {depth, url}}; + return { + optionsContext: {depth, url}, + detail: {documentTitle} + }; } } -- cgit v1.2.3