hide search input in native popups

This commit is contained in:
siikamiika 2020-02-02 16:08:19 +02:00
parent 8d56d6ffcb
commit c16c38638b
4 changed files with 44 additions and 37 deletions

View File

@ -603,8 +603,10 @@ class Backend {
const {popupWidth, popupHeight} = options.general; const {popupWidth, popupHeight} = options.general;
const baseUrl = chrome.runtime.getURL('/bg/search.html'); const baseUrl = chrome.runtime.getURL('/bg/search.html');
const queryString = (query && query.length > 0) ? `?query=${encodeURIComponent(query)}` : ''; const queryParams = {mode};
const url = baseUrl + queryString; if (query && query.length > 0) { queryParams.query = query; }
const queryString = new URLSearchParams(queryParams).toString();
const url = `${baseUrl}?${queryString}`;
switch (mode) { switch (mode) {
case 'sameTab': case 'sameTab':

View File

@ -53,6 +53,8 @@ class DisplaySearch extends Display {
this.search.addEventListener('click', (e) => this.onSearch(e), false); this.search.addEventListener('click', (e) => this.onSearch(e), false);
} }
if (this.query !== null) { if (this.query !== null) {
const {query='', mode=''} = DisplaySearch.parseQueryStringFromLocation(window.location.href);
document.documentElement.dataset.searchMode = mode;
this.query.addEventListener('input', () => this.onSearchInput(), false); this.query.addEventListener('input', () => this.onSearchInput(), false);
if (this.wanakanaEnable !== null) { if (this.wanakanaEnable !== null) {
@ -63,7 +65,6 @@ class DisplaySearch extends Display {
this.wanakanaEnable.checked = false; this.wanakanaEnable.checked = false;
} }
this.wanakanaEnable.addEventListener('change', (e) => { this.wanakanaEnable.addEventListener('change', (e) => {
const query = DisplaySearch.getSearchQueryFromLocation(window.location.href) || '';
if (e.target.checked) { if (e.target.checked) {
window.wanakana.bind(this.query); window.wanakana.bind(this.query);
this.setQuery(window.wanakana.toKana(query)); this.setQuery(window.wanakana.toKana(query));
@ -77,15 +78,12 @@ class DisplaySearch extends Display {
}); });
} }
const query = DisplaySearch.getSearchQueryFromLocation(window.location.href); if (this.isWanakanaEnabled()) {
if (query !== null) { this.setQuery(window.wanakana.toKana(query));
if (this.isWanakanaEnabled()) { } else {
this.setQuery(window.wanakana.toKana(query)); this.setQuery(query);
} else {
this.setQuery(query);
}
this.onSearchQueryUpdated(this.query.value, false);
} }
this.onSearchQueryUpdated(this.query.value, false);
} }
if (this.clipboardMonitorEnable !== null) { if (this.clipboardMonitorEnable !== null) {
if (this.options.general.enableClipboardMonitor === true) { if (this.options.general.enableClipboardMonitor === true) {
@ -162,13 +160,12 @@ class DisplaySearch extends Display {
} }
onPopState() { onPopState() {
const query = DisplaySearch.getSearchQueryFromLocation(window.location.href) || ''; const {query='', mode=''} = DisplaySearch.parseQueryStringFromLocation(window.location.href);
if (this.query !== null) { document.documentElement.dataset.searchMode = mode;
if (this.isWanakanaEnabled()) { if (this.isWanakanaEnabled()) {
this.setQuery(window.wanakana.toKana(query)); this.setQuery(window.wanakana.toKana(query));
} else { } else {
this.setQuery(query); this.setQuery(query);
}
} }
this.onSearchQueryUpdated(this.query.value, false); this.onSearchQueryUpdated(this.query.value, false);
@ -334,9 +331,11 @@ class DisplaySearch extends Display {
} }
} }
static getSearchQueryFromLocation(url) { static parseQueryStringFromLocation(url) {
const match = /^[^?#]*\?(?:[^&#]*&)?query=([^&#]*)/.exec(url); const parsedUrl = new URL(url);
return match !== null ? decodeURIComponent(match[1]) : null; const parsedSearch = new URLSearchParams(parsedUrl.search);
return Array.from(parsedSearch.entries())
.reduce((a, [k, v]) => Object.assign({}, a, {[k]: v}), {});
} }
} }

View File

@ -25,23 +25,25 @@
<p style="margin-bottom: 0;">Search your installed dictionaries by entering a Japanese expression into the field below.</p> <p style="margin-bottom: 0;">Search your installed dictionaries by entering a Japanese expression into the field below.</p>
</div> </div>
<div class="input-group" style="padding-top: 20px;"> <div class="search-input">
<span title="Enable kana input method" class="input-group-text"> <div class="input-group" style="padding-top: 20px;">
<input type="checkbox" id="wanakana-enable" class="icon-checkbox" /> <span title="Enable kana input method" class="input-group-text">
<label for="wanakana-enable" class="scan-disable"></label> <input type="checkbox" id="wanakana-enable" class="icon-checkbox" />
</span> <label for="wanakana-enable" class="scan-disable"></label>
<span title="Enable clipboard monitor" class="input-group-text"> </span>
<input type="checkbox" id="clipboard-monitor-enable" class="icon-checkbox" /> <span title="Enable clipboard monitor" class="input-group-text">
<label for="clipboard-monitor-enable"><span class="glyphicon glyphicon-paste"></span></label> <input type="checkbox" id="clipboard-monitor-enable" class="icon-checkbox" />
</span> <label for="clipboard-monitor-enable"><span class="glyphicon glyphicon-paste"></span></label>
</div> </span>
</div>
<form class="input-group"> <form class="input-group">
<input type="text" class="form-control" placeholder="Search for..." id="query" autofocus> <input type="text" class="form-control" placeholder="Search for..." id="query" autofocus>
<span class="input-group-btn"> <span class="input-group-btn">
<input type="submit" class="btn btn-default form-control" id="search" value="Search"> <input type="submit" class="btn btn-default form-control" id="search" value="Search">
</span> </span>
</form> </form>
</div>
<div id="spinner" hidden><img src="/mixed/img/spinner.gif"></div> <div id="spinner" hidden><img src="/mixed/img/spinner.gif"></div>

View File

@ -136,6 +136,10 @@ html:root[data-yomichan-page=float] .navigation-header:not([hidden])~.navigation
margin-right: 0.2em; margin-right: 0.2em;
} }
html:root[data-yomichan-page=search][data-search-mode=popup] .search-input {
display: none;
}
/* /*
* Entries * Entries