From 57697ee2a09dd5ad0a567b7104e4a5ac9a4f1b23 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 18 Mar 2017 13:00:29 -0700 Subject: [PATCH 01/23] polish and initial command support --- ext/bg/js/display-window.js | 9 +++++++-- ext/bg/js/popup.js | 7 ++----- ext/bg/js/util.js | 9 +++++++++ ext/bg/js/yomichan.js | 22 ++++++++++++++++------ ext/bg/search.html | 2 +- ext/manifest.json | 14 ++++++++++++++ 6 files changed, 49 insertions(+), 14 deletions(-) diff --git a/ext/bg/js/display-window.js b/ext/bg/js/display-window.js index ad193c5b..8c732ddd 100644 --- a/ext/bg/js/display-window.js +++ b/ext/bg/js/display-window.js @@ -20,8 +20,13 @@ window.displayWindow = new class extends Display { constructor() { super($('#spinner'), $('#content')); - $('#search').click(this.onSearch.bind(this)); - window.wanakana.bind($('#query').get(0)); + + const search = $('#search'); + search.click(this.onSearch.bind(this)); + + const query = $('#query'); + query.on('input', () => search.prop('disabled', query.val().length === 0)); + window.wanakana.bind(query.get(0)); } definitionAdd(definition, mode) { diff --git a/ext/bg/js/popup.js b/ext/bg/js/popup.js index 9f2567df..5bc7def4 100644 --- a/ext/bg/js/popup.js +++ b/ext/bg/js/popup.js @@ -18,7 +18,7 @@ $(document).ready(() => { - $('#open-search').click(() => window.open(chrome.extension.getURL('/bg/search.html'))); + $('#open-search').click(() => commandExec('search')); $('#open-options').click(() => chrome.runtime.openOptionsPage()); $('#open-help').click(() => window.open('http://foosoft.net/projects/yomichan')); @@ -26,9 +26,6 @@ $(document).ready(() => { const toggle = $('#enable-search'); toggle.prop('checked', options.general.enable).change(); toggle.bootstrapToggle(); - toggle.change(() => { - options.general.enable = toggle.prop('checked'); - optionsSave(options).then(() => instYomi().optionsSet(options)); - }); + toggle.change(() => commandExec('toggle')); }); }); diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js index 59eb9269..6999cae3 100644 --- a/ext/bg/js/util.js +++ b/ext/bg/js/util.js @@ -33,6 +33,15 @@ function promiseCallback(promise, callback) { } +/* + * Commands + */ + +function commandExec(command) { + instYomi().onCommand(command); +} + + /* * Instance */ diff --git a/ext/bg/js/yomichan.js b/ext/bg/js/yomichan.js index a61be8be..3a42c594 100644 --- a/ext/bg/js/yomichan.js +++ b/ext/bg/js/yomichan.js @@ -25,12 +25,13 @@ window.yomichan = new class { this.anki = new AnkiNull(); this.options = null; - chrome.runtime.onMessage.addListener(this.onMessage.bind(this)); - if (chrome.runtime.onInstalled) { - chrome.runtime.onInstalled.addListener(this.onInstalled.bind(this)); - } - - this.translator.prepare().then(optionsLoad).then(this.optionsSet.bind(this)); + this.translator.prepare().then(optionsLoad).then(this.optionsSet.bind(this)).then(() => { + chrome.commands.onCommand.addListener(this.onCommand.bind(this)); + chrome.runtime.onMessage.addListener(this.onMessage.bind(this)); + if (chrome.runtime.onInstalled) { + chrome.runtime.onInstalled.addListener(this.onInstalled.bind(this)); + } + }); } optionsSet(options) { @@ -153,6 +154,15 @@ window.yomichan = new class { } } + onCommand(command) { + if (command === 'search') { + window.open(chrome.extension.getURL('/bg/search.html')); + } else if (command === 'toggle') { + this.options.general.enable = !this.options.general.enable; + optionsSave(this.options).then(() => this.optionsSet(this.options)); + } + } + onMessage(request, sender, callback) { const handlers = new class { api_optionsGet({callback}) { diff --git a/ext/bg/search.html b/ext/bg/search.html index e9c25e15..2fd44fc7 100644 --- a/ext/bg/search.html +++ b/ext/bg/search.html @@ -20,7 +20,7 @@
- +

diff --git a/ext/manifest.json b/ext/manifest.json index 30f33975..3357e661 100644 --- a/ext/manifest.json +++ b/ext/manifest.json @@ -31,6 +31,20 @@ "", "storage" ], + "commands": { + "toggle": { + "suggested_key": { + "default": "Alt+Delete" + }, + "description": "Toggle text scanning" + }, + "search": { + "suggested_key": { + "default": "Alt+Insert" + }, + "description": "Open search window" + } + }, "web_accessible_resources": ["fg/frame.html"], "applications": { "gecko": { From f3f6139c8ebe2ae02291e950f9cc6915ae45b6dc Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 18 Mar 2017 13:46:56 -0700 Subject: [PATCH 02/23] update guide --- ext/bg/guide.html | 13 +++++++------ ext/fg/js/driver.js | 3 +++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/ext/bg/guide.html b/ext/bg/guide.html index 130d6d68..3b3dcab7 100644 --- a/ext/bg/guide.html +++ b/ext/bg/guide.html @@ -7,7 +7,7 @@ -
+
@@ -23,11 +23,12 @@

    -
  1. Click on the icon in the browser toolbar to open the Yomichan options page.
  2. -
  3. Import the dictionaries (bundled or custom) you wish to use for term and Kanji searches.
  4. -
  5. Hold down Shift (or the middle mouse button) as you hover over text to see term definitions.
  6. -
  7. Click on the icon to hear the term pronounced by a native speaker (if audio is available).
  8. -
  9. Click on Kanji in the definition window to view additional information about that character.
  10. +
  11. Click on the icon in the browser toolbar to open the Yomichan actions dialog.
  12. +
  13. Click on the monkey wrench icon in the middle to open the options page.
  14. +
  15. Import the dictionaries you wish to use for term and Kanji searches.
  16. +
  17. Hold down Shift key or the middle mouse button as you move your mouse over text to display definitions.
  18. +
  19. Click on the icon to hear the term pronounced by a native speaker.
  20. +
  21. Click on individual Kanji in the term definition results to view additional information about those characters.
diff --git a/ext/fg/js/driver.js b/ext/fg/js/driver.js index fbe89ab8..16b12d5e 100644 --- a/ext/fg/js/driver.js +++ b/ext/fg/js/driver.js @@ -105,6 +105,9 @@ window.driver = new class { const handlers = new class { api_optionsSet(options) { this.options = options; + if (!this.options.enable) { + this.searchClear(); + } } }; From 15313de18c54d2d600d838d51bac06678974679f Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 18 Mar 2017 16:52:00 -0700 Subject: [PATCH 03/23] tighter layout --- ext/fg/frame.html | 43 ++++++++++++++++++++++------------------- ext/mixed/css/frame.css | 4 ---- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/ext/fg/frame.html b/ext/fg/frame.html index ec0acf64..d915281c 100644 --- a/ext/fg/frame.html +++ b/ext/fg/frame.html @@ -6,28 +6,31 @@ + -
-
- -
- -
- -
-

Yomichan Updated!

-

- The Yomichan extension has been updated to a new version! In order to continue - viewing definitions on this page you must reload this tab or restart your browser. -

-
- - - - - - +
+
+ +
+ +
+

Yomichan Updated!

+

+ The Yomichan extension has been updated to a new version! In order to continue + viewing definitions on this page you must reload this tab or restart your browser. +

+
+ + + + + + diff --git a/ext/mixed/css/frame.css b/ext/mixed/css/frame.css index af689cbe..78108dd5 100644 --- a/ext/mixed/css/frame.css +++ b/ext/mixed/css/frame.css @@ -51,10 +51,6 @@ hr { * Entries */ -.entry { - padding: 15px 0px 15px 0px; -} - .tag-default { background-color: #8a8a91; } From ad17b0603bfcbb6be54fd4941b6a7ca4195947fc Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 18 Mar 2017 17:40:48 -0700 Subject: [PATCH 04/23] scrolling --- ext/fg/frame.html | 3 ++- ext/mixed/css/frame.css | 5 ++++ ext/mixed/js/display.js | 53 ++++++++++++++++++++++++++++++++++------- 3 files changed, 52 insertions(+), 9 deletions(-) diff --git a/ext/fg/frame.html b/ext/fg/frame.html index d915281c..c593db8d 100644 --- a/ext/fg/frame.html +++ b/ext/fg/frame.html @@ -8,7 +8,8 @@ diff --git a/ext/mixed/css/frame.css b/ext/mixed/css/frame.css index 78108dd5..a425aca8 100644 --- a/ext/mixed/css/frame.css +++ b/ext/mixed/css/frame.css @@ -51,6 +51,11 @@ hr { * Entries */ +.entry { + padding-top: 10px; + padding-bottom: 10px; +} + .tag-default { background-color: #8a8a91; } diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index d90cf897..11df7208 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -24,6 +24,9 @@ class Display { this.definitions = []; this.audioCache = {}; this.sequence = 0; + this.index = 0; + + $(document).keydown(this.onKeyDown.bind(this)); } definitionAdd(definition, mode) { @@ -47,6 +50,8 @@ class Display { } showTermDefs(definitions, options, context) { + window.focus(); + this.spinner.hide(); this.definitions = definitions; @@ -68,13 +73,8 @@ class Display { this.templateRender('terms.html', params).then(content => { this.container.html(content); - let offset = 0; - if (context && context.hasOwnProperty('index') && context.index < definitions.length) { - const entry = $('.entry').eq(context.index); - offset = entry.offset().top; - } - - window.scrollTo(0, offset); + const index = context && context.hasOwnProperty('index') ? context.index : 0; + this.entryScroll(index); $('.action-add-note').click(this.onActionAddNote.bind(this)); $('.action-play-audio').click(e => { @@ -102,6 +102,8 @@ class Display { } showKanjiDefs(definitions, options, context) { + window.focus(); + this.spinner.hide(); this.definitions = definitions; @@ -121,7 +123,9 @@ class Display { this.templateRender('kanji.html', params).then(content => { this.container.html(content); - window.scrollTo(0, 0); + + const index = context && context.hasOwnProperty('index') ? context.index : 0; + this.entryScroll(index); $('.action-add-note').click(this.onActionAddNote.bind(this)); $('.source-term').click(e => { @@ -158,6 +162,23 @@ class Display { }); } + entryScroll(index, smooth) { + if (index < 0 || index >= this.definitions.length) { + return; + } + + const body = $('body').stop(); + const entry = $('.entry').eq(index); + + if (smooth) { + body.animate({scrollTop: entry.offset().top}, 200); + } else { + body.scrollTop(entry.offset().top); + } + + this.index = index; + } + onActionAddNote(e) { e.preventDefault(); this.spinner.show(); @@ -184,6 +205,22 @@ class Display { }).catch(this.handleError.bind(this)).then(() => this.spinner.hide()); } + onKeyDown(e) { + if (e.keyCode === 36 /* home */) { + e.preventDefault(); + this.entryScroll(0, true); + } else if (e.keyCode === 35 /* end */) { + e.preventDefault(); + this.entryScroll(this.definitions.length - 1, true); + } if (e.keyCode === 38 /* up */) { + e.preventDefault(); + this.entryScroll(this.index - 1, true); + } else if (e.keyCode === 40 /* down */) { + e.preventDefault(); + this.entryScroll(this.index + 1, true); + } + } + static audioPlay(definition, cache) { for (const key in cache) { const audio = cache[key]; From ad313fd1825ed1b077ad9a59af9423e93032ce44 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 18 Mar 2017 17:53:21 -0700 Subject: [PATCH 05/23] polish --- ext/bg/js/templates.js | 4 ++-- ext/mixed/img/entry-current.png | Bin 0 -> 743 bytes ext/mixed/js/display.js | 7 +++++-- tmpl/kanji.html | 1 + tmpl/terms.html | 1 + 5 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 ext/mixed/img/entry-current.png diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js index 91518e84..333147ba 100644 --- a/ext/bg/js/templates.js +++ b/ext/bg/js/templates.js @@ -284,7 +284,7 @@ templates['fields.html'] = template({"1":function(container,depth0,helpers,parti templates['kanji.html'] = template({"1":function(container,depth0,helpers,partials,data) { var stack1, helper, alias1=depth0 != null ? depth0 : {}; - return "
\n
\n" + return "
\n
\n \n" + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.addable : depth0),{"name":"if","hash":{},"fn":container.program(2, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.source : depth0),{"name":"if","hash":{},"fn":container.program(4, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "
\n\n
" @@ -442,7 +442,7 @@ templates['terms.html'] = template({"1":function(container,depth0,helpers,partia },"12":function(container,depth0,helpers,partials,data) { var stack1, alias1=depth0 != null ? depth0 : {}; - return "
\n
\n" + return "
\n
\n \n" + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.addable : depth0),{"name":"if","hash":{},"fn":container.program(13, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.playback : depth0),{"name":"if","hash":{},"fn":container.program(15, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "
\n\n" diff --git a/ext/mixed/img/entry-current.png b/ext/mixed/img/entry-current.png new file mode 100644 index 0000000000000000000000000000000000000000..bab7cc9bcc64f4f58a40019ab29bc90c98d5510c GIT binary patch literal 743 zcmV?P)rx$R<IWI`!e`47o+X|cM zhswMI)6H-!+|Ry*GtmT2KZBZTgf*vuh@Iv~E3-o`X2T^+DyW5TGfmLUU@4QG+c^0c z#zg&+`J#c@0((YV&ur`*Iawk7JMET#>EkfEJtz9cD4oNF6e!0Aw?I&|=qKwHAy9XoQ zA^YBJr@&gw)O7(`yrYQGx{Yirh2eMScnk9(q^&}_PQ*$`FTOgh0*()5P;Djfw78dp Z{0&Uoz&aZx@__&V002ovPDHLkV1iM?Q(XW6 literal 0 HcmV?d00001 diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 11df7208..7b8f0aae 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -167,13 +167,16 @@ class Display { return; } + $('.current').hide().eq(index).show(); + const body = $('body').stop(); const entry = $('.entry').eq(index); + const target = index === 0 ? 0 : entry.offset().top; if (smooth) { - body.animate({scrollTop: entry.offset().top}, 200); + body.animate({scrollTop: target}, 200); } else { - body.scrollTop(entry.offset().top); + body.scrollTop(target); } this.index = index; diff --git a/tmpl/kanji.html b/tmpl/kanji.html index 4bb524cf..3cc7f966 100644 --- a/tmpl/kanji.html +++ b/tmpl/kanji.html @@ -1,6 +1,7 @@ {{#*inline "kanji"}}
+ {{#if addable}} {{/if}} diff --git a/tmpl/terms.html b/tmpl/terms.html index fa32cea1..6212cb21 100644 --- a/tmpl/terms.html +++ b/tmpl/terms.html @@ -20,6 +20,7 @@ {{#*inline "term"}}
+ {{#if addable}} From 1a4c94209b2bb06509b15d20941c4f1e53f118f4 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 18 Mar 2017 18:08:09 -0700 Subject: [PATCH 06/23] wip --- ext/mixed/js/display.js | 56 ++++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 17 deletions(-) diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 7b8f0aae..2ceef282 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -80,7 +80,7 @@ class Display { $('.action-play-audio').click(e => { e.preventDefault(); const index = Display.entryIndexFind($(e.currentTarget)); - Display.audioPlay(this.definitions[index], this.audioCache); + this.audioPlay(this.definitions[index]); }); $('.kanji-link').click(e => { e.preventDefault(); @@ -209,24 +209,46 @@ class Display { } onKeyDown(e) { - if (e.keyCode === 36 /* home */) { + const handlers = { + 36: /* home */ () => { + this.entryScroll(0, true); + }, + + 35: /* end */ () => { + this.entryScroll(this.definitions.length - 1, true); + }, + + 38: /* up */ () => { + this.entryScroll(this.index - 1, true); + }, + + 40: /* down */ () => { + this.entryScroll(this.index + 1, true); + }, + + 209: /* [ */ () => { + + }, + + 221: /* ] */ () => { + + }, + + 220: /* \ */ () => { + this.audioPlay(this.definitions[this.index]); + } + }; + + const handler = handlers[e.keyCode]; + if (handler) { e.preventDefault(); - this.entryScroll(0, true); - } else if (e.keyCode === 35 /* end */) { - e.preventDefault(); - this.entryScroll(this.definitions.length - 1, true); - } if (e.keyCode === 38 /* up */) { - e.preventDefault(); - this.entryScroll(this.index - 1, true); - } else if (e.keyCode === 40 /* down */) { - e.preventDefault(); - this.entryScroll(this.index + 1, true); + handler(); } } - static audioPlay(definition, cache) { - for (const key in cache) { - const audio = cache[key]; + audioPlay(definition) { + for (const key in this.audioCache) { + const audio = this.audioCache[key]; if (audio !== null) { audio.pause(); } @@ -237,7 +259,7 @@ class Display { return; } - let audio = cache[url]; + let audio = this.audioCache[url]; if (audio) { audio.currentTime = 0; audio.play(); @@ -248,7 +270,7 @@ class Display { audio = new Audio('/mixed/mp3/button.mp3'); } - cache[url] = audio; + this.audioCache[url] = audio; audio.play(); }; } From 6d55767191f50bceef86bf78df7d340f9c5971c7 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 18 Mar 2017 18:21:02 -0700 Subject: [PATCH 07/23] wip --- ext/bg/js/templates.js | 12 ++++++------ ext/fg/frame.html | 12 +++++++----- ext/mixed/js/display.js | 4 ++++ tmpl/kanji.html | 6 +++--- tmpl/terms.html | 8 ++++---- 5 files changed, 24 insertions(+), 18 deletions(-) diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js index 333147ba..f267da80 100644 --- a/ext/bg/js/templates.js +++ b/ext/bg/js/templates.js @@ -284,7 +284,7 @@ templates['fields.html'] = template({"1":function(container,depth0,helpers,parti templates['kanji.html'] = template({"1":function(container,depth0,helpers,partials,data) { var stack1, helper, alias1=depth0 != null ? depth0 : {}; - return "
\n
\n \n" + return "
\n
\n \n" + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.addable : depth0),{"name":"if","hash":{},"fn":container.program(2, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.source : depth0),{"name":"if","hash":{},"fn":container.program(4, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "
\n\n
" @@ -299,9 +299,9 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia + ((stack1 = helpers["if"].call(alias1,((stack1 = (depth0 != null ? depth0.glossary : depth0)) != null ? stack1["1"] : stack1),{"name":"if","hash":{},"fn":container.program(11, data, 0),"inverse":container.program(15, data, 0),"data":data})) != null ? stack1 : "") + "
\n
\n"; },"2":function(container,depth0,helpers,partials,data) { - return " \n"; + return " \n"; },"4":function(container,depth0,helpers,partials,data) { - return " \n"; + return " \n"; },"6":function(container,depth0,helpers,partials,data) { var stack1; @@ -442,7 +442,7 @@ templates['terms.html'] = template({"1":function(container,depth0,helpers,partia },"12":function(container,depth0,helpers,partials,data) { var stack1, alias1=depth0 != null ? depth0 : {}; - return "
\n
\n \n" + return "
\n
\n \n" + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.addable : depth0),{"name":"if","hash":{},"fn":container.program(13, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.playback : depth0),{"name":"if","hash":{},"fn":container.program(15, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "
\n\n" @@ -453,9 +453,9 @@ templates['terms.html'] = template({"1":function(container,depth0,helpers,partia + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.grouped : depth0),{"name":"if","hash":{},"fn":container.program(26, data, 0),"inverse":container.program(32, data, 0),"data":data})) != null ? stack1 : "") + "
\n
\n"; },"13":function(container,depth0,helpers,partials,data) { - return " \n \n"; + return " \n \n"; },"15":function(container,depth0,helpers,partials,data) { - return " \n"; + return " \n"; },"17":function(container,depth0,helpers,partials,data) { var stack1, helper, options, alias1=depth0 != null ? depth0 : {}, alias2=helpers.helperMissing, alias3="function", buffer = "
"; diff --git a/ext/fg/frame.html b/ext/fg/frame.html index c593db8d..09d1689e 100644 --- a/ext/fg/frame.html +++ b/ext/fg/frame.html @@ -21,11 +21,13 @@
-

Yomichan Updated!

-

- The Yomichan extension has been updated to a new version! In order to continue - viewing definitions on this page you must reload this tab or restart your browser. -

+
+

Yomichan Updated!

+

+ The Yomichan extension has been updated to a new version! In order to continue + viewing definitions on this page you must reload this tab or restart your browser. +

+
diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 2ceef282..707d70ee 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -236,6 +236,10 @@ class Display { 220: /* \ */ () => { this.audioPlay(this.definitions[this.index]); + }, + + 8: /* backspace */ () => { + } }; diff --git a/tmpl/kanji.html b/tmpl/kanji.html index 3cc7f966..be5e8541 100644 --- a/tmpl/kanji.html +++ b/tmpl/kanji.html @@ -1,12 +1,12 @@ {{#*inline "kanji"}}
- + {{#if addable}} - + {{/if}} {{#if source}} - + {{/if}}
diff --git a/tmpl/terms.html b/tmpl/terms.html index 6212cb21..f108da26 100644 --- a/tmpl/terms.html +++ b/tmpl/terms.html @@ -20,13 +20,13 @@ {{#*inline "term"}}
- + {{#if addable}} - - + + {{/if}} {{#if playback}} - + {{/if}}
From 55309c1cb39241e1f40aedb6986c77f410213b97 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 19 Mar 2017 15:45:30 -0700 Subject: [PATCH 08/23] wip --- ext/mixed/js/display.js | 127 +++++++++++++++++++++++++--------------- 1 file changed, 79 insertions(+), 48 deletions(-) diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 707d70ee..25a095e0 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -54,6 +54,8 @@ class Display { this.spinner.hide(); this.definitions = definitions; + this.context = context; + this.options = options; const sequence = ++this.sequence; const params = { @@ -76,26 +78,9 @@ class Display { const index = context && context.hasOwnProperty('index') ? context.index : 0; this.entryScroll(index); - $('.action-add-note').click(this.onActionAddNote.bind(this)); - $('.action-play-audio').click(e => { - e.preventDefault(); - const index = Display.entryIndexFind($(e.currentTarget)); - this.audioPlay(this.definitions[index]); - }); - $('.kanji-link').click(e => { - e.preventDefault(); - - const link = $(e.target); - context = context || {}; - context.source = { - definitions, - index: Display.entryIndexFind(link) - }; - - this.kanjiFind(link.text()).then(kanjiDefs => { - this.showKanjiDefs(kanjiDefs, options, context); - }).catch(this.handleError.bind(this)); - }); + $('.action-add-note').click(this.onAddNote.bind(this)); + $('.action-play-audio').click(this.onPlayAudio.bind(this)); + $('.kanji-link').click(this.onKanjiLookup.bind(this)); return this.adderButtonsUpdate(['term-kanji', 'term-kana'], sequence); }).catch(this.handleError.bind(this)); @@ -106,6 +91,8 @@ class Display { this.spinner.hide(); this.definitions = definitions; + this.context = context; + this.options = options; const sequence = ++this.sequence; const params = { @@ -127,15 +114,8 @@ class Display { const index = context && context.hasOwnProperty('index') ? context.index : 0; this.entryScroll(index); - $('.action-add-note').click(this.onActionAddNote.bind(this)); - $('.source-term').click(e => { - e.preventDefault(); - - if (context && context.source) { - context.index = context.source.index; - this.showTermDefs(context.source.definitions, options, context); - } - }); + $('.action-add-note').click(this.onAddNote.bind(this)); + $('.source-term').click(this.onSourceTerm.bind(this)); return this.adderButtonsUpdate(['kanji'], sequence); }).catch(this.handleError.bind(this)); @@ -182,30 +162,54 @@ class Display { this.index = index; } - onActionAddNote(e) { + onSourceTerm(e) { e.preventDefault(); - this.spinner.show(); - const link = $(e.currentTarget); - const mode = link.data('mode'); - const index = Display.entryIndexFind(link); - const definition = this.definitions[index]; + if (this.context && this.context.source) { + const context = { + url: this.context.source.url, + sentence: this.context.source.sentence, + index: this.context.source.index + }; - if (mode !== 'kanji') { - const url = Display.audioBuildUrl(definition); - const filename = Display.audioBuildFilename(definition); - if (url && filename) { - definition.audio = {url, filename}; + this.showTermDefs(this.context.source.definitions, this.options, context); + } + } + + onKanjiLookup(e) { + e.preventDefault(); + + const link = $(e.target); + const context = { + source: { + definitions, + index: Display.entryIndexFind(link) } + }; + + if (this.context) { + context.sentence = this.context.sentence || ''; + context.url = this.context.url || ''; } - this.definitionAdd(definition, mode).then(success => { - if (success) { - Display.adderButtonFind(index, mode).addClass('disabled'); - } else { - this.handleError('note could not be added'); - } - }).catch(this.handleError.bind(this)).then(() => this.spinner.hide()); + this.kanjiFind(link.text()).then(kanjiDefs => { + this.showKanjiDefs(kanjiDefs, options, context); + }).catch(this.handleError.bind(this)); + } + + onPlayAudio(e) { + e.preventDefault(); + + const index = Display.entryIndexFind($(e.currentTarget)); + this.audioPlay(this.definitions[index]); + } + + onAddNote(e) { + e.preventDefault(); + + const link = $(e.currentTarget); + const index = Display.entryIndexFind(link); + this.noteAdd(index, link.data('mode')); } onKeyDown(e) { @@ -250,7 +254,33 @@ class Display { } } - audioPlay(definition) { + sourceTerm(index) { + + + } + + noteAdd(index, mode) { + this.spinner.show(); + + const definition = this.definitions[index]; + if (mode !== 'kanji') { + const url = Display.audioBuildUrl(definition); + const filename = Display.audioBuildFilename(definition); + if (url && filename) { + definition.audio = {url, filename}; + } + } + + this.definitionAdd(definition, mode).then(success => { + if (success) { + Display.adderButtonFind(index, mode).addClass('disabled'); + } else { + this.handleError('note could not be added'); + } + }).catch(this.handleError.bind(this)).then(() => this.spinner.hide()); + } + + audioPlay(index) { for (const key in this.audioCache) { const audio = this.audioCache[key]; if (audio !== null) { @@ -258,6 +288,7 @@ class Display { } } + const definition = this.definitions[index]; const url = Display.audioBuildUrl(definition); if (!url) { return; From 5989c5faae2467135bef222da886aed41e023d33 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Fri, 24 Mar 2017 22:49:14 -0700 Subject: [PATCH 09/23] cleanup --- ext/mixed/js/display.js | 81 +++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 47 deletions(-) diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 45c1e08c..39ad41a3 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -55,8 +55,8 @@ class Display { this.spinner.hide(); this.definitions = definitions; - this.context = context; this.options = options; + this.context = context; const sequence = ++this.sequence; const params = { @@ -75,9 +75,7 @@ class Display { this.templateRender('terms.html', params).then(content => { this.container.html(content); - - const index = context && context.hasOwnProperty('index') ? context.index : 0; - this.entryScroll(index); + this.entryScroll(context && context.index || 0); $('.action-add-note').click(this.onAddNote.bind(this)); $('.action-play-audio').click(this.onPlayAudio.bind(this)); @@ -92,8 +90,8 @@ class Display { this.spinner.hide(); this.definitions = definitions; - this.context = context; this.options = options; + this.context = context; const sequence = ++this.sequence; const params = { @@ -111,9 +109,7 @@ class Display { this.templateRender('kanji.html', params).then(content => { this.container.html(content); - - const index = context && context.hasOwnProperty('index') ? context.index : 0; - this.entryScroll(index); + this.entryScroll(context && context.index || 0); $('.action-add-note').click(this.onAddNote.bind(this)); $('.source-term').click(this.onSourceTerm.bind(this)); @@ -183,34 +179,32 @@ class Display { const link = $(e.target); const context = { source: { - definitions, + definitions: this.definitions, index: Display.entryIndexFind(link) } }; if (this.context) { - context.sentence = this.context.sentence || ''; - context.url = this.context.url || ''; + context.sentence = this.context.sentence; + context.url = this.context.url; } this.kanjiFind(link.text()).then(kanjiDefs => { - this.showKanjiDefs(kanjiDefs, options, context); + this.showKanjiDefs(kanjiDefs, this.options, context); }).catch(this.handleError.bind(this)); } onPlayAudio(e) { e.preventDefault(); - const index = Display.entryIndexFind($(e.currentTarget)); this.audioPlay(this.definitions[index]); } onAddNote(e) { e.preventDefault(); - const link = $(e.currentTarget); const index = Display.entryIndexFind(link); - this.noteAdd(index, link.data('mode')); + this.noteAdd(this.definitions[index], link.data('mode')); } onKeyDown(e) { @@ -255,14 +249,8 @@ class Display { } } - sourceTerm(index) { - - - } - - noteAdd(index, mode) { + noteAdd(definition, mode) { this.spinner.show(); - const definition = this.definitions[index]; let promise = Promise.resolve(); if (mode !== 'kanji') { @@ -275,6 +263,7 @@ class Display { promise.then(() => { return this.definitionAdd(definition, mode).then(success => { if (success) { + const index = this.definitions.indexOf(definition); Display.adderButtonFind(index, mode).addClass('disabled'); } else { this.handleError('note could not be added'); @@ -283,9 +272,8 @@ class Display { }).catch(this.handleError.bind(this)).then(() => this.spinner.hide()); } - audioPlay(index) { + audioPlay(definition) { this.spinner.show(); - const definition = this.definitions[index]; for (const key in this.audioCache) { this.audioCache[key].pause(); @@ -319,30 +307,29 @@ class Display { const response = this.responseCache[definition.expression]; if (response) { resolve(response); - return; + } else { + const data = { + post: 'dictionary_reference', + match_type: 'exact', + search_query: definition.expression + }; + + const params = []; + for (const key in data) { + params.push(`${encodeURIComponent(key)}=${encodeURIComponent(data[key])}`); + } + + const xhr = new XMLHttpRequest(); + xhr.open('POST', 'https://www.japanesepod101.com/learningcenter/reference/dictionary_post'); + xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); + xhr.addEventListener('error', () => reject('failed to scrape audio data')); + xhr.addEventListener('load', () => { + this.responseCache[definition.expression] = xhr.responseText; + resolve(xhr.responseText); + }); + + xhr.send(params.join('&')); } - - const data = { - post: 'dictionary_reference', - match_type: 'exact', - search_query: definition.expression - }; - - const params = []; - for (const key in data) { - params.push(`${encodeURIComponent(key)}=${encodeURIComponent(data[key])}`); - } - - const xhr = new XMLHttpRequest(); - xhr.open('POST', 'https://www.japanesepod101.com/learningcenter/reference/dictionary_post'); - xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); - xhr.addEventListener('error', () => reject('failed to scrape audio data')); - xhr.addEventListener('load', () => { - this.responseCache[definition.expression] = xhr.responseText; - resolve(xhr.responseText); - }); - - xhr.send(params.join('&')); }).then(response => { const dom = new DOMParser().parseFromString(response, 'text/html'); const entries = []; From 4e5ded5735f353428ad0497923d43e9bd3db8645 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 25 Mar 2017 09:45:05 -0700 Subject: [PATCH 10/23] fix audio playback bug --- ext/mixed/js/display.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 39ad41a3..c7f20a92 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -337,8 +337,8 @@ class Display { for (const row of dom.getElementsByClassName('dc-result-row')) { try { const url = row.getElementsByClassName('ill-onebuttonplayer').item(0).getAttribute('data-url'); - const expression = dom.getElementsByClassName('dc-vocab').item(0).innerText; - const reading = dom.getElementsByClassName('dc-vocab_kana').item(0).innerText; + const expression = row.getElementsByClassName('dc-vocab').item(0).innerText; + const reading = row.getElementsByClassName('dc-vocab_kana').item(0).innerText; if (url && expression && reading) { entries.push({url, expression, reading}); From 0e167876923ba6f20c8b84e518436f2b523e06f9 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 25 Mar 2017 10:05:03 -0700 Subject: [PATCH 11/23] refactor --- ext/bg/search.html | 1 + ext/fg/frame.html | 1 + ext/mixed/js/display.js | 76 ++------------------------------------- ext/mixed/js/util.js | 80 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 84 insertions(+), 74 deletions(-) create mode 100644 ext/mixed/js/util.js diff --git a/ext/bg/search.html b/ext/bg/search.html index 2fd44fc7..b8ab21b0 100644 --- a/ext/bg/search.html +++ b/ext/bg/search.html @@ -34,6 +34,7 @@ + diff --git a/ext/fg/frame.html b/ext/fg/frame.html index 09d1689e..35bc0284 100644 --- a/ext/fg/frame.html +++ b/ext/fg/frame.html @@ -33,6 +33,7 @@ + diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index c7f20a92..29a292c1 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -256,7 +256,7 @@ class Display { if (mode !== 'kanji') { const filename = Display.audioBuildFilename(definition); if (filename) { - promise = this.audioBuildUrl(definition).then(url => definition.audio = {url, filename}).catch(() => {}); + promise = audioBuildUrl(definition, this.responseCache).then(url => definition.audio = {url, filename}).catch(() => {}); } } @@ -279,7 +279,7 @@ class Display { this.audioCache[key].pause(); } - this.audioBuildUrl(definition).then(url => { + audioBuildUrl(definition, this.responseCache).then(url => { if (!url) { url = '/mixed/mp3/button.mp3'; } @@ -302,78 +302,6 @@ class Display { }).catch(this.handleError.bind(this)).then(() => this.spinner.hide()); } - audioBuildUrl(definition) { - return new Promise((resolve, reject) => { - const response = this.responseCache[definition.expression]; - if (response) { - resolve(response); - } else { - const data = { - post: 'dictionary_reference', - match_type: 'exact', - search_query: definition.expression - }; - - const params = []; - for (const key in data) { - params.push(`${encodeURIComponent(key)}=${encodeURIComponent(data[key])}`); - } - - const xhr = new XMLHttpRequest(); - xhr.open('POST', 'https://www.japanesepod101.com/learningcenter/reference/dictionary_post'); - xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); - xhr.addEventListener('error', () => reject('failed to scrape audio data')); - xhr.addEventListener('load', () => { - this.responseCache[definition.expression] = xhr.responseText; - resolve(xhr.responseText); - }); - - xhr.send(params.join('&')); - } - }).then(response => { - const dom = new DOMParser().parseFromString(response, 'text/html'); - const entries = []; - - for (const row of dom.getElementsByClassName('dc-result-row')) { - try { - const url = row.getElementsByClassName('ill-onebuttonplayer').item(0).getAttribute('data-url'); - const expression = row.getElementsByClassName('dc-vocab').item(0).innerText; - const reading = row.getElementsByClassName('dc-vocab_kana').item(0).innerText; - - if (url && expression && reading) { - entries.push({url, expression, reading}); - } - } catch (e) { - // NOP - } - } - - return entries; - }).then(entries => { - for (const entry of entries) { - if (!definition.reading || definition.reading === entry.reading) { - return entry.url; - } - } - }); - } - - static audioBuildFilename(definition) { - if (!definition.reading && !definition.expression) { - return; - } - - let filename = 'yomichan'; - if (definition.reading) { - filename += `_${definition.reading}`; - } - if (definition.expression) { - filename += `_${definition.expression}`; - } - - return filename += '.mp3'; - } - static entryIndexFind(element) { return $('.entry').index(element.closest('.entry')); } diff --git a/ext/mixed/js/util.js b/ext/mixed/js/util.js new file mode 100644 index 00000000..13f124a0 --- /dev/null +++ b/ext/mixed/js/util.js @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2017 Alex Yatskov + * Author: Alex Yatskov + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +/* + * Audio + */ + +function audioBuildUrl(definition, cache) { + return new Promise((resolve, reject) => { + const response = cache[definition.expression]; + if (response) { + resolve(response); + } else { + const data = { + post: 'dictionary_reference', + match_type: 'exact', + search_query: definition.expression + }; + + const params = []; + for (const key in data) { + params.push(`${encodeURIComponent(key)}=${encodeURIComponent(data[key])}`); + } + + const xhr = new XMLHttpRequest(); + xhr.open('POST', 'https://www.japanesepod101.com/learningcenter/reference/dictionary_post'); + xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); + xhr.addEventListener('error', () => reject('failed to scrape audio data')); + xhr.addEventListener('load', () => { + cache[definition.expression] = xhr.responseText; + resolve(xhr.responseText); + }); + + xhr.send(params.join('&')); + } + }).then(response => { + 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 reading = row.getElementsByClassName('dc-vocab_kana').item(0).innerText; + if (url && reading && (!definition.reading || definition.reading === reading)) { + return url; + } + } catch (e) { + // NOP + } + } + }); +} + +function audioBuildFilename(definition) { + if (definition.reading && definition.expression) { + let filename = 'yomichan'; + if (definition.reading) { + filename += `_${definition.reading}`; + } + if (definition.expression) { + filename += `_${definition.expression}`; + } + + return filename += '.mp3'; + } +} From 20d062329bfcdc0d7c5fd07f48071ae6524f9566 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 25 Mar 2017 10:46:59 -0700 Subject: [PATCH 12/23] more audio handling improvements --- ext/bg/background.html | 1 + ext/bg/js/yomichan.js | 35 +++++++++++++---------------------- ext/mixed/js/display.js | 23 ++++++----------------- ext/mixed/js/util.js | 31 ++++++++++++++++++++++++++++++- 4 files changed, 50 insertions(+), 40 deletions(-) diff --git a/ext/bg/background.html b/ext/bg/background.html index 8fb41a38..b5ae147b 100644 --- a/ext/bg/background.html +++ b/ext/bg/background.html @@ -7,6 +7,7 @@ + diff --git a/ext/bg/js/yomichan.js b/ext/bg/js/yomichan.js index 3a42c594..50a8a636 100644 --- a/ext/bg/js/yomichan.js +++ b/ext/bg/js/yomichan.js @@ -56,7 +56,10 @@ window.yomichan = new class { } noteFormat(definition, mode) { - const note = {fields: {}, tags: this.options.anki.tags}; + const note = { + fields: {}, + tags: this.options.anki.tags + }; let fields = []; if (mode === 'kanji') { @@ -67,25 +70,6 @@ window.yomichan = new class { fields = this.options.anki.terms.fields; note.deckName = this.options.anki.terms.deck; note.modelName = this.options.anki.terms.model; - - if (definition.audio) { - const audio = { - url: definition.audio.url, - filename: definition.audio.filename, - skipHash: '7e2c2f954ef6051373ba916f000168dc', - fields: [] - }; - - for (const name in fields) { - if (fields[name].includes('{audio}')) { - audio.fields.push(name); - } - } - - if (audio.fields.length > 0) { - note.audio = audio; - } - } } for (const name in fields) { @@ -117,8 +101,15 @@ window.yomichan = new class { } definitionAdd(definition, mode) { - const note = this.noteFormat(definition, mode); - return this.anki.addNote(note); + let promise = Promise.resolve(); + if (this.options.general.audioPlayback && mode !== 'kanji') { + promise = audioInject(definition, this.options.anki.terms.fields); + } + + return promise.then(() => { + const note = this.noteFormat(definition, mode); + return this.anki.addNote(note); + }); } definitionsAddable(definitions, modes) { diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 29a292c1..050caf4e 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -251,24 +251,13 @@ class Display { noteAdd(definition, mode) { this.spinner.show(); - - let promise = Promise.resolve(); - if (mode !== 'kanji') { - const filename = Display.audioBuildFilename(definition); - if (filename) { - promise = audioBuildUrl(definition, this.responseCache).then(url => definition.audio = {url, filename}).catch(() => {}); + return this.definitionAdd(definition, mode).then(success => { + if (success) { + const index = this.definitions.indexOf(definition); + Display.adderButtonFind(index, mode).addClass('disabled'); + } else { + this.handleError('note could not be added'); } - } - - promise.then(() => { - return this.definitionAdd(definition, mode).then(success => { - if (success) { - const index = this.definitions.indexOf(definition); - Display.adderButtonFind(index, mode).addClass('disabled'); - } else { - this.handleError('note could not be added'); - } - }); }).catch(this.handleError.bind(this)).then(() => this.spinner.hide()); } diff --git a/ext/mixed/js/util.js b/ext/mixed/js/util.js index 13f124a0..1289455c 100644 --- a/ext/mixed/js/util.js +++ b/ext/mixed/js/util.js @@ -21,7 +21,7 @@ * Audio */ -function audioBuildUrl(definition, cache) { +function audioBuildUrl(definition, cache={}) { return new Promise((resolve, reject) => { const response = cache[definition.expression]; if (response) { @@ -78,3 +78,32 @@ function audioBuildFilename(definition) { return filename += '.mp3'; } } + +function audioInject(definition, fields) { + const filename = audioBuildFilename(definition); + if (!filename) { + return Promise.resolve(true); + } + + const audio = { + filename, + skipHash: '7e2c2f954ef6051373ba916f000168dc', + fields: [] + }; + + for (const name in fields) { + if (fields[name].includes('{audio}')) { + audio.fields.push(name); + } + } + + if (audio.fields.length === 0) { + return Promise.resolve(true); + } + + return audioBuildUrl(definition).then(url => { + audio.url = url; + note.audio = audio; + return true; + }).catch(() => false); +} From 83a6c30d0e68496bc7592b3adfa91ae536a487e1 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 25 Mar 2017 12:01:20 -0700 Subject: [PATCH 13/23] audio improvements --- ext/bg/js/yomichan.js | 21 ++++++++++++++++++++- ext/mixed/js/util.js | 15 +++++---------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/ext/bg/js/yomichan.js b/ext/bg/js/yomichan.js index 50a8a636..e2deb2cd 100644 --- a/ext/bg/js/yomichan.js +++ b/ext/bg/js/yomichan.js @@ -70,6 +70,25 @@ window.yomichan = new class { fields = this.options.anki.terms.fields; note.deckName = this.options.anki.terms.deck; note.modelName = this.options.anki.terms.model; + + if (definition.audio) { + const audio = { + url: definition.audio.url, + filename: definition.audio.filename, + skipHash: '7e2c2f954ef6051373ba916f000168dc', + fields: [] + }; + + for (const name in fields) { + if (fields[name].includes('{audio}')) { + audio.fields.push(name); + } + } + + if (audio.fields.length > 0) { + note.audio = audio; + } + } } for (const name in fields) { @@ -102,7 +121,7 @@ window.yomichan = new class { definitionAdd(definition, mode) { let promise = Promise.resolve(); - if (this.options.general.audioPlayback && mode !== 'kanji') { + if (mode !== 'kanji') { promise = audioInject(definition, this.options.anki.terms.fields); } diff --git a/ext/mixed/js/util.js b/ext/mixed/js/util.js index 1289455c..4ce60e4f 100644 --- a/ext/mixed/js/util.js +++ b/ext/mixed/js/util.js @@ -85,25 +85,20 @@ function audioInject(definition, fields) { return Promise.resolve(true); } - const audio = { - filename, - skipHash: '7e2c2f954ef6051373ba916f000168dc', - fields: [] - }; - + let usesAudio = false; for (const name in fields) { if (fields[name].includes('{audio}')) { - audio.fields.push(name); + usesAudio = true; + break; } } - if (audio.fields.length === 0) { + if (!usesAudio) { return Promise.resolve(true); } return audioBuildUrl(definition).then(url => { - audio.url = url; - note.audio = audio; + definition.audio = {url, filename}; return true; }).catch(() => false); } From ff3315ebf147a3e8d1cab5726724b20a2694aa73 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 25 Mar 2017 12:09:57 -0700 Subject: [PATCH 14/23] fixing reason sorting --- ext/bg/js/deinflector.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/bg/js/deinflector.js b/ext/bg/js/deinflector.js index 6e480068..6484f953 100644 --- a/ext/bg/js/deinflector.js +++ b/ext/bg/js/deinflector.js @@ -90,7 +90,7 @@ class Deinflection { source: this.term, rules: this.rules, definitions: this.definitions, - reasons: [this.reason] + reasons: this.reason.length > 0 ? [this.reason] : [] }]; } From 4a232151e065400495ec2ed0ca57dff8da84c4b7 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 25 Mar 2017 12:21:25 -0700 Subject: [PATCH 15/23] more keyboard shortcuts --- ext/mixed/js/display.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 050caf4e..f3423878 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -140,9 +140,8 @@ class Display { } entryScroll(index, smooth) { - if (index < 0 || index >= this.definitions.length) { - return; - } + index = Math.min(index, this.definitions.length - 1); + index = Math.max(index, 0); $('.current').hide().eq(index).show(); @@ -217,6 +216,14 @@ class Display { this.entryScroll(this.definitions.length - 1, true); }, + 33: /* page up */ () => { + this.entryScroll(this.index - 3, true); + }, + + 34: /* page down */ () => { + this.entryScroll(this.index + 3, true); + }, + 38: /* up */ () => { this.entryScroll(this.index - 1, true); }, From 90eaae1725511bbc039f84f684b7b080e0fa2d44 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 25 Mar 2017 15:22:28 -0700 Subject: [PATCH 16/23] wip --- ext/fg/js/driver.js | 22 ++++++++++++++++++++++ ext/mixed/js/display.js | 16 ++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/ext/fg/js/driver.js b/ext/fg/js/driver.js index 16b12d5e..5e17537e 100644 --- a/ext/fg/js/driver.js +++ b/ext/fg/js/driver.js @@ -35,6 +35,7 @@ window.driver = new class { window.addEventListener('mouseup', this.onMouseUp.bind(this)); window.addEventListener('mousemove', this.onMouseMove.bind(this)); window.addEventListener('resize', e => this.searchClear()); + window.addEventListener('message', this.onFrameMessage.bind(this)); chrome.runtime.onMessage.addListener(this.onBgMessage.bind(this)); }).catch(this.handleError.bind(this)); } @@ -101,6 +102,27 @@ window.driver = new class { } } + onFrameMessage(e) { + const handlers = { + popupClose: () => { + this.searchClear(); + }, + + scanLeft: () => { + + }, + + scanRight: () => { + + } + }; + + const handler = handlers[e.data]; + if (handler) { + handler(); + } + } + onBgMessage({action, params}, sender, callback) { const handlers = new class { api_optionsSet(options) { diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index f3423878..30f703bb 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -207,6 +207,10 @@ class Display { } onKeyDown(e) { + const notifyParent = action => { + window.parent.postMessage(action, '*'); + }; + const handlers = { 36: /* home */ () => { this.entryScroll(0, true); @@ -246,6 +250,18 @@ class Display { 8: /* backspace */ () => { + }, + + 27: /* escape */ () => { + notifyParent('popupClose'); + }, + + 37: /* left */ () => { + notifyParent('scanLeft'); + }, + + 39: /* right */ () => { + notifyParent('scanRight'); } }; From b8d0788144974daab8d55c8de1af7515a291ba4f Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 25 Mar 2017 15:59:33 -0700 Subject: [PATCH 17/23] wip --- ext/bg/js/display-window.js | 4 ++++ ext/fg/js/display-frame.js | 4 ++++ ext/fg/js/driver.js | 18 +++++----------- ext/mixed/js/display.js | 42 +++++++++++++++---------------------- 4 files changed, 30 insertions(+), 38 deletions(-) diff --git a/ext/bg/js/display-window.js b/ext/bg/js/display-window.js index 8c732ddd..ae97cd36 100644 --- a/ext/bg/js/display-window.js +++ b/ext/bg/js/display-window.js @@ -49,6 +49,10 @@ window.displayWindow = new class extends Display { window.alert(`Error: ${error}`); } + clearSearch() { + $('#query').focus().select(); + } + onSearch(e) { e.preventDefault(); $('#intro').slideUp(); diff --git a/ext/fg/js/display-frame.js b/ext/fg/js/display-frame.js index 8f15b1bc..d930d325 100644 --- a/ext/fg/js/display-frame.js +++ b/ext/fg/js/display-frame.js @@ -47,6 +47,10 @@ window.displayFrame = new class extends Display { } } + clearSearch() { + window.parent.postMessage('popupClose', '*'); + } + showOrphaned() { $('#content').hide(); $('#orphan').show(); diff --git a/ext/fg/js/driver.js b/ext/fg/js/driver.js index 5e17537e..7a56dd9c 100644 --- a/ext/fg/js/driver.js +++ b/ext/fg/js/driver.js @@ -46,14 +46,14 @@ window.driver = new class { } popupTimerClear() { - if (this.popupTimer !== null) { + if (this.popupTimer) { window.clearTimeout(this.popupTimer); this.popupTimer = null; } } onMouseOver(e) { - if (e.target === this.popup.container && this.popuptimer !== null) { + if (e.target === this.popup.container && this.popupTimer) { this.popupTimerClear(); } } @@ -106,14 +106,6 @@ window.driver = new class { const handlers = { popupClose: () => { this.searchClear(); - }, - - scanLeft: () => { - - }, - - scanRight: () => { - } }; @@ -147,11 +139,11 @@ window.driver = new class { } const textSource = docRangeFromPoint(point, this.options.scanning.imposter); - if (textSource === null || !textSource.containsPoint(point)) { + if (!textSource || !textSource.containsPoint(point)) { return; } - if (this.lastTextSource !== null && this.lastTextSource.equals(textSource)) { + if (this.lastTextSource && this.lastTextSource.equals(textSource)) { return; } @@ -225,7 +217,7 @@ window.driver = new class { docImposterDestroy(); this.popup.hide(); - if (this.options.scanning.selectText && this.lastTextSource !== null) { + if (this.options.scanning.selectText && this.lastTextSource) { this.lastTextSource.deselect(); } diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 30f703bb..140185cc 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -50,6 +50,10 @@ class Display { throw 'override me'; } + clearSearch() { + throw 'override me'; + } + showTermDefs(definitions, options, context) { window.focus(); @@ -207,17 +211,13 @@ class Display { } onKeyDown(e) { - const notifyParent = action => { - window.parent.postMessage(action, '*'); - }; - const handlers = { - 36: /* home */ () => { - this.entryScroll(0, true); + 8: /* backspace */ () => { + }, - 35: /* end */ () => { - this.entryScroll(this.definitions.length - 1, true); + 27: /* escape */ () => { + this.clearSearch(); }, 33: /* page up */ () => { @@ -228,6 +228,14 @@ class Display { this.entryScroll(this.index + 3, true); }, + 35: /* end */ () => { + this.entryScroll(this.definitions.length - 1, true); + }, + + 36: /* home */ () => { + this.entryScroll(0, true); + }, + 38: /* up */ () => { this.entryScroll(this.index - 1, true); }, @@ -240,28 +248,12 @@ class Display { }, - 221: /* ] */ () => { - - }, - 220: /* \ */ () => { this.audioPlay(this.definitions[this.index]); }, - 8: /* backspace */ () => { + 221: /* ] */ () => { - }, - - 27: /* escape */ () => { - notifyParent('popupClose'); - }, - - 37: /* left */ () => { - notifyParent('scanLeft'); - }, - - 39: /* right */ () => { - notifyParent('scanRight'); } }; From bc2bf51a072af45ddc61a7f6b1c5cc3b94f8ad3e Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 25 Mar 2017 16:28:15 -0700 Subject: [PATCH 18/23] wip --- ext/bg/js/popup.js | 4 ++-- ext/bg/js/yomichan.js | 27 ++++++++++++++++++++++----- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/ext/bg/js/popup.js b/ext/bg/js/popup.js index 5bc7def4..8577dd96 100644 --- a/ext/bg/js/popup.js +++ b/ext/bg/js/popup.js @@ -19,8 +19,8 @@ $(document).ready(() => { $('#open-search').click(() => commandExec('search')); - $('#open-options').click(() => chrome.runtime.openOptionsPage()); - $('#open-help').click(() => window.open('http://foosoft.net/projects/yomichan')); + $('#open-options').click(() => commandExec('options')); + $('#open-help').click(() => commandExec('help')); optionsLoad().then(options => { const toggle = $('#enable-search'); diff --git a/ext/bg/js/yomichan.js b/ext/bg/js/yomichan.js index e2deb2cd..1a34aba4 100644 --- a/ext/bg/js/yomichan.js +++ b/ext/bg/js/yomichan.js @@ -165,11 +165,28 @@ window.yomichan = new class { } onCommand(command) { - if (command === 'search') { - window.open(chrome.extension.getURL('/bg/search.html')); - } else if (command === 'toggle') { - this.options.general.enable = !this.options.general.enable; - optionsSave(this.options).then(() => this.optionsSet(this.options)); + const handlers = { + search: () => { + chrome.tabs.create({url: chrome.extension.getURL('/bg/search.html')}); + }, + + help: () => { + chrome.tabs.create({url: 'https://foosoft.net/projects/yomichan/'}); + }, + + options: () => { + chrome.runtime.openOptionsPage(); + }, + + toggle: () => { + this.options.general.enable = !this.options.general.enable; + optionsSave(this.options).then(() => this.optionsSet(this.options)); + } + }; + + const handler = handlers[command]; + if (handler) { + handler(); } } From 218db0771fae0754a50cadc1891a042112b58699 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 25 Mar 2017 16:45:43 -0700 Subject: [PATCH 19/23] cleanup, firefox scrolling --- ext/bg/js/yomichan.js | 14 +++++++------- ext/fg/js/display-frame.js | 8 ++++---- ext/fg/js/driver.js | 4 ++-- ext/mixed/js/display.js | 6 +++--- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/ext/bg/js/yomichan.js b/ext/bg/js/yomichan.js index 1a34aba4..39105c54 100644 --- a/ext/bg/js/yomichan.js +++ b/ext/bg/js/yomichan.js @@ -192,32 +192,32 @@ window.yomichan = new class { onMessage(request, sender, callback) { const handlers = new class { - api_optionsGet({callback}) { + optionsGet({callback}) { promiseCallback(optionsLoad(), callback); } - api_kanjiFind({text, callback}) { + kanjiFind({text, callback}) { promiseCallback(this.kanjiFind(text), callback); } - api_termsFind({text, callback}) { + termsFind({text, callback}) { promiseCallback(this.termsFind(text), callback); } - api_templateRender({template, data, callback}) { + templateRender({template, data, callback}) { promiseCallback(this.templateRender(template, data), callback); } - api_definitionAdd({definition, mode, callback}) { + definitionAdd({definition, mode, callback}) { promiseCallback(this.definitionAdd(definition, mode), callback); } - api_definitionsAddable({definitions, modes, callback}) { + definitionsAddable({definitions, modes, callback}) { promiseCallback(this.definitionsAddable(definitions, modes), callback); } }; - const {action, params} = request, method = handlers[`api_${action}`]; + const {action, params} = request, method = handlers[action]; if (typeof(method) === 'function') { params.callback = callback; method.call(this, params); diff --git a/ext/fg/js/display-frame.js b/ext/fg/js/display-frame.js index d930d325..41c2fb53 100644 --- a/ext/fg/js/display-frame.js +++ b/ext/fg/js/display-frame.js @@ -58,20 +58,20 @@ window.displayFrame = new class extends Display { onMessage(e) { const handlers = new class { - api_showTermDefs({definitions, options, context}) { + showTermDefs({definitions, options, context}) { this.showTermDefs(definitions, options, context); } - api_showKanjiDefs({definitions, options, context}) { + showKanjiDefs({definitions, options, context}) { this.showKanjiDefs(definitions, options, context); } - api_showOrphaned() { + showOrphaned() { this.showOrphaned(); } }; - const {action, params} = e.originalEvent.data, method = handlers[`api_${action}`]; + const {action, params} = e.originalEvent.data, method = handlers[action]; if (typeof(method) === 'function') { method.call(this, params); } diff --git a/ext/fg/js/driver.js b/ext/fg/js/driver.js index 7a56dd9c..036dc2d8 100644 --- a/ext/fg/js/driver.js +++ b/ext/fg/js/driver.js @@ -117,7 +117,7 @@ window.driver = new class { onBgMessage({action, params}, sender, callback) { const handlers = new class { - api_optionsSet(options) { + optionsSet(options) { this.options = options; if (!this.options.enable) { this.searchClear(); @@ -125,7 +125,7 @@ window.driver = new class { } }; - const method = handlers[`api_${action}`]; + const method = handlers[action]; if (typeof(method) === 'function') { method.call(this, params); } diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 140185cc..50940e58 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -149,14 +149,14 @@ class Display { $('.current').hide().eq(index).show(); - const body = $('body').stop(); + const container = $('html,body').stop(); const entry = $('.entry').eq(index); const target = index === 0 ? 0 : entry.offset().top; if (smooth) { - body.animate({scrollTop: target}, 200); + container.animate({scrollTop: target}, 200); } else { - body.scrollTop(target); + container.scrollTop(target); } this.index = index; From f5a8383d2a670f32d5431150fe6571a3ada3bf18 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 25 Mar 2017 17:18:55 -0700 Subject: [PATCH 20/23] wip --- ext/manifest.json | 6 ++++++ ext/mixed/js/display.js | 21 +++++++++------------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/ext/manifest.json b/ext/manifest.json index 215397d0..e759c4dc 100644 --- a/ext/manifest.json +++ b/ext/manifest.json @@ -43,6 +43,12 @@ "default": "Alt+Insert" }, "description": "Open search window" + }, + "options": { + "suggested_key": { + "default": "Alt+End" + }, + "description": "Open options page" } }, "web_accessible_resources": ["fg/frame.html"], diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 50940e58..dca32e78 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -211,11 +211,8 @@ class Display { } onKeyDown(e) { + const requireAlt = ['e', 'k', 'p']; const handlers = { - 8: /* backspace */ () => { - - }, - 27: /* escape */ () => { this.clearSearch(); }, @@ -244,21 +241,21 @@ class Display { this.entryScroll(this.index + 1, true); }, - 209: /* [ */ () => { - + 69: /* e */ () => { + this.noteAdd(this.definitions[this.index], 'term-kanji'); }, - 220: /* \ */ () => { + 75: /* k */ () => { + this.noteAdd(this.definitions[this.index], 'term-kana'); + }, + + 80: /* p */ () => { this.audioPlay(this.definitions[this.index]); - }, - - 221: /* ] */ () => { - } }; const handler = handlers[e.keyCode]; - if (handler) { + if (handler && (e.altKey || !requireAlt.includes(e.keyCode))) { e.preventDefault(); handler(); } From 2580dd8e7fc21bc5c39521f777a53c2aa790cfe1 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 25 Mar 2017 17:53:25 -0700 Subject: [PATCH 21/23] keyboard shortcuts --- ext/mixed/js/display.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index dca32e78..639c2673 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -211,7 +211,13 @@ class Display { } onKeyDown(e) { - const requireAlt = ['e', 'k', 'p']; + const noteTryAdd = mode => { + const button = Display.adderButtonFind(this.index, mode); + if (button.length !== 0 && !button.hasClass('disabled')) { + this.noteAdd(this.definitions[this.index], mode); + } + }; + const handlers = { 27: /* escape */ () => { this.clearSearch(); @@ -242,20 +248,26 @@ class Display { }, 69: /* e */ () => { - this.noteAdd(this.definitions[this.index], 'term-kanji'); + noteTryAdd('term-kanji'); }, 75: /* k */ () => { - this.noteAdd(this.definitions[this.index], 'term-kana'); + noteTryAdd('kanji'); + }, + + 82: /* r */ () => { + noteTryAdd('term-kana'); }, 80: /* p */ () => { - this.audioPlay(this.definitions[this.index]); + if (Display.adderButtonFind(this.index, 'kanji').length === 0) { + this.audioPlay(this.definitions[this.index]); + } } }; const handler = handlers[e.keyCode]; - if (handler && (e.altKey || !requireAlt.includes(e.keyCode))) { + if (handler && (e.altKey || !['e', 'k', 'p'].includes(e.keyCode))) { e.preventDefault(); handler(); } From 9d31801b73ad3f2a273f20aecda0e7157c481d46 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 25 Mar 2017 18:08:42 -0700 Subject: [PATCH 22/23] more hotkey work --- ext/bg/js/templates.js | 12 ++++++------ ext/mixed/js/display.js | 29 ++++++++++++++++++----------- tmpl/kanji.html | 8 ++++---- tmpl/terms.html | 10 +++++----- 4 files changed, 33 insertions(+), 26 deletions(-) diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js index f267da80..1afe124f 100644 --- a/ext/bg/js/templates.js +++ b/ext/bg/js/templates.js @@ -284,7 +284,7 @@ templates['fields.html'] = template({"1":function(container,depth0,helpers,parti templates['kanji.html'] = template({"1":function(container,depth0,helpers,partials,data) { var stack1, helper, alias1=depth0 != null ? depth0 : {}; - return "
\n
\n \n" + return "
\n
\n \n" + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.addable : depth0),{"name":"if","hash":{},"fn":container.program(2, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.source : depth0),{"name":"if","hash":{},"fn":container.program(4, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "
\n\n
" @@ -299,9 +299,9 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia + ((stack1 = helpers["if"].call(alias1,((stack1 = (depth0 != null ? depth0.glossary : depth0)) != null ? stack1["1"] : stack1),{"name":"if","hash":{},"fn":container.program(11, data, 0),"inverse":container.program(15, data, 0),"data":data})) != null ? stack1 : "") + "
\n
\n"; },"2":function(container,depth0,helpers,partials,data) { - return " \n"; + return " \n"; },"4":function(container,depth0,helpers,partials,data) { - return " \n"; + return " \n"; },"6":function(container,depth0,helpers,partials,data) { var stack1; @@ -442,7 +442,7 @@ templates['terms.html'] = template({"1":function(container,depth0,helpers,partia },"12":function(container,depth0,helpers,partials,data) { var stack1, alias1=depth0 != null ? depth0 : {}; - return "
\n
\n \n" + return "
\n
\n \n" + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.addable : depth0),{"name":"if","hash":{},"fn":container.program(13, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.playback : depth0),{"name":"if","hash":{},"fn":container.program(15, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "
\n\n" @@ -453,9 +453,9 @@ templates['terms.html'] = template({"1":function(container,depth0,helpers,partia + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.grouped : depth0),{"name":"if","hash":{},"fn":container.program(26, data, 0),"inverse":container.program(32, data, 0),"data":data})) != null ? stack1 : "") + "
\n
\n"; },"13":function(container,depth0,helpers,partials,data) { - return " \n \n"; + return " \n \n"; },"15":function(container,depth0,helpers,partials,data) { - return " \n"; + return " \n"; },"17":function(container,depth0,helpers,partials,data) { var stack1, helper, options, alias1=depth0 != null ? depth0 : {}, alias2=helpers.helperMissing, alias3="function", buffer = "
"; diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 639c2673..1b629dec 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -164,16 +164,7 @@ class Display { onSourceTerm(e) { e.preventDefault(); - - if (this.context && this.context.source) { - const context = { - url: this.context.source.url, - sentence: this.context.source.sentence, - index: this.context.source.index - }; - - this.showTermDefs(this.context.source.definitions, this.options, context); - } + this.sourceBack(); } onKanjiLookup(e) { @@ -247,6 +238,10 @@ class Display { this.entryScroll(this.index + 1, true); }, + 66: /* b */ () => { + this.sourceBack(); + }, + 69: /* e */ () => { noteTryAdd('term-kanji'); }, @@ -260,7 +255,7 @@ class Display { }, 80: /* p */ () => { - if (Display.adderButtonFind(this.index, 'kanji').length === 0) { + if ($('.entry').eq(this.index).data('type') === 'term') { this.audioPlay(this.definitions[this.index]); } } @@ -273,6 +268,18 @@ class Display { } } + sourceBack() { + if (this.context && this.context.source) { + const context = { + url: this.context.source.url, + sentence: this.context.source.sentence, + index: this.context.source.index + }; + + this.showTermDefs(this.context.source.definitions, this.options, context); + } + } + noteAdd(definition, mode) { this.spinner.show(); return this.definitionAdd(definition, mode).then(success => { diff --git a/tmpl/kanji.html b/tmpl/kanji.html index be5e8541..7a2df8db 100644 --- a/tmpl/kanji.html +++ b/tmpl/kanji.html @@ -1,12 +1,12 @@ {{#*inline "kanji"}} -
+
- + {{#if addable}} - + {{/if}} {{#if source}} - + {{/if}}
diff --git a/tmpl/terms.html b/tmpl/terms.html index f108da26..83b16106 100644 --- a/tmpl/terms.html +++ b/tmpl/terms.html @@ -18,15 +18,15 @@ {{/inline}} {{#*inline "term"}} -
+
- + {{#if addable}} - - + + {{/if}} {{#if playback}} - + {{/if}}
From 063f3d4dbf8c896f4f7b022cfae6e2b907769251 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 25 Mar 2017 18:18:31 -0700 Subject: [PATCH 23/23] version bump, finishing up keyboard shortcuts --- ext/bg/js/templates.js | 4 +-- ext/bg/popup.html | 6 ++-- ext/manifest.json | 2 +- ext/mixed/js/display.js | 62 +++++++++++++++++++++++++++++++---------- tmpl/kanji.html | 2 +- tmpl/terms.html | 2 +- 6 files changed, 56 insertions(+), 22 deletions(-) diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js index 1afe124f..0346e4c7 100644 --- a/ext/bg/js/templates.js +++ b/ext/bg/js/templates.js @@ -284,7 +284,7 @@ templates['fields.html'] = template({"1":function(container,depth0,helpers,parti templates['kanji.html'] = template({"1":function(container,depth0,helpers,partials,data) { var stack1, helper, alias1=depth0 != null ? depth0 : {}; - return "
\n
\n \n" + return "
\n
\n \n" + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.addable : depth0),{"name":"if","hash":{},"fn":container.program(2, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.source : depth0),{"name":"if","hash":{},"fn":container.program(4, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "
\n\n
" @@ -442,7 +442,7 @@ templates['terms.html'] = template({"1":function(container,depth0,helpers,partia },"12":function(container,depth0,helpers,partials,data) { var stack1, alias1=depth0 != null ? depth0 : {}; - return "
\n
\n \n" + return "
\n
\n \n" + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.addable : depth0),{"name":"if","hash":{},"fn":container.program(13, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.playback : depth0),{"name":"if","hash":{},"fn":container.program(15, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "
\n\n" diff --git a/ext/bg/popup.html b/ext/bg/popup.html index 22fc0d40..e223e241 100644 --- a/ext/bg/popup.html +++ b/ext/bg/popup.html @@ -18,12 +18,12 @@

- +

- - + +

diff --git a/ext/manifest.json b/ext/manifest.json index e759c4dc..ae7cf8e3 100644 --- a/ext/manifest.json +++ b/ext/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "Yomichan", - "version": "1.1.7", + "version": "1.1.8", "description": "Japanese dictionary with Anki integration", "icons": {"16": "mixed/img/icon16.png", "48": "mixed/img/icon48.png", "128": "mixed/img/icon128.png"}, diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 1b629dec..db14a43c 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -212,59 +212,93 @@ class Display { const handlers = { 27: /* escape */ () => { this.clearSearch(); + return true; }, 33: /* page up */ () => { - this.entryScroll(this.index - 3, true); + if (e.altKey) { + this.entryScroll(this.index - 3, true); + return true; + } }, 34: /* page down */ () => { - this.entryScroll(this.index + 3, true); + if (e.altKey) { + this.entryScroll(this.index + 3, true); + return true; + } }, 35: /* end */ () => { - this.entryScroll(this.definitions.length - 1, true); + if (e.altKey) { + this.entryScroll(this.definitions.length - 1, true); + return true; + } }, 36: /* home */ () => { - this.entryScroll(0, true); + if (e.altKey) { + this.entryScroll(0, true); + return true; + } }, 38: /* up */ () => { - this.entryScroll(this.index - 1, true); + if (e.altKey) { + this.entryScroll(this.index - 1, true); + return true; + } }, 40: /* down */ () => { - this.entryScroll(this.index + 1, true); + if (e.altKey) { + this.entryScroll(this.index + 1, true); + return true; + } }, 66: /* b */ () => { - this.sourceBack(); + if (e.altKey) { + this.sourceBack(); + return true; + } }, 69: /* e */ () => { - noteTryAdd('term-kanji'); + if (e.altKey) { + noteTryAdd('term-kanji'); + return true; + } }, 75: /* k */ () => { - noteTryAdd('kanji'); + if (e.altKey) { + noteTryAdd('kanji'); + return true; + } }, 82: /* r */ () => { - noteTryAdd('term-kana'); + if (e.altKey) { + noteTryAdd('term-kana'); + return true; + } }, 80: /* p */ () => { - if ($('.entry').eq(this.index).data('type') === 'term') { - this.audioPlay(this.definitions[this.index]); + if (e.altKey) { + if ($('.entry').eq(this.index).data('type') === 'term') { + this.audioPlay(this.definitions[this.index]); + } + + return true; } } }; const handler = handlers[e.keyCode]; - if (handler && (e.altKey || !['e', 'k', 'p'].includes(e.keyCode))) { + if (handler && handler()) { e.preventDefault(); - handler(); } } diff --git a/tmpl/kanji.html b/tmpl/kanji.html index 7a2df8db..acd79036 100644 --- a/tmpl/kanji.html +++ b/tmpl/kanji.html @@ -1,7 +1,7 @@ {{#*inline "kanji"}}
- + {{#if addable}} {{/if}} diff --git a/tmpl/terms.html b/tmpl/terms.html index 83b16106..dc50efe2 100644 --- a/tmpl/terms.html +++ b/tmpl/terms.html @@ -20,7 +20,7 @@ {{#*inline "term"}}
- + {{#if addable}}