summaryrefslogtreecommitdiff
path: root/ext/bg
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2019-04-28 11:47:04 -0700
committerAlex Yatskov <alex@foosoft.net>2019-04-28 11:47:04 -0700
commit9b00daed07db8d70485f2fee22bb1a9b118aa186 (patch)
treec8c7e9f90d45be017e881abacdd2c328674bb506 /ext/bg
parent162f3c3836f83660cbb7f01cc724367216eab3e2 (diff)
parentc7f8d0874a758924802179a44757153bbf18bf7f (diff)
Merge branch 'master' of https://github.com/FooSoft/yomichan
Diffstat (limited to 'ext/bg')
-rw-r--r--ext/bg/js/audio.js29
-rw-r--r--ext/bg/js/options.js2
-rw-r--r--ext/bg/js/settings.js4
-rw-r--r--ext/bg/settings.html12
4 files changed, 43 insertions, 4 deletions
diff --git a/ext/bg/js/audio.js b/ext/bg/js/audio.js
index 549288f5..2e5db7cc 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 audioUrlNormalize(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 audioUrlNormalize(url, 'https://jisho.org', '/search/');
+ }
}
} catch (e) {
// NOP
@@ -112,6 +115,24 @@ async function audioBuildUrl(definition, mode, cache={}) {
}
}
+function audioUrlNormalize(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';
diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js
index 373a1a6b..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,
@@ -201,6 +202,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..4bf7181f 100644
--- a/ext/bg/js/settings.js
+++ b/ext/bg/js/settings.js
@@ -31,11 +31,13 @@ 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);
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');
@@ -161,11 +163,13 @@ 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);
$('#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..7f18a358 100644
--- a/ext/bg/settings.html
+++ b/ext/bg/settings.html
@@ -74,6 +74,14 @@
</select>
</div>
+ <div class="form-group">
+ <label for="popup-display-mode">Popup display mode</label>
+ <select class="form-control" id="popup-display-mode">
+ <option value="default">Default</option>
+ <option value="full-width">Full width</option>
+ </select>
+ </div>
+
<div class="form-group options-advanced">
<label for="audio-playback-volume">Audio playback volume (percent)</label>
<input type="number" min="0" max="100" id="audio-playback-volume" class="form-control">
@@ -106,6 +114,10 @@
</div>
<div class="checkbox">
+ <label><input type="checkbox" id="touch-input-enabled"> Touch input enabled</label>
+ </div>
+
+ <div class="checkbox">
<label><input type="checkbox" id="select-matched-text"> Select matched text</label>
</div>