aboutsummaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorsiikamiika <siikamiika@users.noreply.github.com>2019-10-26 19:12:13 +0300
committersiikamiika <siikamiika@users.noreply.github.com>2019-10-26 19:12:13 +0300
commitbbbd23c842fae4a6f21afcf91fb797dd6f5709f7 (patch)
tree455db64482c47be2fe8fa0a00e6d495f8ac50d3c /ext
parent303205dc124a1dde981db5b6401961f797e3a6d4 (diff)
add button to enable/disable wanakana IME
Diffstat (limited to 'ext')
-rw-r--r--ext/bg/js/search.js40
-rw-r--r--ext/bg/search.html8
2 files changed, 37 insertions, 11 deletions
diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js
index 8d2e7bf2..11d1d871 100644
--- a/ext/bg/js/search.js
+++ b/ext/bg/js/search.js
@@ -29,7 +29,8 @@ class DisplaySearch extends Display {
this.search = document.querySelector('#search');
this.query = document.querySelector('#query');
this.intro = document.querySelector('#intro');
- this.clipboardMonitorCheck = document.querySelector('#clipboard-monitor');
+ this.clipboardMonitorEnable = document.querySelector('#clipboard-monitor-enable');
+ this.wanakanaEnable = document.querySelector('#wanakana-enable');
this.introVisible = true;
this.introAnimationTimer = null;
@@ -54,17 +55,31 @@ class DisplaySearch extends Display {
if (this.query !== null) {
this.query.addEventListener('input', () => this.onSearchInput(), false);
- const query = DisplaySearch.getSearchQueryFromLocation(window.location.href);
+ if (this.wanakanaEnable !== null) {
+ if (this.wanakanaEnable.checked) {
+ window.wanakana.bind(this.query);
+ }
+ this.wanakanaEnable.addEventListener('change', (e) => {
+ if (e.target.checked) {
+ window.wanakana.bind(this.query);
+ } else {
+ window.wanakana.unbind(this.query);
+ }
+ });
+ }
+
+ let query = DisplaySearch.getSearchQueryFromLocation(window.location.href);
if (query !== null) {
- this.query.value = window.wanakana.toKana(query);
+ if (this.wanakanaEnable !== null && this.wanakanaEnable.checked) {
+ query = window.wanakana.toKana(query);
+ }
+ this.query.value = query;
window.history.replaceState({query}, '');
this.onSearchQueryUpdated(query, false);
}
-
- window.wanakana.bind(this.query);
}
- if (this.clipboardMonitorCheck !== null) {
- this.clipboardMonitorCheck.addEventListener('change', (e) => {
+ if (this.clipboardMonitorEnable !== null) {
+ this.clipboardMonitorEnable.addEventListener('change', (e) => {
if (e.target.checked) {
this.startClipboardMonitor();
} else {
@@ -203,13 +218,20 @@ class DisplaySearch extends Display {
initClipboardMonitor() {
// ignore copy from search page
window.addEventListener('copy', (e) => {
- this.clipboardPrevText = document.getSelection().toString().trim();
+ let prevText = document.getSelection().toString().trim();
+ if (this.wanakanaEnable !== null && this.wanakanaEnable.checked) {
+ prevText = window.wanakana.toKana(prevText);
+ }
+ this.clipboardPrevText = prevText;
});
}
startClipboardMonitor() {
this.clipboardMonitorIntervalId = setInterval(async () => {
- const curText = (await navigator.clipboard.readText()).trim();
+ let curText = (await navigator.clipboard.readText()).trim();
+ if (this.wanakanaEnable !== null && this.wanakanaEnable.checked) {
+ curText = window.wanakana.toKana(curText);
+ }
if (curText && (curText !== this.clipboardPrevText)) {
this.query.value = curText;
this.onSearch();
diff --git a/ext/bg/search.html b/ext/bg/search.html
index 1e650be0..11dca5a2 100644
--- a/ext/bg/search.html
+++ b/ext/bg/search.html
@@ -20,9 +20,13 @@
</div>
<div class="input-group" style="padding-top: 10px; font-size: 20px;">
+ <span title="Enable kana input method" class="input-group-text">
+ <label for="wanakana-enable">あ</label>
+ <input type="checkbox" id="wanakana-enable" checked />
+ </span>
<span title="Enable clipboard monitor" class="input-group-text">
- <label for="clipboard-monitor"><span class="glyphicon glyphicon-paste"></span></label>
- <input type="checkbox" id="clipboard-monitor" />
+ <label for="clipboard-monitor-enable"><span class="glyphicon glyphicon-paste"></span></label>
+ <input type="checkbox" id="clipboard-monitor-enable" />
</span>
</div>