summaryrefslogtreecommitdiff
path: root/ext/bg/js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-08-01 16:22:00 -0400
committerGitHub <noreply@github.com>2020-08-01 16:22:00 -0400
commit1e839cd230e53f822478f945cb415a8af2b09aef (patch)
treeeeb4c9552ce591b52642f38542f83f8094066231 /ext/bg/js
parentb52074b3f0df09b9e37a210789507aa553a2dc9d (diff)
More display refactoring (#697)
* Remove some unnecessary _setQuery calls * Add support for forcing the query parser to be visible or hidden * Move _setEventListenersActive calls * Remove URL for kanji links * Refactor _setContentTermsOrKanji * Move search query text assignment into Display * Move title updates into Display * Move popup close calls * Prevent infinite loop of extension unload events
Diffstat (limited to 'ext/bg/js')
-rw-r--r--ext/bg/js/search.js58
1 files changed, 17 insertions, 41 deletions
diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js
index fc857368..d95fd5e4 100644
--- a/ext/bg/js/search.js
+++ b/ext/bg/js/search.js
@@ -63,11 +63,14 @@ class DisplaySearch extends Display {
this.on('contentUpdating', this._onContentUpdating.bind(this));
+ this.queryParserVisible = true;
this.setHistorySettings({useBrowserHistory: true});
const options = this.getOptions();
- const {queryParams: {query='', mode=''}} = parseUrl(window.location.href);
+ const urlSearchParams = new URLSearchParams(location.search);
+ let mode = urlSearchParams.get('mode');
+ if (mode === null) { mode = ''; }
document.documentElement.dataset.searchMode = mode;
@@ -78,8 +81,6 @@ class DisplaySearch extends Display {
this._wanakanaEnable.checked = false;
}
- this._setQuery(query);
-
if (mode !== 'popup') {
if (options.general.enableClipboardMonitor === true) {
this._clipboardMonitorEnable.checked = true;
@@ -147,14 +148,24 @@ class DisplaySearch extends Display {
if (!this._isPrepared) { return; }
const query = this._query.value;
if (query) {
- this._setQuery(query);
this._onSearchQueryUpdated(query, false);
}
}
+ postProcessQuery(query) {
+ if (this._isWanakanaEnabled()) {
+ try {
+ query = wanakana.toKana(query);
+ } catch (e) {
+ // NOP
+ }
+ }
+ return query;
+ }
+
// Private
- _onContentUpdating({type, source, content, urlSearchParams}) {
+ _onContentUpdating({type, content, source}) {
let animate = false;
let valid = false;
switch (type) {
@@ -173,13 +184,8 @@ class DisplaySearch extends Display {
if (typeof source !== 'string') { source = ''; }
- let full = urlSearchParams.get('full');
- if (full === null) { full = source; }
-
- this._closePopups();
- this._setQuery(full);
+ this._query.value = source;
this._setIntroVisible(!valid, animate);
- this._setTitleText(source);
this._updateSearchButton();
}
@@ -289,19 +295,6 @@ class DisplaySearch extends Display {
return this._wanakanaEnable !== null && this._wanakanaEnable.checked;
}
- _setQuery(query) {
- let interpretedQuery = query;
- if (this._isWanakanaEnabled()) {
- try {
- interpretedQuery = wanakana.toKana(query);
- } catch (e) {
- // NOP
- }
- }
- this._query.value = interpretedQuery;
- this.setQueryParserText(interpretedQuery);
- }
-
_setIntroVisible(visible, animate) {
if (this._introVisible === visible) {
return;
@@ -362,19 +355,6 @@ class DisplaySearch extends Display {
this._search.disabled = this._introVisible && (this._query === null || this._query.value.length === 0);
}
- _setTitleText(text) {
- // Chrome limits title to 1024 characters
- if (text.length > 1000) {
- text = text.substring(0, 1000) + '...';
- }
-
- if (text.length === 0) {
- document.title = 'Yomichan Search';
- } else {
- document.title = `${text} - Yomichan Search`;
- }
- }
-
async _prepareNestedPopups() {
let complete = false;
@@ -401,8 +381,4 @@ class DisplaySearch extends Display {
await onOptionsUpdated();
}
-
- _closePopups() {
- yomichan.trigger('closePopups');
- }
}