From 01f611d1898f046de2f367e8fe0ec6692ca7e445 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 10 Feb 2019 20:44:16 -0500 Subject: Add support for touch input --- ext/bg/js/options.js | 1 + ext/bg/js/settings.js | 2 ++ ext/bg/settings.html | 4 ++++ 3 files changed, 7 insertions(+) (limited to 'ext/bg') diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js index 373a1a6b..f5f0bca7 100644 --- a/ext/bg/js/options.js +++ b/ext/bg/js/options.js @@ -201,6 +201,7 @@ function optionsSetDefaults(options) { scanning: { middleMouse: true, + touchInputEnabled: true, selectText: true, alphanumeric: true, autoHideResults: false, diff --git a/ext/bg/js/settings.js b/ext/bg/js/settings.js index 7bc6a651..9da869c7 100644 --- a/ext/bg/js/settings.js +++ b/ext/bg/js/settings.js @@ -36,6 +36,7 @@ async function formRead() { optionsNew.general.popupOffset = parseInt($('#popup-offset').val(), 10); optionsNew.scanning.middleMouse = $('#middle-mouse-button-scan').prop('checked'); + optionsNew.scanning.touchInputEnabled = $('#touch-input-enabled').prop('checked'); optionsNew.scanning.selectText = $('#select-matched-text').prop('checked'); optionsNew.scanning.alphanumeric = $('#search-alphanumeric').prop('checked'); optionsNew.scanning.autoHideResults = $('#auto-hide-results').prop('checked'); @@ -166,6 +167,7 @@ async function onReady() { $('#popup-offset').val(options.general.popupOffset); $('#middle-mouse-button-scan').prop('checked', options.scanning.middleMouse); + $('#touch-input-enabled').prop('checked', options.scanning.touchInputEnabled); $('#select-matched-text').prop('checked', options.scanning.selectText); $('#search-alphanumeric').prop('checked', options.scanning.alphanumeric); $('#auto-hide-results').prop('checked', options.scanning.autoHideResults); diff --git a/ext/bg/settings.html b/ext/bg/settings.html index c77f550c..fe4c32b1 100644 --- a/ext/bg/settings.html +++ b/ext/bg/settings.html @@ -105,6 +105,10 @@ +
+ +
+
-- cgit v1.2.3 From ba972d8547089d8f2c8e19749ee0a0ab93d36233 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Thu, 14 Feb 2019 21:42:59 -0500 Subject: Add popup display mode Allows the popup to be stretched to the full width of the screen, anchored to the top or bottom of the window. --- ext/bg/js/options.js | 1 + ext/bg/js/settings.js | 2 ++ ext/bg/settings.html | 8 ++++++++ ext/fg/css/client.css | 22 ++++++++++++++++++++++ ext/fg/js/popup.js | 4 ++++ 5 files changed, 37 insertions(+) (limited to 'ext/bg') diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js index f5f0bca7..f1e02e18 100644 --- a/ext/bg/js/options.js +++ b/ext/bg/js/options.js @@ -190,6 +190,7 @@ function optionsSetDefaults(options) { debugInfo: false, maxResults: 32, showAdvanced: false, + popupDisplayMode: 'default', popupWidth: 400, popupHeight: 250, popupOffset: 10, diff --git a/ext/bg/js/settings.js b/ext/bg/js/settings.js index 9da869c7..4bf7181f 100644 --- a/ext/bg/js/settings.js +++ b/ext/bg/js/settings.js @@ -31,6 +31,7 @@ async function formRead() { optionsNew.general.debugInfo = $('#show-debug-info').prop('checked'); optionsNew.general.showAdvanced = $('#show-advanced-options').prop('checked'); optionsNew.general.maxResults = parseInt($('#max-displayed-results').val(), 10); + optionsNew.general.popupDisplayMode = $('#popup-display-mode').val(); optionsNew.general.popupWidth = parseInt($('#popup-width').val(), 10); optionsNew.general.popupHeight = parseInt($('#popup-height').val(), 10); optionsNew.general.popupOffset = parseInt($('#popup-offset').val(), 10); @@ -162,6 +163,7 @@ async function onReady() { $('#show-debug-info').prop('checked', options.general.debugInfo); $('#show-advanced-options').prop('checked', options.general.showAdvanced); $('#max-displayed-results').val(options.general.maxResults); + $('#popup-display-mode').val(options.general.popupDisplayMode); $('#popup-width').val(options.general.popupWidth); $('#popup-height').val(options.general.popupHeight); $('#popup-offset').val(options.general.popupOffset); diff --git a/ext/bg/settings.html b/ext/bg/settings.html index fe4c32b1..7f18a358 100644 --- a/ext/bg/settings.html +++ b/ext/bg/settings.html @@ -74,6 +74,14 @@ +
+ + +
+
diff --git a/ext/fg/css/client.css b/ext/fg/css/client.css index b5b1f6bd..a9b8e025 100644 --- a/ext/fg/css/client.css +++ b/ext/fg/css/client.css @@ -27,3 +27,25 @@ iframe#yomichan-float { visibility: hidden; z-index: 2147483647; } + +iframe#yomichan-float.yomichan-float-full-width { + border-left: none; + border-right: none; + left: 0 !important; + right: 0 !important; + width: 100% !important; + box-sizing: border-box; + resize: none; +} + +iframe#yomichan-float.yomichan-float-full-width:not(.yomichan-float-above) { + border-bottom: none; + top: auto !important; + bottom: 0 !important; +} + +iframe#yomichan-float.yomichan-float-full-width.yomichan-float-above { + border-top: none; + top: 0 !important; + bottom: auto !important; +} diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js index a17b184a..14276efe 100644 --- a/ext/fg/js/popup.js +++ b/ext/fg/js/popup.js @@ -62,6 +62,7 @@ class Popup { } } + let above = false; let y = 0; let height = Math.max(containerHeight, options.general.popupHeight); const yBelow = elementRect.bottom + options.general.popupOffset; @@ -75,11 +76,14 @@ class Popup { } else { height = Math.max(height - overflowAbove, 0); y = Math.max(yAbove - height, 0); + above = true; } } else { y = yBelow; } + this.container.classList.toggle('yomichan-float-full-width', options.general.popupDisplayMode === 'full-width'); + this.container.classList.toggle('yomichan-float-above', above); this.container.style.left = `${x}px`; this.container.style.top = `${y}px`; this.container.style.width = `${width}px`; -- cgit v1.2.3 From b58b91d3fce466457521b87dda850c8514c5e381 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 16 Feb 2019 22:34:00 -0500 Subject: Fix audio URLs --- ext/bg/js/audio.js | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'ext/bg') diff --git a/ext/bg/js/audio.js b/ext/bg/js/audio.js index 549288f5..c93b7550 100644 --- a/ext/bg/js/audio.js +++ b/ext/bg/js/audio.js @@ -69,10 +69,10 @@ async function audioBuildUrl(definition, mode, cache={}) { const dom = new DOMParser().parseFromString(response, 'text/html'); for (const row of dom.getElementsByClassName('dc-result-row')) { try { - const url = row.getElementsByClassName('ill-onebuttonplayer').item(0).getAttribute('data-url'); + const url = row.querySelector('audio>source[src]').getAttribute('src'); const reading = row.getElementsByClassName('dc-vocab_kana').item(0).innerText; if (url && reading && (!definition.reading || definition.reading === reading)) { - return url; + return normalizeAudioUrl(url, 'https://www.japanesepod101.com', '/learningcenter/reference/'); } } catch (e) { // NOP @@ -86,7 +86,7 @@ async function audioBuildUrl(definition, mode, cache={}) { resolve(response); } else { const xhr = new XMLHttpRequest(); - xhr.open('GET', `http://jisho.org/search/${definition.expression}`); + xhr.open('GET', `https://jisho.org/search/${definition.expression}`); xhr.addEventListener('error', () => reject('Failed to scrape audio data')); xhr.addEventListener('load', () => { cache[definition.expression] = xhr.responseText; @@ -100,7 +100,10 @@ async function audioBuildUrl(definition, mode, cache={}) { const dom = new DOMParser().parseFromString(response, 'text/html'); const audio = dom.getElementById(`audio_${definition.expression}:${definition.reading}`); if (audio) { - return audio.getElementsByTagName('source').item(0).getAttribute('src'); + const url = audio.getElementsByTagName('source').item(0).getAttribute('src'); + if (url) { + return normalizeAudioUrl(url, 'https://jisho.org', '/search/'); + } } } catch (e) { // NOP @@ -112,6 +115,24 @@ async function audioBuildUrl(definition, mode, cache={}) { } } +function normalizeAudioUrl(url, baseUrl, basePath) { + if (url) { + if (url[0] === '/') { + if (url.length >= 2 && url[1] === '/') { + // Begins with "//" + url = baseUrl.substr(0, baseUrl.indexOf(':') + 1) + url; + } else { + // Begins with "/" + url = baseUrl + url; + } + } else if (!/^[a-z][a-z0-9\+\-\.]*:/i.test(url)) { + // No URI scheme => relative path + url = baseUrl + basePath + url; + } + } + return url; +} + function audioBuildFilename(definition) { if (definition.reading || definition.expression) { let filename = 'yomichan'; -- cgit v1.2.3 From ee5e47251eb416952e0a4f8dfe923fe48565e64b Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Wed, 20 Feb 2019 21:16:40 -0500 Subject: Rename normalizeAudioUrl to audioUrlNormalize --- ext/bg/js/audio.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'ext/bg') diff --git a/ext/bg/js/audio.js b/ext/bg/js/audio.js index c93b7550..2e5db7cc 100644 --- a/ext/bg/js/audio.js +++ b/ext/bg/js/audio.js @@ -72,7 +72,7 @@ async function audioBuildUrl(definition, mode, cache={}) { const url = row.querySelector('audio>source[src]').getAttribute('src'); const reading = row.getElementsByClassName('dc-vocab_kana').item(0).innerText; if (url && reading && (!definition.reading || definition.reading === reading)) { - return normalizeAudioUrl(url, 'https://www.japanesepod101.com', '/learningcenter/reference/'); + return audioUrlNormalize(url, 'https://www.japanesepod101.com', '/learningcenter/reference/'); } } catch (e) { // NOP @@ -102,7 +102,7 @@ async function audioBuildUrl(definition, mode, cache={}) { if (audio) { const url = audio.getElementsByTagName('source').item(0).getAttribute('src'); if (url) { - return normalizeAudioUrl(url, 'https://jisho.org', '/search/'); + return audioUrlNormalize(url, 'https://jisho.org', '/search/'); } } } catch (e) { @@ -115,7 +115,7 @@ async function audioBuildUrl(definition, mode, cache={}) { } } -function normalizeAudioUrl(url, baseUrl, basePath) { +function audioUrlNormalize(url, baseUrl, basePath) { if (url) { if (url[0] === '/') { if (url.length >= 2 && url[1] === '/') { -- cgit v1.2.3