From 26ea278c29dbb19d003dddda2e60559c502d0cc3 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Tue, 21 Jan 2020 19:08:56 -0500 Subject: Improve debug logging --- ext/bg/js/settings/anki.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'ext/bg/js/settings') diff --git a/ext/bg/js/settings/anki.js b/ext/bg/js/settings/anki.js index 5f7989b8..9adb2f2a 100644 --- a/ext/bg/js/settings/anki.js +++ b/ext/bg/js/settings/anki.js @@ -37,13 +37,35 @@ function _ankiSetError(error) { if (error) { node.hidden = false; node.textContent = `${error}`; - } - else { + _ankiSetErrorData(node, error); + } else { node.hidden = true; node.textContent = ''; } } +function _ankiSetErrorData(node, error) { + const data = error.data; + let message = ''; + if (typeof data !== 'undefined') { + message += `${JSON.stringify(data, null, 4)}\n\n`; + } + message += `${error.stack}`.trimRight(); + + const button = document.createElement('a'); + button.className = 'error-data-show-button'; + + const content = document.createElement('div'); + content.className = 'error-data-container'; + content.textContent = message; + content.hidden = true; + + button.addEventListener('click', () => content.hidden = !content.hidden, false); + + node.appendChild(button); + node.appendChild(content); +} + function _ankiSetDropdownOptions(dropdown, optionValues) { const fragment = document.createDocumentFragment(); for (const optionValue of optionValues) { -- cgit v1.2.3 From f725549330e851ededad3c97c4517f8a23168e4a Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Mon, 23 Dec 2019 14:09:41 -0500 Subject: Remove redundant window resize handler --- ext/bg/js/settings/popup-preview-frame.js | 12 +----------- ext/fg/js/frontend.js | 7 ++++--- 2 files changed, 5 insertions(+), 14 deletions(-) (limited to 'ext/bg/js/settings') diff --git a/ext/bg/js/settings/popup-preview-frame.js b/ext/bg/js/settings/popup-preview-frame.js index 2b727cbd..54f246e3 100644 --- a/ext/bg/js/settings/popup-preview-frame.js +++ b/ext/bg/js/settings/popup-preview-frame.js @@ -35,7 +35,6 @@ class SettingsPopupPreview { async prepare() { // Setup events - window.addEventListener('resize', (e) => this.onWindowResize(e), false); window.addEventListener('message', (e) => this.onMessage(e), false); const themeDarkCheckbox = document.querySelector('#theme-dark-checkbox'); @@ -96,16 +95,6 @@ class SettingsPopupPreview { return result; } - onWindowResize() { - if (this.frontend === null) { return; } - const textSource = this.textSource; - if (textSource === null) { return; } - - const elementRect = textSource.getRect(); - const writingMode = textSource.getWritingMode(); - this.frontend.popup.showContent(elementRect, writingMode); - } - onMessage(e) { const {action, params} = e.data; const handler = SettingsPopupPreview._messageHandlers.get(action); @@ -163,6 +152,7 @@ class SettingsPopupPreview { try { await this.frontend.onSearchSource(source, 'script'); + this.frontend.setCurrentTextSource(source); } finally { source.cleanup(); } diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js index 2543b52c..85f1f373 100644 --- a/ext/fg/js/frontend.js +++ b/ext/fg/js/frontend.js @@ -42,6 +42,8 @@ class Frontend extends TextScanner { try { await this.updateOptions(); + window.addEventListener('resize', this.onResize.bind(this), false); + yomichan.on('orphaned', () => this.onOrphaned()); yomichan.on('optionsUpdate', () => this.updateOptions()); chrome.runtime.onMessage.addListener(this.onRuntimeMessage.bind(this)); @@ -51,7 +53,7 @@ class Frontend extends TextScanner { } async onResize() { - const textSource = this.textSourceCurrent; + const textSource = this.getCurrentTextSource(); if (textSource !== null && await this.popup.isVisible()) { this._showPopupContent(textSource); } @@ -81,8 +83,7 @@ class Frontend extends TextScanner { getMouseEventListeners() { return [ ...super.getMouseEventListeners(), - [window, 'message', this.onWindowMessage.bind(this)], - [window, 'resize', this.onResize.bind(this)] + [window, 'message', this.onWindowMessage.bind(this)] ]; } -- cgit v1.2.3 From 351598a1829930a25a27a007fb3bc69bde251787 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Mon, 23 Dec 2019 17:39:00 -0500 Subject: Add settings to control popup content scale --- ext/bg/js/options.js | 2 ++ ext/bg/js/settings/main.js | 4 ++++ ext/bg/settings.html | 16 ++++++++++++++++ ext/fg/js/frontend.js | 4 +++- 4 files changed, 25 insertions(+), 1 deletion(-) (limited to 'ext/bg/js/settings') diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js index 8021672b..cf9af240 100644 --- a/ext/bg/js/options.js +++ b/ext/bg/js/options.js @@ -279,6 +279,8 @@ function profileOptionsCreateDefaults() { popupVerticalOffset2: 0, popupHorizontalTextPosition: 'below', popupVerticalTextPosition: 'before', + popupScalingFactor: 1, + popupScaleRelativeToPageZoom: false, showGuide: true, compactTags: false, compactGlossaries: false, diff --git a/ext/bg/js/settings/main.js b/ext/bg/js/settings/main.js index 56828a15..a5407b75 100644 --- a/ext/bg/js/settings/main.js +++ b/ext/bg/js/settings/main.js @@ -44,6 +44,8 @@ async function formRead(options) { options.general.popupVerticalOffset = parseInt($('#popup-vertical-offset').val(), 10); options.general.popupHorizontalOffset2 = parseInt($('#popup-horizontal-offset2').val(), 0); options.general.popupVerticalOffset2 = parseInt($('#popup-vertical-offset2').val(), 10); + options.general.popupScalingFactor = parseInt($('#popup-scaling-factor').val(), 10); + options.general.popupScaleRelativeToPageZoom = $('#popup-scale-relative-to-page-zoom').val() === 'true'; options.general.popupTheme = $('#popup-theme').val(); options.general.popupOuterTheme = $('#popup-outer-theme').val(); options.general.customPopupCss = $('#custom-popup-css').val(); @@ -109,6 +111,8 @@ async function formWrite(options) { $('#popup-vertical-offset').val(options.general.popupVerticalOffset); $('#popup-horizontal-offset2').val(options.general.popupHorizontalOffset2); $('#popup-vertical-offset2').val(options.general.popupVerticalOffset2); + $('#popup-scaling-factor').val(options.general.popupScalingFactor); + $('#popup-scale-relative-to-page-zoom').val(options.general.popupScaleRelativeToPageZoom ? 'true' : 'false'); $('#popup-theme').val(options.general.popupTheme); $('#popup-outer-theme').val(options.general.popupOuterTheme); $('#custom-popup-css').val(options.general.customPopupCss); diff --git a/ext/bg/settings.html b/ext/bg/settings.html index 4c973674..37ee20aa 100644 --- a/ext/bg/settings.html +++ b/ext/bg/settings.html @@ -237,6 +237,22 @@ +
+
+
+ + +
+
+ + +
+
+
+
diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js index 52e3a5bc..d2fe9e76 100644 --- a/ext/fg/js/frontend.js +++ b/ext/fg/js/frontend.js @@ -196,7 +196,9 @@ class Frontend extends TextScanner { } _updateContentScale() { - const contentScale = 1.0 / this._pageZoomFactor; // TODO : Use options + const {popupScalingFactor, popupScaleRelativeToPageZoom} = this.options.general; + let contentScale = popupScalingFactor; + if (popupScaleRelativeToPageZoom) { contentScale /= this._pageZoomFactor; } if (contentScale === this._contentScale) { return; } this._contentScale = contentScale; -- cgit v1.2.3 From 5d366b722f4104d4f3252fb733fa31a44d4df3df Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Mon, 30 Dec 2019 12:42:12 -0500 Subject: Add option for changing poup scale relative to visual viewport --- ext/bg/data/options-schema.json | 5 +++++ ext/bg/js/options.js | 1 + ext/bg/js/settings/main.js | 6 ++++-- ext/bg/settings.html | 29 +++++++++++++---------------- 4 files changed, 23 insertions(+), 18 deletions(-) (limited to 'ext/bg/js/settings') diff --git a/ext/bg/data/options-schema.json b/ext/bg/data/options-schema.json index 27de2bf9..3cb25218 100644 --- a/ext/bg/data/options-schema.json +++ b/ext/bg/data/options-schema.json @@ -93,6 +93,7 @@ "popupVerticalTextPosition", "popupScalingFactor", "popupScaleRelativeToPageZoom", + "popupScaleRelativeToVisualViewport", "showGuide", "compactTags", "compactGlossaries", @@ -176,6 +177,10 @@ "type": "boolean", "default": false }, + "popupScaleRelativeToVisualViewport": { + "type": "boolean", + "default": true + }, "showGuide": { "type": "boolean", "default": true diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js index cf9af240..c2da76b1 100644 --- a/ext/bg/js/options.js +++ b/ext/bg/js/options.js @@ -281,6 +281,7 @@ function profileOptionsCreateDefaults() { popupVerticalTextPosition: 'before', popupScalingFactor: 1, popupScaleRelativeToPageZoom: false, + popupScaleRelativeToVisualViewport: true, showGuide: true, compactTags: false, compactGlossaries: false, diff --git a/ext/bg/js/settings/main.js b/ext/bg/js/settings/main.js index a5407b75..ac255978 100644 --- a/ext/bg/js/settings/main.js +++ b/ext/bg/js/settings/main.js @@ -45,7 +45,8 @@ async function formRead(options) { options.general.popupHorizontalOffset2 = parseInt($('#popup-horizontal-offset2').val(), 0); options.general.popupVerticalOffset2 = parseInt($('#popup-vertical-offset2').val(), 10); options.general.popupScalingFactor = parseInt($('#popup-scaling-factor').val(), 10); - options.general.popupScaleRelativeToPageZoom = $('#popup-scale-relative-to-page-zoom').val() === 'true'; + options.general.popupScaleRelativeToPageZoom = $('#popup-scale-relative-to-page-zoom').prop('checked'); + options.general.popupScaleRelativeToVisualViewport = $('#popup-scale-relative-to-visual-viewport').prop('checked'); options.general.popupTheme = $('#popup-theme').val(); options.general.popupOuterTheme = $('#popup-outer-theme').val(); options.general.customPopupCss = $('#custom-popup-css').val(); @@ -112,7 +113,8 @@ async function formWrite(options) { $('#popup-horizontal-offset2').val(options.general.popupHorizontalOffset2); $('#popup-vertical-offset2').val(options.general.popupVerticalOffset2); $('#popup-scaling-factor').val(options.general.popupScalingFactor); - $('#popup-scale-relative-to-page-zoom').val(options.general.popupScaleRelativeToPageZoom ? 'true' : 'false'); + $('#popup-scale-relative-to-page-zoom').prop('checked', options.general.popupScaleRelativeToPageZoom); + $('#popup-scale-relative-to-visual-viewport').prop('checked', options.general.popupScaleRelativeToVisualViewport); $('#popup-theme').val(options.general.popupTheme); $('#popup-outer-theme').val(options.general.popupOuterTheme); $('#custom-popup-css').val(options.general.customPopupCss); diff --git a/ext/bg/settings.html b/ext/bg/settings.html index 37ee20aa..a283335c 100644 --- a/ext/bg/settings.html +++ b/ext/bg/settings.html @@ -150,6 +150,14 @@
+
+ +
+ +
+ +
+
@@ -171,6 +179,11 @@
+
+ + +
+
@@ -237,22 +250,6 @@
-
-
-
- - -
-
- - -
-
-
-
-- cgit v1.2.3 From fa4004437d8ca5aff34c31f61ce8aea485be24d1 Mon Sep 17 00:00:00 2001 From: siikamiika Date: Sat, 25 Jan 2020 02:57:57 +0200 Subject: query parser: add toggle for term spacing --- ext/bg/data/options-schema.json | 5 +++++ ext/bg/js/search-query-parser.js | 5 +++++ ext/bg/js/settings/main.js | 1 + ext/bg/settings.html | 4 ++++ ext/mixed/css/display.css | 2 +- 5 files changed, 16 insertions(+), 1 deletion(-) (limited to 'ext/bg/js/settings') diff --git a/ext/bg/data/options-schema.json b/ext/bg/data/options-schema.json index 224b93f8..d4bd3c21 100644 --- a/ext/bg/data/options-schema.json +++ b/ext/bg/data/options-schema.json @@ -381,6 +381,7 @@ "enableScanningParser", "enableMecabParser", "selectedParser", + "termSpacing", "readingMode" ], "properties": { @@ -396,6 +397,10 @@ "type": ["string", "null"], "default": null }, + "termSpacing": { + "type": "boolean", + "default": true + }, "readingMode": { "type": "string", "enum": ["hiragana", "katakana", "romaji", "none"], diff --git a/ext/bg/js/search-query-parser.js b/ext/bg/js/search-query-parser.js index 8115dd46..e8e6d11f 100644 --- a/ext/bg/js/search-query-parser.js +++ b/ext/bg/js/search-query-parser.js @@ -88,6 +88,11 @@ class QueryParser extends TextScanner { ]; } + setOptions(options) { + super.setOptions(options); + this.queryParser.dataset.termSpacing = `${options.parsing.termSpacing}`; + } + refreshSelectedParser() { if (this.parseResults.length > 0) { if (this.selectedParser === null) { diff --git a/ext/bg/js/settings/main.js b/ext/bg/js/settings/main.js index ac255978..bed57f7d 100644 --- a/ext/bg/js/settings/main.js +++ b/ext/bg/js/settings/main.js @@ -74,6 +74,7 @@ async function formRead(options) { options.parsing.enableScanningParser = $('#parsing-scan-enable').prop('checked'); options.parsing.enableMecabParser = $('#parsing-mecab-enable').prop('checked'); + options.parsing.termSpacing = $('#parsing-term-spacing').prop('checked'); options.parsing.readingMode = $('#parsing-reading-mode').val(); const optionsAnkiEnableOld = options.anki.enable; diff --git a/ext/bg/settings.html b/ext/bg/settings.html index 4b73e02c..f73f79c8 100644 --- a/ext/bg/settings.html +++ b/ext/bg/settings.html @@ -451,6 +451,10 @@
+
+ +
+
+ + + + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+
+