From 405e487a7347181f6f49f01839c807c84fc93e41 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Fri, 31 Mar 2017 21:48:10 -0700 Subject: ctrl + c to copy --- ext/fg/js/display-frame.js | 27 +++++++++++++++++++++++++++ ext/fg/js/driver.js | 4 ++++ ext/manifest.json | 3 ++- ext/mixed/js/display.js | 3 +++ 4 files changed, 36 insertions(+), 1 deletion(-) (limited to 'ext') diff --git a/ext/fg/js/display-frame.js b/ext/fg/js/display-frame.js index 59032d0c..f6f7683e 100644 --- a/ext/fg/js/display-frame.js +++ b/ext/fg/js/display-frame.js @@ -51,6 +51,10 @@ window.displayFrame = new class extends Display { window.parent.postMessage('popupClose', '*'); } + selectionCopy() { + window.parent.postMessage('selectionCopy', '*'); + } + showOrphaned() { $('#content').hide(); $('#orphan').show(); @@ -77,4 +81,27 @@ window.displayFrame = new class extends Display { handler(params); } } + + onKeyDown(e) { + if (super.onKeyDown(e)) { + return true; + } + + const handlers = { + 67: /* c */ () => { + if (e.ctrlKey) { + this.selectionCopy(); + return true; + } + } + }; + + const handler = handlers[e.keyCode]; + if (handler && handler()) { + e.preventDefault(); + return true; + } + + return false; + } }; diff --git a/ext/fg/js/driver.js b/ext/fg/js/driver.js index 5191f18d..d4cb1532 100644 --- a/ext/fg/js/driver.js +++ b/ext/fg/js/driver.js @@ -106,6 +106,10 @@ window.driver = new class { const handlers = { popupClose: () => { this.searchClear(); + }, + + selectionCopy: () => { + document.execCommand('copy'); } }; diff --git a/ext/manifest.json b/ext/manifest.json index 83df26e4..3939ae21 100644 --- a/ext/manifest.json +++ b/ext/manifest.json @@ -29,7 +29,8 @@ }, "permissions": [ "", - "storage" + "storage", + "clipboardWrite" ], "commands": { "toggle": { diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 9738319a..f950f0f0 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -301,7 +301,10 @@ class Display { const handler = handlers[e.keyCode]; if (handler && handler()) { e.preventDefault(); + return true; } + + return false; } sourceBack() { -- cgit v1.2.3 From e62c46c4fc46f777fa64a931beaef18f2bb0bd7f Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 1 Apr 2017 11:05:28 -0700 Subject: fix grouped definition sorting bug (fixes #41) --- ext/bg/js/util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext') diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js index d1099262..b3e4feec 100644 --- a/ext/bg/js/util.js +++ b/ext/bg/js/util.js @@ -375,7 +375,7 @@ function dictTermsGroup(definitions, dictionaries) { expression: firstDef.expression, reading: firstDef.reading, reasons: firstDef.reasons, - score: groupDefs.reduce((x, y) => x.score > y.score ? x.score : y.score, Number.MIN_SAFE_INTEGER), + score: groupDefs.reduce((p, v) => v.score > p ? v.score : p, Number.MIN_SAFE_INTEGER), source: firstDef.source }); } -- cgit v1.2.3 From f556c95038e2ef9e4d97b4168ce417ba0d74282f Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 1 Apr 2017 11:20:58 -0700 Subject: improve ctrl + c behavior --- ext/fg/js/display-frame.js | 11 +++-------- ext/mixed/js/display.js | 3 --- 2 files changed, 3 insertions(+), 11 deletions(-) (limited to 'ext') diff --git a/ext/fg/js/display-frame.js b/ext/fg/js/display-frame.js index f6f7683e..9fd09e74 100644 --- a/ext/fg/js/display-frame.js +++ b/ext/fg/js/display-frame.js @@ -83,13 +83,9 @@ window.displayFrame = new class extends Display { } onKeyDown(e) { - if (super.onKeyDown(e)) { - return true; - } - const handlers = { 67: /* c */ () => { - if (e.ctrlKey) { + if (e.ctrlKey && window.getSelection().toString() === '') { this.selectionCopy(); return true; } @@ -99,9 +95,8 @@ window.displayFrame = new class extends Display { const handler = handlers[e.keyCode]; if (handler && handler()) { e.preventDefault(); - return true; + } else { + super.onKeyDown(e); } - - return false; } }; diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index f950f0f0..9738319a 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -301,10 +301,7 @@ class Display { const handler = handlers[e.keyCode]; if (handler && handler()) { e.preventDefault(); - return true; } - - return false; } sourceBack() { -- cgit v1.2.3 From 4de9e5e9e06031e163bfeb27f83a8614f912d454 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 1 Apr 2017 12:01:34 -0700 Subject: support for audio volume adjustment (fixes #39) --- ext/bg/js/options.js | 2 ++ ext/bg/js/util.js | 1 + ext/bg/options.html | 13 +++++++++---- ext/mixed/js/display.js | 2 ++ 4 files changed, 14 insertions(+), 4 deletions(-) (limited to 'ext') diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js index 2089cc53..75f39d24 100644 --- a/ext/bg/js/options.js +++ b/ext/bg/js/options.js @@ -26,6 +26,7 @@ function formRead() { const optionsNew = $.extend(true, {}, optionsOld); optionsNew.general.audioPlayback = $('#audio-playback-buttons').prop('checked'); + optionsNew.general.audioVolume = $('#audio-playback-volume').val(); optionsNew.general.groupResults = $('#group-terms-results').prop('checked'); optionsNew.general.softKatakana = $('#soft-katakana-search').prop('checked'); optionsNew.general.showAdvanced = $('#show-advanced-options').prop('checked'); @@ -111,6 +112,7 @@ $(document).ready(() => { optionsLoad().then(options => { $('#audio-playback-buttons').prop('checked', options.general.audioPlayback); + $('#audio-playback-volume').val(options.general.audioVolume); $('#group-terms-results').prop('checked', options.general.groupResults); $('#soft-katakana-search').prop('checked', options.general.softKatakana); $('#show-advanced-options').prop('checked', options.general.showAdvanced); diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js index b3e4feec..78258c97 100644 --- a/ext/bg/js/util.js +++ b/ext/bg/js/util.js @@ -85,6 +85,7 @@ function optionsSetDefaults(options) { general: { enable: true, audioPlayback: true, + audioVolume: 100, groupResults: true, softKatakana: true, maxResults: 32, diff --git a/ext/bg/options.html b/ext/bg/options.html index 3e457d2d..c483c656 100644 --- a/ext/bg/options.html +++ b/ext/bg/options.html @@ -25,10 +25,6 @@

General Options

-
- -
-
@@ -41,6 +37,15 @@
+
+ +
+ +
+ + +
+
diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 9738319a..36609525 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -343,6 +343,7 @@ class Display { let audio = this.audioCache[url]; if (audio) { audio.currentTime = 0; + audio.volume = this.options.general.audioVolume / 100.0; audio.play(); } else { audio = new Audio(url); @@ -352,6 +353,7 @@ class Display { } this.audioCache[url] = audio; + audio.volume = this.options.general.audioVolume / 100.0; audio.play(); }; } -- cgit v1.2.3 From 4eb3e2f06cd83ef0721557f8559fc0a6d70ad4f5 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 1 Apr 2017 12:08:20 -0700 Subject: version bump --- ext/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext') diff --git a/ext/manifest.json b/ext/manifest.json index 3939ae21..62a70f9c 100644 --- a/ext/manifest.json +++ b/ext/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "Yomichan", - "version": "1.1.9", + "version": "1.1.10", "description": "Japanese dictionary with Anki integration", "icons": {"16": "mixed/img/icon16.png", "48": "mixed/img/icon48.png", "128": "mixed/img/icon128.png"}, -- cgit v1.2.3