From 57697ee2a09dd5ad0a567b7104e4a5ac9a4f1b23 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 18 Mar 2017 13:00:29 -0700 Subject: 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 ++++++++++++++++------ 4 files changed, 34 insertions(+), 13 deletions(-) (limited to 'ext/bg/js') 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}) { -- cgit v1.2.3 From ad313fd1825ed1b077ad9a59af9423e93032ce44 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 18 Mar 2017 17:53:21 -0700 Subject: 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 (limited to 'ext/bg/js') 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 00000000..bab7cc9b Binary files /dev/null and b/ext/mixed/img/entry-current.png differ 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}} -- cgit v1.2.3 From 6d55767191f50bceef86bf78df7d340f9c5971c7 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 18 Mar 2017 18:21:02 -0700 Subject: 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(-) (limited to 'ext/bg/js') 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}}
-- cgit v1.2.3 From 20d062329bfcdc0d7c5fd07f48071ae6524f9566 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 25 Mar 2017 10:46:59 -0700 Subject: 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(-) (limited to 'ext/bg/js') 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); +} -- cgit v1.2.3 From 83a6c30d0e68496bc7592b3adfa91ae536a487e1 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 25 Mar 2017 12:01:20 -0700 Subject: audio improvements --- ext/bg/js/yomichan.js | 21 ++++++++++++++++++++- ext/mixed/js/util.js | 15 +++++---------- 2 files changed, 25 insertions(+), 11 deletions(-) (limited to 'ext/bg/js') 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); } -- cgit v1.2.3 From ff3315ebf147a3e8d1cab5726724b20a2694aa73 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 25 Mar 2017 12:09:57 -0700 Subject: fixing reason sorting --- ext/bg/js/deinflector.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/bg/js') 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] : [] }]; } -- cgit v1.2.3 From b8d0788144974daab8d55c8de1af7515a291ba4f Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 25 Mar 2017 15:59:33 -0700 Subject: 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(-) (limited to 'ext/bg/js') 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 */ () => { - - }, - - 27: /* escape */ () => { - notifyParent('popupClose'); - }, - - 37: /* left */ () => { - notifyParent('scanLeft'); - }, + 221: /* ] */ () => { - 39: /* right */ () => { - notifyParent('scanRight'); } }; -- cgit v1.2.3 From bc2bf51a072af45ddc61a7f6b1c5cc3b94f8ad3e Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 25 Mar 2017 16:28:15 -0700 Subject: wip --- ext/bg/js/popup.js | 4 ++-- ext/bg/js/yomichan.js | 27 ++++++++++++++++++++++----- 2 files changed, 24 insertions(+), 7 deletions(-) (limited to 'ext/bg/js') 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(); } } -- cgit v1.2.3 From 218db0771fae0754a50cadc1891a042112b58699 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 25 Mar 2017 16:45:43 -0700 Subject: 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(-) (limited to 'ext/bg/js') 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; -- cgit v1.2.3 From 9d31801b73ad3f2a273f20aecda0e7157c481d46 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 25 Mar 2017 18:08:42 -0700 Subject: 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(-) (limited to 'ext/bg/js') 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}}
-- cgit v1.2.3 From 063f3d4dbf8c896f4f7b022cfae6e2b907769251 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 25 Mar 2017 18:18:31 -0700 Subject: 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(-) (limited to 'ext/bg/js') 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}} -- cgit v1.2.3