From 704864b7b2365de488150c947d50e27c97d3bc4c Mon Sep 17 00:00:00 2001 From: siikamiika Date: Sat, 26 Oct 2019 18:15:28 +0300 Subject: add clipboard monitor to search page Related to issue #262 about APIs --- ext/bg/search.html | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'ext/bg/search.html') diff --git a/ext/bg/search.html b/ext/bg/search.html index 9d28b358..1e650be0 100644 --- a/ext/bg/search.html +++ b/ext/bg/search.html @@ -19,7 +19,14 @@

Search your installed dictionaries by entering a Japanese expression into the field below.

-
+
+ + + + +
+ + -- cgit v1.2.3 From bbbd23c842fae4a6f21afcf91fb797dd6f5709f7 Mon Sep 17 00:00:00 2001 From: siikamiika Date: Sat, 26 Oct 2019 19:12:13 +0300 Subject: add button to enable/disable wanakana IME --- ext/bg/js/search.js | 40 +++++++++++++++++++++++++++++++--------- ext/bg/search.html | 8 ++++++-- 2 files changed, 37 insertions(+), 11 deletions(-) (limited to 'ext/bg/search.html') 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 @@
+ + + + - - + +
-- cgit v1.2.3 From 70418202cf2739258a4e95fdc7f0fbe4c7c46821 Mon Sep 17 00:00:00 2001 From: siikamiika Date: Sun, 27 Oct 2019 20:11:23 +0200 Subject: make search page checkbox options persist --- ext/bg/js/api.js | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ ext/bg/js/backend.js | 1 + ext/bg/js/options.js | 4 +++- ext/bg/js/search.js | 15 ++++++++++++++- ext/bg/search.html | 2 +- ext/fg/js/api.js | 4 ++++ 6 files changed, 72 insertions(+), 3 deletions(-) (limited to 'ext/bg/search.html') diff --git a/ext/bg/js/api.js b/ext/bg/js/api.js index 88eef431..6c109614 100644 --- a/ext/bg/js/api.js +++ b/ext/bg/js/api.js @@ -21,6 +21,55 @@ function apiOptionsGet(optionsContext) { return utilBackend().getOptions(optionsContext); } +async function apiOptionsSet(changedOptions, optionsContext, source) { + const backend = utilBackend(); + const {depth} = optionsContext; + let options = await apiOptionsGetFull(); + + function getValuePaths(obj) { + let valuePaths = []; + let nodes = [{ + obj: changedOptions, + path: [] + }]; + while (nodes.length > 0) { + let node = nodes.pop(); + Object.keys(node.obj).forEach((key) => { + let path = node.path.concat(key); + let value = node.obj[key]; + if (typeof value === 'object') { + nodes.unshift({ + obj: value, + path: path + }); + } else { + valuePaths.push([value, path]); + } + }); + } + return valuePaths; + } + + function modifyOption(path, value, options) { + let pivot = options; + for (let pathKey of path.slice(0, -1)) { + if (!(pathKey in pivot)) { + return false; + } + pivot = pivot[pathKey]; + } + pivot[path[path.length - 1]] = value; + return true; + } + + for (let [value, path] of getValuePaths(changedOptions)) { + modifyOption(path, value, options.profiles[depth].options); + } + + await optionsSave(options); + backend.onOptionsUpdated(source); +} + function apiOptionsGetFull() { return utilBackend().getFullOptions(); } diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js index 7192d026..71393467 100644 --- a/ext/bg/js/backend.js +++ b/ext/bg/js/backend.js @@ -177,6 +177,7 @@ class Backend { Backend.messageHandlers = { optionsGet: ({optionsContext}) => apiOptionsGet(optionsContext), + optionsSet: ({changedOptions, optionsContext, source}) => apiOptionsSet(changedOptions, optionsContext, source), kanjiFind: ({text, optionsContext}) => apiKanjiFind(text, optionsContext), termsFind: ({text, optionsContext}) => apiTermsFind(text, optionsContext), definitionAdd: ({definition, mode, context, optionsContext}) => apiDefinitionAdd(definition, mode, context, optionsContext), diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js index 4854cd65..be1ccfbb 100644 --- a/ext/bg/js/options.js +++ b/ext/bg/js/options.js @@ -279,7 +279,9 @@ function profileOptionsCreateDefaults() { popupTheme: 'default', popupOuterTheme: 'default', customPopupCss: '', - customPopupOuterCss: '' + customPopupOuterCss: '', + enableWanakana: true, + enableClipboardMonitor: false }, audio: { diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js index dca4e8fa..65cca002 100644 --- a/ext/bg/js/search.js +++ b/ext/bg/js/search.js @@ -62,17 +62,22 @@ class DisplaySearch extends Display { this.query.addEventListener('input', () => this.onSearchInput(), false); if (this.wanakanaEnable !== null) { - if (this.wanakanaEnable.checked) { + if (this.options.general.enableWanakana === true) { + this.wanakanaEnable.checked = true; window.wanakana.bind(this.query); + } else { + this.wanakanaEnable.checked = false; } this.wanakanaEnable.addEventListener('change', (e) => { let query = DisplaySearch.getSearchQueryFromLocation(window.location.href); if (e.target.checked) { window.wanakana.bind(this.query); this.query.value = window.wanakana.toKana(query); + apiOptionsSet({general: {enableWanakana: true}}, this.getOptionsContext()); } else { window.wanakana.unbind(this.query); this.query.value = query; + apiOptionsSet({general: {enableWanakana: false}}, this.getOptionsContext()); } this.onSearchQueryUpdated(this.query.value, false); }); @@ -89,6 +94,12 @@ class DisplaySearch extends Display { } } if (this.clipboardMonitorEnable !== null) { + if (this.options.general.enableClipboardMonitor === true) { + this.clipboardMonitorEnable.checked = true; + this.startClipboardMonitor(); + } else { + this.clipboardMonitorEnable.checked = false; + } this.clipboardMonitorEnable.addEventListener('change', (e) => { if (e.target.checked) { chrome.permissions.request( @@ -96,6 +107,7 @@ class DisplaySearch extends Display { (granted) => { if (granted) { this.startClipboardMonitor(); + apiOptionsSet({general: {enableClipboardMonitor: true}}, this.getOptionsContext()); } else { e.target.checked = false; } @@ -103,6 +115,7 @@ class DisplaySearch extends Display { ); } else { this.stopClipboardMonitor(); + apiOptionsSet({general: {enableClipboardMonitor: false}}, this.getOptionsContext()); } }); } diff --git a/ext/bg/search.html b/ext/bg/search.html index 11dca5a2..8b339cc7 100644 --- a/ext/bg/search.html +++ b/ext/bg/search.html @@ -22,7 +22,7 @@
- + diff --git a/ext/fg/js/api.js b/ext/fg/js/api.js index bbc9b5fc..54818702 100644 --- a/ext/fg/js/api.js +++ b/ext/fg/js/api.js @@ -21,6 +21,10 @@ function apiOptionsGet(optionsContext) { return utilInvoke('optionsGet', {optionsContext}); } +function apiOptionsSet(changedOptions, optionsContext, source) { + return utilInvoke('optionsSet', {changedOptions, optionsContext, source}); +} + function apiTermsFind(text, optionsContext) { return utilInvoke('termsFind', {text, optionsContext}); } -- cgit v1.2.3 From f6d3f739a85367058a45581c7d7e4f9fffcca776 Mon Sep 17 00:00:00 2001 From: siikamiika Date: Mon, 28 Oct 2019 01:13:05 +0200 Subject: improve search page checkbox usability Disable text selection and make the entire area clickable, including whitespace --- ext/bg/search.html | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'ext/bg/search.html') diff --git a/ext/bg/search.html b/ext/bg/search.html index 8b339cc7..9853ee5e 100644 --- a/ext/bg/search.html +++ b/ext/bg/search.html @@ -19,14 +19,18 @@

Search your installed dictionaries by entering a Japanese expression into the field below.

-
+
- - + - - +
-- cgit v1.2.3 From 7de24dd355f0ab27e43509929d66c60e07e7eee4 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 2 Nov 2019 10:10:03 -0400 Subject: Add favicons --- ext/bg/background.html | 7 +++++++ ext/bg/context.html | 6 ++++++ ext/bg/guide.html | 6 ++++++ ext/bg/legal.html | 6 ++++++ ext/bg/search.html | 6 ++++++ ext/bg/settings-popup-preview.html | 6 ++++++ ext/bg/settings.html | 6 ++++++ ext/fg/float.html | 6 ++++++ 8 files changed, 49 insertions(+) (limited to 'ext/bg/search.html') diff --git a/ext/bg/background.html b/ext/bg/background.html index 30b3db48..3ab68639 100644 --- a/ext/bg/background.html +++ b/ext/bg/background.html @@ -3,6 +3,13 @@ + Background + + + + + +
diff --git a/ext/bg/context.html b/ext/bg/context.html index 48fa463f..7e08dddd 100644 --- a/ext/bg/context.html +++ b/ext/bg/context.html @@ -3,6 +3,12 @@ + + + + + + diff --git a/ext/bg/guide.html b/ext/bg/guide.html index 2a602f1f..ff9c71ee 100644 --- a/ext/bg/guide.html +++ b/ext/bg/guide.html @@ -4,6 +4,12 @@ Welcome to Yomichan! + + + + + + diff --git a/ext/bg/legal.html b/ext/bg/legal.html index 26ac033d..30927da6 100644 --- a/ext/bg/legal.html +++ b/ext/bg/legal.html @@ -4,6 +4,12 @@ Yomichan Legal + + + + + + diff --git a/ext/bg/search.html b/ext/bg/search.html index 9853ee5e..91140b95 100644 --- a/ext/bg/search.html +++ b/ext/bg/search.html @@ -4,6 +4,12 @@ Yomichan Search + + + + + + diff --git a/ext/bg/settings-popup-preview.html b/ext/bg/settings-popup-preview.html index 07caa271..d27a9a33 100644 --- a/ext/bg/settings-popup-preview.html +++ b/ext/bg/settings-popup-preview.html @@ -4,6 +4,12 @@ Yomichan Popup Preview + + + + + +