From 7f643b814038104d41eaeac3f012f179dd240c1a Mon Sep 17 00:00:00 2001 From: Jason Ojisan Date: Fri, 5 Jul 2024 22:55:43 +0300 Subject: [PATCH 1/9] add a toggle for sticky header --- ext/css/display.css | 11 +++++++++-- ext/data/schemas/options-schema.json | 7 ++++++- ext/js/data/options-util.js | 1 + ext/js/display/display.js | 12 ++++++++++++ ext/js/display/search-display-controller.js | 9 +++++++++ ext/search.html | 2 +- ext/settings.html | 9 +++++++++ types/ext/settings.d.ts | 1 + 8 files changed, 48 insertions(+), 4 deletions(-) diff --git a/ext/css/display.css b/ext/css/display.css index 4eef597a10..540a5f22e8 100644 --- a/ext/css/display.css +++ b/ext/css/display.css @@ -577,6 +577,7 @@ button.sidebar-button.sidebar-button-highlight { /* Search page */ .search-header-wrapper { + background-color: var(--background-color); width: 100%; display: flex; justify-content: center; @@ -595,7 +596,6 @@ button.sidebar-button.sidebar-button-highlight { padding: var(--main-content-vertical-padding) var(--main-content-horizontal-padding); } #query-parser-container { - overflow-y: auto; padding-left: var(--entry-horizontal-padding); padding-right: var(--entry-horizontal-padding); padding-bottom: 0.25em; @@ -605,12 +605,19 @@ button.sidebar-button.sidebar-button-highlight { margin-top: 0.5em; font-size: var(--query-parser-font-size); white-space: pre-wrap; - max-height: calc(var(--query-parser-font-size) * 2); } #query-parser-content[data-term-spacing=true] .query-parser-term { margin-right: 0.2em; } +.sticky-header { + #query-parser-container { + overflow-y: auto; + } + #query-parser-content { + max-height: calc(var(--query-parser-font-size) * 2); + } +} /* Action buttons */ .actions { diff --git a/ext/data/schemas/options-schema.json b/ext/data/schemas/options-schema.json index 8873b935c1..efff88f89b 100644 --- a/ext/data/schemas/options-schema.json +++ b/ext/data/schemas/options-schema.json @@ -319,7 +319,8 @@ "useLeft", "useTop", "windowType", - "windowState" + "windowState", + "searchStickyHeader" ], "properties": { "width": { @@ -357,6 +358,10 @@ "type": "string", "enum": ["normal", "maximized", "fullscreen"], "default": "normal" + }, + "searchStickyHeader": { + "type": "boolean", + "default": true } } }, diff --git a/ext/js/data/options-util.js b/ext/js/data/options-util.js index e43b43cf6c..80cc1f49f6 100644 --- a/ext/js/data/options-util.js +++ b/ext/js/data/options-util.js @@ -835,6 +835,7 @@ export class OptionsUtil { useTop: false, windowType: 'popup', windowState: 'normal', + searchStickyHeader: true, }; profile.options.audio.customSourceType = 'audio'; profile.options.clipboard = { diff --git a/ext/js/display/display.js b/ext/js/display/display.js index b54eea2f86..3b259b0001 100644 --- a/ext/js/display/display.js +++ b/ext/js/display/display.js @@ -426,6 +426,18 @@ export class Display extends EventDispatcher { await this.updateOptions(); } + /** + * @throws {Error} + * @returns {boolean} + */ + searchStickyHeader() { + if (this._options) { + return Boolean(this._options.popupWindow.searchStickyHeader); + } else { + throw new Error('options should be initialized.'); + } + } + /** */ async updateOptions() { const options = await this._application.api.optionsGet(this.getOptionsContext()); diff --git a/ext/js/display/search-display-controller.js b/ext/js/display/search-display-controller.js index a25b90347a..572ae9910a 100644 --- a/ext/js/display/search-display-controller.js +++ b/ext/js/display/search-display-controller.js @@ -20,6 +20,7 @@ import * as wanakana from '../../lib/wanakana.js'; import {ClipboardMonitor} from '../comm/clipboard-monitor.js'; import {createApiMap, invokeApiMapHandler} from '../core/api-map.js'; import {EventListenerCollection} from '../core/event-listener-collection.js'; +import {log} from '../core/log.js'; import {querySelectorNotNull} from '../dom/query-selector.js'; export class SearchDisplayController { @@ -113,6 +114,14 @@ export class SearchDisplayController { if (displayOptions !== null) { await this._onDisplayOptionsUpdated({options: displayOptions}); } + + try { + if (this._display.searchStickyHeader()) { + querySelectorNotNull(document, '#sticky_header').classList.add('sticky-header'); + } + } catch (e) { + log.error(e); + } } /** diff --git a/ext/search.html b/ext/search.html index 071f2f9031..b47d68467a 100644 --- a/ext/search.html +++ b/ext/search.html @@ -55,7 +55,7 @@

Rikaitan Search

- +
+
+
Sticky search header
+
Search header sticks to the top of the window.
+
+
+ +
+
diff --git a/types/ext/settings.d.ts b/types/ext/settings.d.ts index 52a635aa6b..eae41f8583 100644 --- a/types/ext/settings.d.ts +++ b/types/ext/settings.d.ts @@ -153,6 +153,7 @@ export type PopupWindowOptions = { useTop: boolean; windowType: PopupWindowType; windowState: PopupWindowState; + searchStickyHeader: boolean; }; export type AudioOptions = { From d092f8b8148ee90de21db4dafc50bc8a61927873 Mon Sep 17 00:00:00 2001 From: Jason Ojisan Date: Fri, 5 Jul 2024 23:05:44 +0300 Subject: [PATCH 2/9] fix test --- docs/audio.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/audio.md b/docs/audio.md index a137caa5bb..c419d455e0 100644 --- a/docs/audio.md +++ b/docs/audio.md @@ -30,7 +30,7 @@ To enable this, just add a new playback source with the `Text-to-speech` type an - TTS voices vary between browsers and so might not support all languages. For instance, [Microsoft Edge](https://www.microsoft.com/en-us/edge) offers a wide selection of free Azure natural voices for a variety of languages. Edge provides over 300 voices, compared to around 25 in Google Chrome (see [here](https://learn.microsoft.com/en-us/azure/ai-services/speech-service/language-support?tabs=stt) for a list of supported languages). - TTS audio can be inaccurate for languages with complex pronunciation such as Japanese, where words can have multiple possible readings and pitch accents. -- ⚠️ Note that the TTS voices cannot be sent to Anki; this is a [limitation of the browser SpeechSynthesis API](https://github.com/Ajatt-Tools/rikaitan/issues/864). +- ⚠️ Note that the TTS voices cannot be sent to Anki; this is a limitation of the browser SpeechSynthesis API. ### Custom URL From 2796d24f2df5cb6e0c4ed422beeb70036806b29b Mon Sep 17 00:00:00 2001 From: Jason Ojisan Date: Fri, 5 Jul 2024 23:36:01 +0300 Subject: [PATCH 3/9] fix test --- .eslintignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.eslintignore b/.eslintignore index 572c354a4e..5358ca71f5 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,2 +1,3 @@ node_modules/ -builds/ \ No newline at end of file +builds/ +manifest-variants.v2.json From 6b5b2af9f0a60cc48aabdddc0e67373d11345aad Mon Sep 17 00:00:00 2001 From: Jason Ojisan Date: Fri, 5 Jul 2024 23:42:39 +0300 Subject: [PATCH 4/9] fix test --- test/data/json.json | 1 + test/options-util.test.js | 1 + 2 files changed, 2 insertions(+) diff --git a/test/data/json.json b/test/data/json.json index f5b632e1c7..217a95ce83 100644 --- a/test/data/json.json +++ b/test/data/json.json @@ -27,6 +27,7 @@ {"path": "test/data/vitest.options.config.json", "ignore": true}, {"path": "test/data/vitest.json.config.json", "ignore": true}, {"path": "benches/jsconfig.json", "ignore": true}, + {"path": "dev/data/manifest-variants.v2.json", "ignore": true}, { "path": "dev/data/manifest-variants.json", diff --git a/test/options-util.test.js b/test/options-util.test.js index 9c739fd12d..353fbefd39 100644 --- a/test/options-util.test.js +++ b/test/options-util.test.js @@ -509,6 +509,7 @@ function createProfileOptionsUpdatedTestData1() { useTop: false, windowType: 'popup', windowState: 'normal', + searchStickyHeader: true, }, clipboard: { enableBackgroundMonitor: false, From e6482b10a46dfdd6911155ffd854ae6f5d893147 Mon Sep 17 00:00:00 2001 From: Jason Ojisan Date: Sat, 6 Jul 2024 01:00:52 +0300 Subject: [PATCH 5/9] fix test --- ext/js/pages/action-popup-main.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ext/js/pages/action-popup-main.js b/ext/js/pages/action-popup-main.js index 6965da3ad7..bbe02ce0ed 100644 --- a/ext/js/pages/action-popup-main.js +++ b/ext/js/pages/action-popup-main.js @@ -19,6 +19,7 @@ import {ThemeController} from '../app/theme-controller.js'; import {Application} from '../application.js'; import {getAllPermissions, hasRequiredPermissionsForOptions} from '../data/permissions-util.js'; +import { querySelectorNotNull } from '../dom/query-selector.js'; import {HotkeyHelpController} from '../input/hotkey-help-controller.js'; class DisplayController { @@ -74,7 +75,7 @@ class DisplayController { // Show Rikaitan version. // replace version number () - document.querySelector('#version').textContent = `v${manifest.version}`; + querySelectorNotNull(document, "#version").textContent = `v${manifest.version}`; this._updateProfileSelect(profiles, profileCurrent); From 7278e994bcbbfbc0aa5362ec50604e19bd2f9702 Mon Sep 17 00:00:00 2001 From: Jason Ojisan Date: Sat, 6 Jul 2024 01:18:59 +0300 Subject: [PATCH 6/9] fix format --- ext/js/pages/action-popup-main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/js/pages/action-popup-main.js b/ext/js/pages/action-popup-main.js index bbe02ce0ed..9f9bb2d9bb 100644 --- a/ext/js/pages/action-popup-main.js +++ b/ext/js/pages/action-popup-main.js @@ -19,7 +19,7 @@ import {ThemeController} from '../app/theme-controller.js'; import {Application} from '../application.js'; import {getAllPermissions, hasRequiredPermissionsForOptions} from '../data/permissions-util.js'; -import { querySelectorNotNull } from '../dom/query-selector.js'; +import {querySelectorNotNull} from '../dom/query-selector.js'; import {HotkeyHelpController} from '../input/hotkey-help-controller.js'; class DisplayController { @@ -75,7 +75,7 @@ class DisplayController { // Show Rikaitan version. // replace version number () - querySelectorNotNull(document, "#version").textContent = `v${manifest.version}`; + querySelectorNotNull(document, '#version').textContent = `v${manifest.version}`; this._updateProfileSelect(profiles, profileCurrent); From dd23483d42ad1fec75552543d2ef6083765a8c1a Mon Sep 17 00:00:00 2001 From: Jason Ojisan Date: Sat, 6 Jul 2024 02:02:53 +0300 Subject: [PATCH 7/9] fix test --- ext/css/action-popup.css | 2 +- ext/css/display.css | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/css/action-popup.css b/ext/css/action-popup.css index 389270d158..78f678af19 100644 --- a/ext/css/action-popup.css +++ b/ext/css/action-popup.css @@ -503,7 +503,7 @@ select.profile-select { /* Small text inside the popup that reports the current version */ .popup-version { font-size: 10px; - color: gray; + color: #616161; } /* Mobile overrides */ diff --git a/ext/css/display.css b/ext/css/display.css index 540a5f22e8..288bb26f03 100644 --- a/ext/css/display.css +++ b/ext/css/display.css @@ -611,7 +611,7 @@ button.sidebar-button.sidebar-button-highlight { } .sticky-header { - #query-parser-container { + #query-parser-container { overflow-y: auto; } #query-parser-content { From ffb4461526674aed5914634dc99a6a427ebb24c4 Mon Sep 17 00:00:00 2001 From: Jason Ojisan Date: Sat, 6 Jul 2024 02:32:13 +0300 Subject: [PATCH 8/9] react to config change --- ext/js/display/display.js | 2 +- ext/js/display/search-display-controller.js | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/ext/js/display/display.js b/ext/js/display/display.js index 3b259b0001..d58db7277d 100644 --- a/ext/js/display/display.js +++ b/ext/js/display/display.js @@ -430,7 +430,7 @@ export class Display extends EventDispatcher { * @throws {Error} * @returns {boolean} */ - searchStickyHeader() { + isSearchStickyHeaderEnabled() { if (this._options) { return Boolean(this._options.popupWindow.searchStickyHeader); } else { diff --git a/ext/js/display/search-display-controller.js b/ext/js/display/search-display-controller.js index 572ae9910a..83b74fc133 100644 --- a/ext/js/display/search-display-controller.js +++ b/ext/js/display/search-display-controller.js @@ -115,10 +115,15 @@ export class SearchDisplayController { await this._onDisplayOptionsUpdated({options: displayOptions}); } + this.setStickyHeaderState(); + } + + /** + * + */ + setStickyHeaderState() { try { - if (this._display.searchStickyHeader()) { - querySelectorNotNull(document, '#sticky_header').classList.add('sticky-header'); - } + querySelectorNotNull(document, '#sticky_header').classList.toggle('sticky-header', this._display.isSearchStickyHeaderEnabled()); } catch (e) { log.error(e); } @@ -183,6 +188,7 @@ export class SearchDisplayController { if (query) { this._display.searchLast(false); } + this.setStickyHeaderState(); } /** From 275f0dd4ac4ef9c76c1c6b35a81d4d95f74d5410 Mon Sep 17 00:00:00 2001 From: Jason Ojisan Date: Sat, 6 Jul 2024 02:38:19 +0300 Subject: [PATCH 9/9] fix format --- docs/anki-integration.md | 4 ++-- docs/dictionaries.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/anki-integration.md b/docs/anki-integration.md index 150e422031..28da41c881 100644 --- a/docs/anki-integration.md +++ b/docs/anki-integration.md @@ -33,7 +33,7 @@ Flashcard fields can be configured with the following steps: | `{audio}` | Audio of the term's pronunciation from one of the audio sources (if available). | | `{clipboard-image}` | An image which is stored in the system clipboard, if present. | | `{clipboard-text}` | Text which is stored in the system clipboard, if present. | - | `{cloze-body}` | Raw, inflected term as it appeared before being reduced to dictionary form by Rikaitan. | + | `{cloze-body}` | Raw, inflected term as it appeared before being reduced to dictionary form by Rikaitan. | | `{cloze-body-kana}` | Kana reading for `{cloze-body}`. | | `{cloze-prefix}` | Fragment of the containing `{sentence}` starting at the beginning of `{sentence}` until the beginning of `{cloze-body}`. | | `{cloze-suffix}` | Fragment of the containing `{sentence}` starting at the end of `{cloze-body}` until the end of `{sentence}`. | @@ -80,7 +80,7 @@ Flashcard fields can be configured with the following steps: | `{character}` | Unicode glyph representing the current kanji. | | `{clipboard-image}` | An image which is stored in the system clipboard, if present. | | `{clipboard-text}` | Text which is stored in the system clipboard, if present. | - | `{cloze-body}` | Raw, inflected parent term as it appeared before being reduced to dictionary form by Rikaitan. | + | `{cloze-body}` | Raw, inflected parent term as it appeared before being reduced to dictionary form by Rikaitan. | | `{cloze-prefix}` | Fragment of the containing `{sentence}` starting at the beginning of `{sentence}` until the beginning of `{cloze-body}`. | | `{cloze-suffix}` | Fragment of the containing `{sentence}` starting at the end of `{cloze-body}` until the end of `{sentence}`. | | `{dictionary}` | Name of the dictionary from which the card is being created. | diff --git a/docs/dictionaries.md b/docs/dictionaries.md index d1dacc5813..dbb331d100 100644 --- a/docs/dictionaries.md +++ b/docs/dictionaries.md @@ -12,8 +12,8 @@ you may consider also importing the English version for better coverage. ### Recommended Dictionaries -* [Our recommended dictionaries](https://tatsumoto.neocities.org/blog/yomichan-and-epwing-dictionaries#rikaitan) -* [Other dictionaries](https://github.com/Ajatt-Tools/rikaitan/tree/dictionaries) +- [Our recommended dictionaries](https://tatsumoto.neocities.org/blog/yomichan-and-epwing-dictionaries#rikaitan) +- [Other dictionaries](https://github.com/Ajatt-Tools/rikaitan/tree/dictionaries) ### Japanese beginner dictionaries