From 6e986bf1f5957be12ad610c627060f4d86eca98c Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 9 Jul 2017 16:29:52 -0700 Subject: cleanup --- ext/bg/js/util.js | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'ext/bg/js/util.js') diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js index cdd5ec31..b39b4b2f 100644 --- a/ext/bg/js/util.js +++ b/ext/bg/js/util.js @@ -43,6 +43,10 @@ function jpIsKana(c) { return wanakana.isKana(c); } +function jpKatakanaToHiragana(text) { + return wanakana._katakanaToHiragana(text); +} + /* * Commands -- cgit v1.2.3 From f694026827ab2ce3a884206f7494b98335137709 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Mon, 10 Jul 2017 14:53:06 -0700 Subject: move zip import to async --- ext/bg/js/database.js | 48 +++++++++++++++++++++++++++++++++++++- ext/bg/js/util.js | 64 --------------------------------------------------- 2 files changed, 47 insertions(+), 65 deletions(-) (limited to 'ext/bg/js/util.js') diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js index 9eed8ea3..45ba3d08 100644 --- a/ext/bg/js/database.js +++ b/ext/bg/js/database.js @@ -224,7 +224,53 @@ class Database { await this.db.kanji.bulkAdd(rows); }; - await zipLoadDb(archive, indexLoaded, termsLoaded, kanjiLoaded); + await Database.importDictionaryZip(archive, indexLoaded, termsLoaded, kanjiLoaded); return summary; } + + static async importDictionaryZip(archive, indexLoaded, termsLoaded, kanjiLoaded) { + const files = (await JSZip.loadAsync(archive)).files; + + const indexFile = files['index.json']; + if (!indexFile) { + throw 'no dictionary index found in archive'; + } + + const index = JSON.parse(await indexFile.async('string')); + if (!index.title || !index.version || !index.revision) { + throw 'unrecognized dictionary format'; + } + + await indexLoaded( + index.title, + index.version, + index.revision, + index.tagMeta || {}, + index.termBanks > 0, + index.kanjiBanks > 0 + ); + + const banksTotal = index.termBanks + index.kanjiBanks; + let banksLoaded = 0; + + for (let i = 1; i <= index.termBanks; ++i) { + const bankFile = files[`term_bank_${i}.json`]; + if (bankFile) { + const bank = JSON.parse(await bankFile.async('string')); + await termsLoaded(index.title, bank, banksTotal, banksLoaded++); + } else { + throw 'missing term bank file'; + } + } + + for (let i = 1; i <= index.kanjiBanks; ++i) { + const bankFile = files[`kanji_bank_${i}.json`]; + if (bankFile) { + const bank = JSON.parse(await bankFile.async('string')); + await kanjiLoaded(index.title, bank, banksTotal, banksLoaded++); + } else { + throw 'missing kanji bank file'; + } + } + } } diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js index b39b4b2f..1954e83b 100644 --- a/ext/bg/js/util.js +++ b/ext/bg/js/util.js @@ -455,70 +455,6 @@ function jsonLoadInt(url) { return jsonLoad(chrome.extension.getURL(url)); } -/* - * Zip - */ - -function zipLoadDb(archive, indexLoaded, termsLoaded, kanjiLoaded) { - return JSZip.loadAsync(archive).then(files => files.files).then(files => { - const indexFile = files['index.json']; - if (!indexFile) { - return Promise.reject('no dictionary index found in archive'); - } - - return indexFile.async('string').then(indexJson => { - const index = JSON.parse(indexJson); - if (!index.title || !index.version || !index.revision) { - return Promise.reject('unrecognized dictionary format'); - } - - return indexLoaded( - index.title, - index.version, - index.revision, - index.tagMeta || {}, - index.termBanks > 0, - index.kanjiBanks > 0 - ).then(() => index); - }).then(index => { - const loaders = []; - const banksTotal = index.termBanks + index.kanjiBanks; - let banksLoaded = 0; - - for (let i = 1; i <= index.termBanks; ++i) { - const bankFile = files[`term_bank_${i}.json`]; - if (!bankFile) { - return Promise.reject('missing term bank file'); - } - - loaders.push(() => bankFile.async('string').then(bankJson => { - const bank = JSON.parse(bankJson); - return termsLoaded(index.title, bank, banksTotal, banksLoaded++); - })); - } - - for (let i = 1; i <= index.kanjiBanks; ++i) { - const bankFile = files[`kanji_bank_${i}.json`]; - if (!bankFile) { - return Promise.reject('missing kanji bank file'); - } - - loaders.push(() => bankFile.async('string').then(bankJson => { - const bank = JSON.parse(bankJson); - return kanjiLoaded(index.title, bank, banksTotal, banksLoaded++); - })); - } - - let chain = Promise.resolve(); - for (const loader of loaders) { - chain = chain.then(loader); - } - - return chain; - }); - }); -} - /* * Helpers */ -- cgit v1.2.3 From 28bc1449d1b2260df2970318982385b0d8456c54 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Mon, 10 Jul 2017 15:00:38 -0700 Subject: cleanup --- ext/bg/js/translator.js | 22 +++++++++++++++++++++- ext/bg/js/util.js | 26 -------------------------- 2 files changed, 21 insertions(+), 27 deletions(-) (limited to 'ext/bg/js/util.js') diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index 84a6e1d7..dfe54623 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -30,7 +30,8 @@ class Translator { } if (!this.deinflector) { - const reasons = await jsonLoadInt('/bg/lang/deinflect.json'); + const url = chrome.extension.getURL('/bg/lang/deinflect.json'); + const reasons = await Translator.loadRules(url); this.deinflector = new Deinflector(reasons); } } @@ -127,4 +128,23 @@ class Translator { return definitions; } + + + static loadRules(url) { + return new Promise((resolve, reject) => { + const xhr = new XMLHttpRequest(); + xhr.overrideMimeType('application/json'); + xhr.addEventListener('load', () => resolve(xhr.responseText)); + xhr.addEventListener('error', () => reject('failed to execute network request')); + xhr.open('GET', url); + xhr.send(); + }).then(responseText => { + try { + return JSON.parse(responseText); + } + catch (e) { + return Promise.reject('invalid JSON response'); + } + }); + } } diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js index 1954e83b..b8a60217 100644 --- a/ext/bg/js/util.js +++ b/ext/bg/js/util.js @@ -429,32 +429,6 @@ function dictFieldFormat(field, definition, mode, options) { } -/* - * Json - */ - -function jsonLoad(url) { - return new Promise((resolve, reject) => { - const xhr = new XMLHttpRequest(); - xhr.overrideMimeType('application/json'); - xhr.addEventListener('load', () => resolve(xhr.responseText)); - xhr.addEventListener('error', () => reject('failed to execute network request')); - xhr.open('GET', url); - xhr.send(); - }).then(responseText => { - try { - return JSON.parse(responseText); - } - catch (e) { - return Promise.reject('invalid JSON response'); - } - }); -} - -function jsonLoadInt(url) { - return jsonLoad(chrome.extension.getURL(url)); -} - /* * Helpers */ -- cgit v1.2.3 From b0cdf59bd8dae8f44362b14bdf19b243514e31d3 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Mon, 10 Jul 2017 16:24:31 -0700 Subject: move anki to async --- ext/bg/js/anki-connect.js | 69 +++++++++++++++++------------------------------ ext/bg/js/anki-null.js | 24 ++++++++--------- ext/bg/js/translator.js | 20 +------------- ext/bg/js/util.js | 25 +++++++++++++++++ 4 files changed, 63 insertions(+), 75 deletions(-) (limited to 'ext/bg/js/util.js') diff --git a/ext/bg/js/anki-connect.js b/ext/bg/js/anki-connect.js index 173feefd..a4d8ba3f 100644 --- a/ext/bg/js/anki-connect.js +++ b/ext/bg/js/anki-connect.js @@ -20,69 +20,50 @@ class AnkiConnect { constructor(server) { this.server = server; - this.asyncPools = {}; this.localVersion = 2; - this.remoteVersion = null; + this.remoteVersion = 0; } - addNote(note) { - return this.checkVersion().then(() => this.ankiInvoke('addNote', {note})); + async addNote(note) { + await this.checkVersion(); + return await this.ankiInvoke('addNote', {note}); } - canAddNotes(notes) { - return this.checkVersion().then(() => this.ankiInvoke('canAddNotes', {notes}, 'notes')); + async canAddNotes(notes) { + await this.checkVersion(); + return await this.ankiInvoke('canAddNotes', {notes}); } - getDeckNames() { - return this.checkVersion().then(() => this.ankiInvoke('deckNames', {})); + async getDeckNames() { + await this.checkVersion(); + return await this.ankiInvoke('deckNames'); } - getModelNames() { - return this.checkVersion().then(() => this.ankiInvoke('modelNames', {})); + async getModelNames() { + await this.checkVersion(); + return await this.ankiInvoke('modelNames'); } - getModelFieldNames(modelName) { - return this.checkVersion().then(() => this.ankiInvoke('modelFieldNames', {modelName})); + async getModelFieldNames(modelName) { + await this.checkVersion(); + return await this.ankiInvoke('modelFieldNames', {modelName}); } - guiBrowse(query) { - return this.checkVersion().then(() => this.ankiInvoke('guiBrowse', {query})); + async guiBrowse(query) { + await this.checkVersion(); + return await this.ankiInvoke('guiBrowse', {query}); } - checkVersion() { - if (this.localVersion === this.remoteVersion) { - return Promise.resolve(true); - } - - return this.ankiInvoke('version', {}, null).then(version => { - this.remoteVersion = version; + async checkVersion() { + if (this.remoteVersion < this.localVersion) { + this.remoteVersion = await this.ankiInvoke('version'); if (this.remoteVersion < this.localVersion) { return Promise.reject('extension and plugin versions incompatible'); } - }); + } } - ankiInvoke(action, params, pool) { - return new Promise((resolve, reject) => { - if (pool && this.asyncPools.hasOwnProperty(pool)) { - this.asyncPools[pool].abort(); - } - - const xhr = new XMLHttpRequest(); - xhr.addEventListener('loadend', () => { - if (pool) { - delete this.asyncPools[pool]; - } - - if (xhr.responseText) { - resolve(JSON.parse(xhr.responseText)); - } else { - reject('unable to connect to plugin'); - } - }); - - xhr.open('POST', this.server); - xhr.send(JSON.stringify({action, params})); - }); + ankiInvoke(action, params) { + return jsonRequest(this.server, 'POST', {action, params, version: this.localVersion}); } } diff --git a/ext/bg/js/anki-null.js b/ext/bg/js/anki-null.js index 8dad6915..d82f0e68 100644 --- a/ext/bg/js/anki-null.js +++ b/ext/bg/js/anki-null.js @@ -18,27 +18,27 @@ class AnkiNull { - addNote(note) { - return Promise.reject('unsupported action'); + async addNote(note) { + return null; } - canAddNotes(notes) { - return Promise.resolve([]); + async canAddNotes(notes) { + return []; } - getDeckNames() { - return Promise.resolve([]); + async getDeckNames() { + return []; } - getModelNames() { - return Promise.resolve([]); + async getModelNames() { + return []; } - getModelFieldNames(modelName) { - return Promise.resolve([]); + async getModelFieldNames(modelName) { + return []; } - guiBrowse(query) { - return Promise.resolve([]); + async guiBrowse(query) { + return []; } } diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index aa11ea63..9232e529 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -31,7 +31,7 @@ class Translator { if (!this.deinflector) { const url = chrome.extension.getURL('/bg/lang/deinflect.json'); - const reasons = await Translator.loadRules(url); + const reasons = await jsonRequest(url, 'GET'); this.deinflector = new Deinflector(reasons); } } @@ -124,22 +124,4 @@ class Translator { return definitions; } - - static loadRules(url) { - return new Promise((resolve, reject) => { - const xhr = new XMLHttpRequest(); - xhr.overrideMimeType('application/json'); - xhr.addEventListener('load', () => resolve(xhr.responseText)); - xhr.addEventListener('error', () => reject('failed to execute network request')); - xhr.open('GET', url); - xhr.send(); - }).then(responseText => { - try { - return JSON.parse(responseText); - } - catch (e) { - return Promise.reject('invalid JSON response'); - } - }); - } } diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js index b8a60217..4f907923 100644 --- a/ext/bg/js/util.js +++ b/ext/bg/js/util.js @@ -428,6 +428,31 @@ function dictFieldFormat(field, definition, mode, options) { return field; } +/* + * JSON + */ + +function jsonRequest(url, action, params) { + return new Promise((resolve, reject) => { + const xhr = new XMLHttpRequest(); + xhr.overrideMimeType('application/json'); + xhr.addEventListener('load', () => resolve(xhr.responseText)); + xhr.addEventListener('error', () => reject('failed to execute network request')); + xhr.open(action, url); + if (params) { + xhr.send(JSON.stringify(params)); + } else { + xhr.send(); + } + }).then(responseText => { + try { + return JSON.parse(responseText); + } + catch (e) { + return Promise.reject('invalid JSON response'); + } + }); +} /* * Helpers -- cgit v1.2.3 From ede139097c670f16ca3c332d8a79e9009b23bfac Mon Sep 17 00:00:00 2001 From: dequis Date: Sun, 16 Jul 2017 05:05:23 -0300 Subject: Add glossary-brief anki field, like glossary but without tags --- README.md | 1 + ext/bg/js/options.js | 1 + ext/bg/js/templates.js | 239 ++++++++++++++++++++++++++----------------------- ext/bg/js/util.js | 1 + tmpl/fields.html | 20 +++-- 5 files changed, 143 insertions(+), 119 deletions(-) (limited to 'ext/bg/js/util.js') diff --git a/README.md b/README.md index c32c867f..6ac97eea 100644 --- a/README.md +++ b/README.md @@ -132,6 +132,7 @@ Flashcard fields can be configured with the following steps: `{expression}` | Term expressed as Kanji (will be displayed in Kana if Kanji is not available). `{furigana}` | Term expressed as Kanji with Furigana displayed above it (e.g. 日本語にほんご). `{glossary}` | List of definitions for the term (output format depends on whether running in *grouped* mode). + `{glossary-brief}` | Shorter version of `{glossary}`, without `{tags}` `{reading}` | Kana reading for the term (empty for terms where the expression is the reading). `{sentence}` | Sentence, quote, or phrase in which the term appears in the source content. `{tags}` | Grammar and usage tags providing information about the term (unavailable in *grouped* mode). diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js index 728ddae4..e105f1b2 100644 --- a/ext/bg/js/options.js +++ b/ext/bg/js/options.js @@ -351,6 +351,7 @@ function ankiFieldsPopulate(element, options) { 'expression', 'furigana', 'glossary', + 'glossary-brief', 'reading', 'sentence', 'tags', diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js index 50686ed4..6fa1dad0 100644 --- a/ext/bg/js/templates.js +++ b/ext/bg/js/templates.js @@ -24,106 +24,114 @@ templates['dictionary.html'] = template({"1":function(container,depth0,helpers,p templates['fields.html'] = template({"1":function(container,depth0,helpers,partials,data) { var stack1; - return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.html : depth0),{"name":"if","hash":{},"fn":container.program(2, data, 0),"inverse":container.program(14, data, 0),"data":data})) != null ? stack1 : ""); + return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.html : depth0),{"name":"if","hash":{},"fn":container.program(2, data, 0),"inverse":container.program(15, data, 0),"data":data})) != null ? stack1 : ""); },"2":function(container,depth0,helpers,partials,data) { var stack1, alias1=depth0 != null ? depth0 : {}; - return ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.tags : depth0),{"name":"if","hash":{},"fn":container.program(3, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + ((stack1 = helpers["if"].call(alias1,((stack1 = (depth0 != null ? depth0.glossary : depth0)) != null ? stack1["1"] : stack1),{"name":"if","hash":{},"fn":container.program(7, data, 0),"inverse":container.program(11, data, 0),"data":data})) != null ? stack1 : ""); + return ((stack1 = helpers.unless.call(alias1,(depth0 != null ? depth0.brief : depth0),{"name":"unless","hash":{},"fn":container.program(3, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers["if"].call(alias1,((stack1 = (depth0 != null ? depth0.glossary : depth0)) != null ? stack1["1"] : stack1),{"name":"if","hash":{},"fn":container.program(8, data, 0),"inverse":container.program(12, data, 0),"data":data})) != null ? stack1 : ""); },"3":function(container,depth0,helpers,partials,data) { var stack1; + return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.tags : depth0),{"name":"if","hash":{},"fn":container.program(4, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : ""); +},"4":function(container,depth0,helpers,partials,data) { + var stack1; + return "(" - + ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.tags : depth0),{"name":"each","hash":{},"fn":container.program(4, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.tags : depth0),{"name":"each","hash":{},"fn":container.program(5, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + ") "; -},"4":function(container,depth0,helpers,partials,data) { +},"5":function(container,depth0,helpers,partials,data) { var stack1, helper, alias1=depth0 != null ? depth0 : {}; return container.escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(alias1,{"name":"name","hash":{},"data":data}) : helper))) - + ((stack1 = helpers.unless.call(alias1,(data && data.last),{"name":"unless","hash":{},"fn":container.program(5, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : ""); -},"5":function(container,depth0,helpers,partials,data) { + + ((stack1 = helpers.unless.call(alias1,(data && data.last),{"name":"unless","hash":{},"fn":container.program(6, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : ""); +},"6":function(container,depth0,helpers,partials,data) { return ", "; -},"7":function(container,depth0,helpers,partials,data) { +},"8":function(container,depth0,helpers,partials,data) { var stack1; return "
    " - + ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.glossary : depth0),{"name":"each","hash":{},"fn":container.program(8, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.glossary : depth0),{"name":"each","hash":{},"fn":container.program(9, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "
"; -},"8":function(container,depth0,helpers,partials,data) { +},"9":function(container,depth0,helpers,partials,data) { var stack1, helper, options, buffer = "
  • "; - stack1 = ((helper = (helper = helpers.multiLine || (depth0 != null ? depth0.multiLine : depth0)) != null ? helper : helpers.helperMissing),(options={"name":"multiLine","hash":{},"fn":container.program(9, data, 0),"inverse":container.noop,"data":data}),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : {},options) : helper)); + stack1 = ((helper = (helper = helpers.multiLine || (depth0 != null ? depth0.multiLine : depth0)) != null ? helper : helpers.helperMissing),(options={"name":"multiLine","hash":{},"fn":container.program(10, data, 0),"inverse":container.noop,"data":data}),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : {},options) : helper)); if (!helpers.multiLine) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)} if (stack1 != null) { buffer += stack1; } return buffer + "
  • "; -},"9":function(container,depth0,helpers,partials,data) { +},"10":function(container,depth0,helpers,partials,data) { return container.escapeExpression(container.lambda(depth0, depth0)); -},"11":function(container,depth0,helpers,partials,data) { +},"12":function(container,depth0,helpers,partials,data) { var stack1, helper, options, buffer = ""; - stack1 = ((helper = (helper = helpers.multiLine || (depth0 != null ? depth0.multiLine : depth0)) != null ? helper : helpers.helperMissing),(options={"name":"multiLine","hash":{},"fn":container.program(12, data, 0),"inverse":container.noop,"data":data}),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : {},options) : helper)); + stack1 = ((helper = (helper = helpers.multiLine || (depth0 != null ? depth0.multiLine : depth0)) != null ? helper : helpers.helperMissing),(options={"name":"multiLine","hash":{},"fn":container.program(13, data, 0),"inverse":container.noop,"data":data}),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : {},options) : helper)); if (!helpers.multiLine) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)} if (stack1 != null) { buffer += stack1; } return buffer; -},"12":function(container,depth0,helpers,partials,data) { +},"13":function(container,depth0,helpers,partials,data) { var stack1; return container.escapeExpression(container.lambda(((stack1 = (depth0 != null ? depth0.glossary : depth0)) != null ? stack1["0"] : stack1), depth0)); -},"14":function(container,depth0,helpers,partials,data) { +},"15":function(container,depth0,helpers,partials,data) { var stack1, alias1=depth0 != null ? depth0 : {}; - return ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.tags : depth0),{"name":"if","hash":{},"fn":container.program(15, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + ((stack1 = helpers["if"].call(alias1,((stack1 = (depth0 != null ? depth0.glossary : depth0)) != null ? stack1["1"] : stack1),{"name":"if","hash":{},"fn":container.program(17, data, 0),"inverse":container.program(12, data, 0),"data":data})) != null ? stack1 : ""); -},"15":function(container,depth0,helpers,partials,data) { + return ((stack1 = helpers.unless.call(alias1,(depth0 != null ? depth0.brief : depth0),{"name":"unless","hash":{},"fn":container.program(16, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers["if"].call(alias1,((stack1 = (depth0 != null ? depth0.glossary : depth0)) != null ? stack1["1"] : stack1),{"name":"if","hash":{},"fn":container.program(19, data, 0),"inverse":container.program(13, data, 0),"data":data})) != null ? stack1 : ""); +},"16":function(container,depth0,helpers,partials,data) { + var stack1; + + return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.tags : depth0),{"name":"if","hash":{},"fn":container.program(17, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : ""); +},"17":function(container,depth0,helpers,partials,data) { var stack1; return "(" - + ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.tags : depth0),{"name":"each","hash":{},"fn":container.program(4, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.tags : depth0),{"name":"each","hash":{},"fn":container.program(5, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + ") "; -},"17":function(container,depth0,helpers,partials,data) { +},"19":function(container,depth0,helpers,partials,data) { var stack1; - return ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.glossary : depth0),{"name":"each","hash":{},"fn":container.program(18, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : ""); -},"18":function(container,depth0,helpers,partials,data) { + return ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.glossary : depth0),{"name":"each","hash":{},"fn":container.program(20, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : ""); +},"20":function(container,depth0,helpers,partials,data) { var stack1; return container.escapeExpression(container.lambda(depth0, depth0)) - + ((stack1 = helpers.unless.call(depth0 != null ? depth0 : {},(data && data.last),{"name":"unless","hash":{},"fn":container.program(5, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : ""); -},"20":function(container,depth0,helpers,partials,data) { - return ""; + + ((stack1 = helpers.unless.call(depth0 != null ? depth0 : {},(data && data.last),{"name":"unless","hash":{},"fn":container.program(6, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : ""); },"22":function(container,depth0,helpers,partials,data) { + return ""; +},"24":function(container,depth0,helpers,partials,data) { var stack1; return container.escapeExpression(container.lambda(((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.character : stack1), depth0)); -},"24":function(container,depth0,helpers,partials,data) { +},"26":function(container,depth0,helpers,partials,data) { var stack1; return container.escapeExpression(container.lambda(((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.dictionary : stack1), depth0)); -},"26":function(container,depth0,helpers,partials,data) { +},"28":function(container,depth0,helpers,partials,data) { var stack1; - return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.modeTermKana : depth0),{"name":"if","hash":{},"fn":container.program(27, data, 0),"inverse":container.program(30, data, 0),"data":data})) != null ? stack1 : ""); -},"27":function(container,depth0,helpers,partials,data) { + return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.modeTermKana : depth0),{"name":"if","hash":{},"fn":container.program(29, data, 0),"inverse":container.program(32, data, 0),"data":data})) != null ? stack1 : ""); +},"29":function(container,depth0,helpers,partials,data) { var stack1; - return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.reading : stack1),{"name":"if","hash":{},"fn":container.program(28, data, 0),"inverse":container.program(30, data, 0),"data":data})) != null ? stack1 : ""); -},"28":function(container,depth0,helpers,partials,data) { + return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.reading : stack1),{"name":"if","hash":{},"fn":container.program(30, data, 0),"inverse":container.program(32, data, 0),"data":data})) != null ? stack1 : ""); +},"30":function(container,depth0,helpers,partials,data) { var stack1; return container.escapeExpression(container.lambda(((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.reading : stack1), depth0)); -},"30":function(container,depth0,helpers,partials,data) { +},"32":function(container,depth0,helpers,partials,data) { var stack1; return container.escapeExpression(container.lambda(((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.expression : stack1), depth0)); -},"32":function(container,depth0,helpers,partials,data) { +},"34":function(container,depth0,helpers,partials,data) { var stack1; - return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.html : depth0),{"name":"if","hash":{},"fn":container.program(33, data, 0),"inverse":container.program(36, data, 0),"data":data})) != null ? stack1 : ""); -},"33":function(container,depth0,helpers,partials,data) { + return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.html : depth0),{"name":"if","hash":{},"fn":container.program(35, data, 0),"inverse":container.program(38, data, 0),"data":data})) != null ? stack1 : ""); +},"35":function(container,depth0,helpers,partials,data) { var stack1; - return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.reading : stack1),{"name":"if","hash":{},"fn":container.program(34, data, 0),"inverse":container.program(30, data, 0),"data":data})) != null ? stack1 : ""); -},"34":function(container,depth0,helpers,partials,data) { + return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.reading : stack1),{"name":"if","hash":{},"fn":container.program(36, data, 0),"inverse":container.program(32, data, 0),"data":data})) != null ? stack1 : ""); +},"36":function(container,depth0,helpers,partials,data) { var stack1, alias1=container.lambda, alias2=container.escapeExpression; return "" @@ -131,147 +139,151 @@ templates['fields.html'] = template({"1":function(container,depth0,helpers,parti + "" + alias2(alias1(((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.reading : stack1), depth0)) + ""; -},"36":function(container,depth0,helpers,partials,data) { +},"38":function(container,depth0,helpers,partials,data) { var stack1; - return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.reading : stack1),{"name":"if","hash":{},"fn":container.program(37, data, 0),"inverse":container.program(30, data, 0),"data":data})) != null ? stack1 : ""); -},"37":function(container,depth0,helpers,partials,data) { + return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.reading : stack1),{"name":"if","hash":{},"fn":container.program(39, data, 0),"inverse":container.program(32, data, 0),"data":data})) != null ? stack1 : ""); +},"39":function(container,depth0,helpers,partials,data) { var stack1, alias1=container.lambda, alias2=container.escapeExpression; return alias2(alias1(((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.expression : stack1), depth0)) + " [" + alias2(alias1(((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.reading : stack1), depth0)) + "]"; -},"39":function(container,depth0,helpers,partials,data,blockParams,depths) { +},"41":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1, alias1=depth0 != null ? depth0 : {}; - return ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.html : depth0),{"name":"if","hash":{},"fn":container.program(40, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.modeKanji : depth0),{"name":"if","hash":{},"fn":container.program(42, data, 0, blockParams, depths),"inverse":container.program(51, data, 0, blockParams, depths),"data":data})) != null ? stack1 : "") - + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.html : depth0),{"name":"if","hash":{},"fn":container.program(64, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : ""); -},"40":function(container,depth0,helpers,partials,data) { - return "
    "; + return ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.html : depth0),{"name":"if","hash":{},"fn":container.program(42, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.modeKanji : depth0),{"name":"if","hash":{},"fn":container.program(44, data, 0, blockParams, depths),"inverse":container.program(53, data, 0, blockParams, depths),"data":data})) != null ? stack1 : "") + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.html : depth0),{"name":"if","hash":{},"fn":container.program(66, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : ""); },"42":function(container,depth0,helpers,partials,data) { + return "
    "; +},"44":function(container,depth0,helpers,partials,data) { var stack1; - return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},((stack1 = ((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.glossary : stack1)) != null ? stack1["1"] : stack1),{"name":"if","hash":{},"fn":container.program(43, data, 0),"inverse":container.program(49, data, 0),"data":data})) != null ? stack1 : ""); -},"43":function(container,depth0,helpers,partials,data) { + return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},((stack1 = ((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.glossary : stack1)) != null ? stack1["1"] : stack1),{"name":"if","hash":{},"fn":container.program(45, data, 0),"inverse":container.program(51, data, 0),"data":data})) != null ? stack1 : ""); +},"45":function(container,depth0,helpers,partials,data) { var stack1; - return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.html : depth0),{"name":"if","hash":{},"fn":container.program(44, data, 0),"inverse":container.program(47, data, 0),"data":data})) != null ? stack1 : ""); -},"44":function(container,depth0,helpers,partials,data) { + return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.html : depth0),{"name":"if","hash":{},"fn":container.program(46, data, 0),"inverse":container.program(49, data, 0),"data":data})) != null ? stack1 : ""); +},"46":function(container,depth0,helpers,partials,data) { var stack1; return "
      " - + ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.glossary : stack1),{"name":"each","hash":{},"fn":container.program(45, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.glossary : stack1),{"name":"each","hash":{},"fn":container.program(47, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "
    "; -},"45":function(container,depth0,helpers,partials,data) { +},"47":function(container,depth0,helpers,partials,data) { return "
  • " + container.escapeExpression(container.lambda(depth0, depth0)) + "
  • "; -},"47":function(container,depth0,helpers,partials,data) { +},"49":function(container,depth0,helpers,partials,data) { var stack1; - return ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.glossary : stack1),{"name":"each","hash":{},"fn":container.program(18, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : ""); -},"49":function(container,depth0,helpers,partials,data) { + return ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.glossary : stack1),{"name":"each","hash":{},"fn":container.program(20, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : ""); +},"51":function(container,depth0,helpers,partials,data) { var stack1; return container.escapeExpression(container.lambda(((stack1 = ((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.glossary : stack1)) != null ? stack1["0"] : stack1), depth0)); -},"51":function(container,depth0,helpers,partials,data,blockParams,depths) { +},"53":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; - return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.group : depth0),{"name":"if","hash":{},"fn":container.program(52, data, 0, blockParams, depths),"inverse":container.program(62, data, 0, blockParams, depths),"data":data})) != null ? stack1 : ""); -},"52":function(container,depth0,helpers,partials,data,blockParams,depths) { + return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.group : depth0),{"name":"if","hash":{},"fn":container.program(54, data, 0, blockParams, depths),"inverse":container.program(64, data, 0, blockParams, depths),"data":data})) != null ? stack1 : ""); +},"54":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; - return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},((stack1 = ((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.definitions : stack1)) != null ? stack1["1"] : stack1),{"name":"if","hash":{},"fn":container.program(53, data, 0, blockParams, depths),"inverse":container.program(60, data, 0, blockParams, depths),"data":data})) != null ? stack1 : ""); -},"53":function(container,depth0,helpers,partials,data,blockParams,depths) { + return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},((stack1 = ((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.definitions : stack1)) != null ? stack1["1"] : stack1),{"name":"if","hash":{},"fn":container.program(55, data, 0, blockParams, depths),"inverse":container.program(62, data, 0, blockParams, depths),"data":data})) != null ? stack1 : ""); +},"55":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; - return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.html : depth0),{"name":"if","hash":{},"fn":container.program(54, data, 0, blockParams, depths),"inverse":container.program(57, data, 0, blockParams, depths),"data":data})) != null ? stack1 : ""); -},"54":function(container,depth0,helpers,partials,data,blockParams,depths) { + return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.html : depth0),{"name":"if","hash":{},"fn":container.program(56, data, 0, blockParams, depths),"inverse":container.program(59, data, 0, blockParams, depths),"data":data})) != null ? stack1 : ""); +},"56":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; return "
      " - + ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.definitions : stack1),{"name":"each","hash":{},"fn":container.program(55, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.definitions : stack1),{"name":"each","hash":{},"fn":container.program(57, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "
    "; -},"55":function(container,depth0,helpers,partials,data,blockParams,depths) { +},"57":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; return "
  • " - + ((stack1 = container.invokePartial(partials["glossary-single"],depth0,{"name":"glossary-single","hash":{"html":(depths[1] != null ? depths[1].html : depths[1])},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "") + + ((stack1 = container.invokePartial(partials["glossary-single"],depth0,{"name":"glossary-single","hash":{"brief":(depths[1] != null ? depths[1].brief : depths[1]),"html":(depths[1] != null ? depths[1].html : depths[1])},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "") + "
  • "; -},"57":function(container,depth0,helpers,partials,data,blockParams,depths) { +},"59":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; - return ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.definitions : stack1),{"name":"each","hash":{},"fn":container.program(58, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : ""); -},"58":function(container,depth0,helpers,partials,data,blockParams,depths) { + return ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.definitions : stack1),{"name":"each","hash":{},"fn":container.program(60, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : ""); +},"60":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; return " * " - + ((stack1 = container.invokePartial(partials["glossary-single"],depth0,{"name":"glossary-single","hash":{"html":(depths[1] != null ? depths[1].html : depths[1])},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : ""); -},"60":function(container,depth0,helpers,partials,data) { - var stack1; - - return ((stack1 = container.invokePartial(partials["glossary-single"],((stack1 = ((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.definitions : stack1)) != null ? stack1["0"] : stack1),{"name":"glossary-single","hash":{"html":(depth0 != null ? depth0.html : depth0)},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : ""); + + ((stack1 = container.invokePartial(partials["glossary-single"],depth0,{"name":"glossary-single","hash":{"brief":(depths[1] != null ? depths[1].brief : depths[1]),"html":(depths[1] != null ? depths[1].html : depths[1])},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : ""); },"62":function(container,depth0,helpers,partials,data) { var stack1; - return ((stack1 = container.invokePartial(partials["glossary-single"],(depth0 != null ? depth0.definition : depth0),{"name":"glossary-single","hash":{"html":(depth0 != null ? depth0.html : depth0)},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : ""); + return ((stack1 = container.invokePartial(partials["glossary-single"],((stack1 = ((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.definitions : stack1)) != null ? stack1["0"] : stack1),{"name":"glossary-single","hash":{"brief":(depth0 != null ? depth0.brief : depth0),"html":(depth0 != null ? depth0.html : depth0)},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : ""); },"64":function(container,depth0,helpers,partials,data) { - return "
    "; -},"66":function(container,depth0,helpers,partials,data) { var stack1; - return ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.kunyomi : stack1),{"name":"each","hash":{},"fn":container.program(18, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : ""); + return ((stack1 = container.invokePartial(partials["glossary-single"],(depth0 != null ? depth0.definition : depth0),{"name":"glossary-single","hash":{"brief":(depth0 != null ? depth0.brief : depth0),"html":(depth0 != null ? depth0.html : depth0)},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : ""); +},"66":function(container,depth0,helpers,partials,data) { + return "
    "; },"68":function(container,depth0,helpers,partials,data) { var stack1; - return ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.onyomi : stack1),{"name":"each","hash":{},"fn":container.program(18, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : ""); + return ((stack1 = container.invokePartial(partials.glossary,depth0,{"name":"glossary","hash":{"brief":true},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : ""); },"70":function(container,depth0,helpers,partials,data) { var stack1; - return ((stack1 = helpers.unless.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.modeTermKana : depth0),{"name":"unless","hash":{},"fn":container.program(28, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : ""); + return ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.kunyomi : stack1),{"name":"each","hash":{},"fn":container.program(20, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : ""); },"72":function(container,depth0,helpers,partials,data) { var stack1; - return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.cloze : stack1),{"name":"if","hash":{},"fn":container.program(73, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : ""); -},"73":function(container,depth0,helpers,partials,data) { + return ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.onyomi : stack1),{"name":"each","hash":{},"fn":container.program(20, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : ""); +},"74":function(container,depth0,helpers,partials,data) { + var stack1; + + return ((stack1 = helpers.unless.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.modeTermKana : depth0),{"name":"unless","hash":{},"fn":container.program(30, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : ""); +},"76":function(container,depth0,helpers,partials,data) { + var stack1; + + return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.cloze : stack1),{"name":"if","hash":{},"fn":container.program(77, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : ""); +},"77":function(container,depth0,helpers,partials,data) { var stack1; return container.escapeExpression(container.lambda(((stack1 = ((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.cloze : stack1)) != null ? stack1.sentence : stack1), depth0)); -},"75":function(container,depth0,helpers,partials,data) { +},"79":function(container,depth0,helpers,partials,data) { var stack1; - return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.cloze : stack1),{"name":"if","hash":{},"fn":container.program(76, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : ""); -},"76":function(container,depth0,helpers,partials,data) { + return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.cloze : stack1),{"name":"if","hash":{},"fn":container.program(80, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : ""); +},"80":function(container,depth0,helpers,partials,data) { var stack1; return container.escapeExpression(container.lambda(((stack1 = ((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.cloze : stack1)) != null ? stack1.prefix : stack1), depth0)); -},"78":function(container,depth0,helpers,partials,data) { +},"82":function(container,depth0,helpers,partials,data) { var stack1; - return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.cloze : stack1),{"name":"if","hash":{},"fn":container.program(79, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : ""); -},"79":function(container,depth0,helpers,partials,data) { + return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.cloze : stack1),{"name":"if","hash":{},"fn":container.program(83, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : ""); +},"83":function(container,depth0,helpers,partials,data) { var stack1; return container.escapeExpression(container.lambda(((stack1 = ((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.cloze : stack1)) != null ? stack1.body : stack1), depth0)); -},"81":function(container,depth0,helpers,partials,data) { +},"85":function(container,depth0,helpers,partials,data) { var stack1; - return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.cloze : stack1),{"name":"if","hash":{},"fn":container.program(82, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : ""); -},"82":function(container,depth0,helpers,partials,data) { + return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.cloze : stack1),{"name":"if","hash":{},"fn":container.program(86, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : ""); +},"86":function(container,depth0,helpers,partials,data) { var stack1; return container.escapeExpression(container.lambda(((stack1 = ((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.cloze : stack1)) != null ? stack1.suffix : stack1), depth0)); -},"84":function(container,depth0,helpers,partials,data) { +},"88":function(container,depth0,helpers,partials,data) { var stack1; - return ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.tags : stack1),{"name":"each","hash":{},"fn":container.program(4, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : ""); -},"86":function(container,depth0,helpers,partials,data) { + return ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.tags : stack1),{"name":"each","hash":{},"fn":container.program(5, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : ""); +},"90":function(container,depth0,helpers,partials,data) { var stack1; - return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.html : depth0),{"name":"if","hash":{},"fn":container.program(87, data, 0),"inverse":container.program(89, data, 0),"data":data})) != null ? stack1 : ""); -},"87":function(container,depth0,helpers,partials,data) { + return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.html : depth0),{"name":"if","hash":{},"fn":container.program(91, data, 0),"inverse":container.program(93, data, 0),"data":data})) != null ? stack1 : ""); +},"91":function(container,depth0,helpers,partials,data) { var stack1, alias1=container.lambda, alias2=container.escapeExpression; return "" + alias2(alias1(((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.url : stack1), depth0)) + ""; -},"89":function(container,depth0,helpers,partials,data) { +},"93":function(container,depth0,helpers,partials,data) { var stack1; return container.escapeExpression(container.lambda(((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.url : stack1), depth0)); },"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; - return "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + return "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ((stack1 = container.invokePartial(helpers.lookup.call(depth0 != null ? depth0 : {},depth0,"marker",{"name":"lookup","hash":{},"data":data}),depth0,{"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : ""); },"main_d": function(fn, props, container, depth0, data, blockParams, depths) { var decorators = container.decorators; fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(1, data, 0, blockParams, depths),"inverse":container.noop,"args":["glossary-single"],"data":data}) || fn; - fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(20, data, 0, blockParams, depths),"inverse":container.noop,"args":["audio"],"data":data}) || fn; - fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(22, data, 0, blockParams, depths),"inverse":container.noop,"args":["character"],"data":data}) || fn; - fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(24, data, 0, blockParams, depths),"inverse":container.noop,"args":["dictionary"],"data":data}) || fn; - fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(26, data, 0, blockParams, depths),"inverse":container.noop,"args":["expression"],"data":data}) || fn; - fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(32, data, 0, blockParams, depths),"inverse":container.noop,"args":["furigana"],"data":data}) || fn; - fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(39, data, 0, blockParams, depths),"inverse":container.noop,"args":["glossary"],"data":data}) || fn; - fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(66, data, 0, blockParams, depths),"inverse":container.noop,"args":["kunyomi"],"data":data}) || fn; - fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(68, data, 0, blockParams, depths),"inverse":container.noop,"args":["onyomi"],"data":data}) || fn; - fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(70, data, 0, blockParams, depths),"inverse":container.noop,"args":["reading"],"data":data}) || fn; - fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(72, data, 0, blockParams, depths),"inverse":container.noop,"args":["sentence"],"data":data}) || fn; - fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(75, data, 0, blockParams, depths),"inverse":container.noop,"args":["cloze-prefix"],"data":data}) || fn; - fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(78, data, 0, blockParams, depths),"inverse":container.noop,"args":["cloze-body"],"data":data}) || fn; - fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(81, data, 0, blockParams, depths),"inverse":container.noop,"args":["cloze-suffix"],"data":data}) || fn; - fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(84, data, 0, blockParams, depths),"inverse":container.noop,"args":["tags"],"data":data}) || fn; - fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(86, data, 0, blockParams, depths),"inverse":container.noop,"args":["url"],"data":data}) || fn; + fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(22, data, 0, blockParams, depths),"inverse":container.noop,"args":["audio"],"data":data}) || fn; + fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(24, data, 0, blockParams, depths),"inverse":container.noop,"args":["character"],"data":data}) || fn; + fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(26, data, 0, blockParams, depths),"inverse":container.noop,"args":["dictionary"],"data":data}) || fn; + fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(28, data, 0, blockParams, depths),"inverse":container.noop,"args":["expression"],"data":data}) || fn; + fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(34, data, 0, blockParams, depths),"inverse":container.noop,"args":["furigana"],"data":data}) || fn; + fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(41, data, 0, blockParams, depths),"inverse":container.noop,"args":["glossary"],"data":data}) || fn; + fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(68, data, 0, blockParams, depths),"inverse":container.noop,"args":["glossary-brief"],"data":data}) || fn; + fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(70, data, 0, blockParams, depths),"inverse":container.noop,"args":["kunyomi"],"data":data}) || fn; + fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(72, data, 0, blockParams, depths),"inverse":container.noop,"args":["onyomi"],"data":data}) || fn; + fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(74, data, 0, blockParams, depths),"inverse":container.noop,"args":["reading"],"data":data}) || fn; + fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(76, data, 0, blockParams, depths),"inverse":container.noop,"args":["sentence"],"data":data}) || fn; + fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(79, data, 0, blockParams, depths),"inverse":container.noop,"args":["cloze-prefix"],"data":data}) || fn; + fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(82, data, 0, blockParams, depths),"inverse":container.noop,"args":["cloze-body"],"data":data}) || fn; + fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(85, data, 0, blockParams, depths),"inverse":container.noop,"args":["cloze-suffix"],"data":data}) || fn; + fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(88, data, 0, blockParams, depths),"inverse":container.noop,"args":["tags"],"data":data}) || fn; + fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(90, data, 0, blockParams, depths),"inverse":container.noop,"args":["url"],"data":data}) || fn; return fn; } diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js index 4f907923..4d0aa27e 100644 --- a/ext/bg/js/util.js +++ b/ext/bg/js/util.js @@ -400,6 +400,7 @@ function dictFieldFormat(field, definition, mode, options) { 'expression', 'furigana', 'glossary', + 'glossary-brief', 'kunyomi', 'onyomi', 'reading', diff --git a/tmpl/fields.html b/tmpl/fields.html index ab1a9722..944a43e6 100644 --- a/tmpl/fields.html +++ b/tmpl/fields.html @@ -1,13 +1,17 @@ {{#*inline "glossary-single"}} {{~#if html~}} - {{~#if tags~}}({{#each tags}}{{name}}{{#unless @last}}, {{/unless}}{{/each}}) {{/if~}} + {{~#unless brief~}} + {{~#if tags~}}({{#each tags}}{{name}}{{#unless @last}}, {{/unless}}{{/each}}) {{/if~}} + {{~/unless~}} {{~#if glossary.[1]~}}
      {{#each glossary}}
    • {{#multiLine}}{{.}}{{/multiLine}}
    • {{/each}}
    {{~else~}} {{~#multiLine}}{{glossary.[0]}}{{/multiLine~}} {{~/if~}} {{~else~}} - {{~#if tags~}}({{#each tags}}{{name}}{{#unless @last}}, {{/unless}}{{/each}}) {{/if~}} + {{~#unless brief~}} + {{~#if tags~}}({{#each tags}}{{name}}{{#unless @last}}, {{/unless}}{{/each}}) {{/if~}} + {{~/unless~}} {{~#if glossary.[1]~}} {{#each glossary}}{{.}}{{#unless @last}}, {{/unless}}{{/each}} {{~else~}} @@ -58,18 +62,22 @@ {{~else~}} {{~#if group~}} {{~#if definition.definitions.[1]~}} - {{~#if html}}
      {{#each definition.definitions}}
    1. {{> glossary-single html=../html}}
    2. {{/each}}
    - {{~else}}{{#each definition.definitions}} * {{> glossary-single html=../html}}{{/each}}{{/if~}} + {{~#if html}}
      {{#each definition.definitions}}
    1. {{> glossary-single html=../html brief=../brief}}
    2. {{/each}}
    + {{~else}}{{#each definition.definitions}} * {{> glossary-single html=../html brief=../brief}}{{/each}}{{/if~}} {{~else~}} - {{~> glossary-single definition.definitions.[0] html=html~}} + {{~> glossary-single definition.definitions.[0] html=html brief=brief~}} {{~/if~}} {{~else~}} - {{~> glossary-single definition html=html~}} + {{~> glossary-single definition html=html brief=brief~}} {{~/if~}} {{~/if~}} {{~#if html}}{{/if~}} {{/inline}} +{{#*inline "glossary-brief"}} + {{~> glossary brief=true ~}} +{{/inline}} + {{#*inline "kunyomi"}} {{~#each definition.kunyomi}}{{.}}{{#unless @last}}, {{/unless}}{{/each~}} {{/inline}} -- cgit v1.2.3 From 39f1f30dc9e9aaae8cbeac9afe120fbb5c2ecfd3 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 16 Jul 2017 13:14:28 -0700 Subject: refactor bg/js/util.js --- ext/bg/background.html | 1 + ext/bg/js/options.js | 132 +++++++++++++++++++++++++++++++++++++++++++++++++ ext/bg/js/util.js | 119 -------------------------------------------- ext/bg/popup.html | 1 + ext/bg/settings.html | 1 + ext/mixed/js/audio.js | 4 -- 6 files changed, 135 insertions(+), 123 deletions(-) create mode 100644 ext/bg/js/options.js (limited to 'ext/bg/js/util.js') diff --git a/ext/bg/background.html b/ext/bg/background.html index 4a2d8c8d..a9071cc7 100644 --- a/ext/bg/background.html +++ b/ext/bg/background.html @@ -11,6 +11,7 @@ + diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js new file mode 100644 index 00000000..a9345fdd --- /dev/null +++ b/ext/bg/js/options.js @@ -0,0 +1,132 @@ +/* + * Copyright (C) 2016 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 . + */ + + +function optionsSetDefaults(options) { + const defaults = { + general: { + enable: true, + audioSource: 'jpod101', + audioVolume: 100, + groupResults: true, + debugInfo: false, + maxResults: 32, + showAdvanced: false, + popupWidth: 400, + popupHeight: 250, + popupOffset: 10, + showGuide: true + }, + + scanning: { + middleMouse: true, + selectText: true, + alphanumeric: true, + delay: 15, + length: 10, + modifier: 'shift' + }, + + dictionaries: {}, + + anki: { + enable: false, + server: 'http://127.0.0.1:8765', + tags: ['yomichan'], + htmlCards: true, + sentenceExt: 200, + terms: {deck: '', model: '', fields: {}}, + kanji: {deck: '', model: '', fields: {}} + } + }; + + const combine = (target, source) => { + for (const key in source) { + if (!target.hasOwnProperty(key)) { + target[key] = source[key]; + } + } + }; + + combine(options, defaults); + combine(options.general, defaults.general); + combine(options.scanning, defaults.scanning); + combine(options.anki, defaults.anki); + combine(options.anki.terms, defaults.anki.terms); + combine(options.anki.kanji, defaults.anki.kanji); + + return options; +} + +function optionsVersion(options) { + const fixups = [ + () => {}, + () => {}, + () => {}, + () => {}, + () => { + if (options.general.audioPlayback) { + options.general.audioSource = 'jpod101'; + } else { + options.general.audioSource = 'disabled'; + } + }, + () => { + options.general.showGuide = false; + }, + () => { + if (options.scanning.requireShift) { + options.scanning.modifier = 'shift'; + } else { + options.scanning.modifier = 'none'; + } + } + ]; + + optionsSetDefaults(options); + if (!options.hasOwnProperty('version')) { + options.version = fixups.length; + } + + while (options.version < fixups.length) { + fixups[options.version++](); + } + + return options; +} + +function optionsLoad() { + return new Promise((resolve, reject) => { + chrome.storage.local.get(null, store => resolve(store.options)); + }).then(optionsStr => { + return optionsStr ? JSON.parse(optionsStr) : {}; + }).catch(error => { + return {}; + }).then(options => { + return optionsVersion(options); + }); +} + +function optionsSave(options) { + return new Promise((resolve, reject) => { + chrome.storage.local.set({options: JSON.stringify(options)}, resolve); + }).then(() => { + instYomi().optionsSet(options); + fgOptionsSet(options); + }); +} diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js index 4d0aa27e..5d80fdb7 100644 --- a/ext/bg/js/util.js +++ b/ext/bg/js/util.js @@ -91,125 +91,6 @@ function fgOptionsSet(options) { } -/* - * Options - */ - -function optionsSetDefaults(options) { - const defaults = { - general: { - enable: true, - audioSource: 'jpod101', - audioVolume: 100, - groupResults: true, - debugInfo: false, - maxResults: 32, - showAdvanced: false, - popupWidth: 400, - popupHeight: 250, - popupOffset: 10, - showGuide: true - }, - - scanning: { - middleMouse: true, - selectText: true, - alphanumeric: true, - delay: 15, - length: 10, - modifier: 'shift' - }, - - dictionaries: {}, - - anki: { - enable: false, - server: 'http://127.0.0.1:8765', - tags: ['yomichan'], - htmlCards: true, - sentenceExt: 200, - terms: {deck: '', model: '', fields: {}}, - kanji: {deck: '', model: '', fields: {}} - } - }; - - const combine = (target, source) => { - for (const key in source) { - if (!target.hasOwnProperty(key)) { - target[key] = source[key]; - } - } - }; - - combine(options, defaults); - combine(options.general, defaults.general); - combine(options.scanning, defaults.scanning); - combine(options.anki, defaults.anki); - combine(options.anki.terms, defaults.anki.terms); - combine(options.anki.kanji, defaults.anki.kanji); - - return options; -} - -function optionsVersion(options) { - const fixups = [ - () => {}, - () => {}, - () => {}, - () => {}, - () => { - if (options.general.audioPlayback) { - options.general.audioSource = 'jpod101'; - } else { - options.general.audioSource = 'disabled'; - } - }, - () => { - options.general.showGuide = false; - }, - () => { - if (options.scanning.requireShift) { - options.scanning.modifier = 'shift'; - } else { - options.scanning.modifier = 'none'; - } - } - ]; - - optionsSetDefaults(options); - if (!options.hasOwnProperty('version')) { - options.version = fixups.length; - } - - while (options.version < fixups.length) { - fixups[options.version++](); - } - - return options; -} - -function optionsLoad() { - return new Promise((resolve, reject) => { - chrome.storage.local.get(null, store => resolve(store.options)); - }).then(optionsStr => { - return optionsStr ? JSON.parse(optionsStr) : {}; - }).catch(error => { - return {}; - }).then(options => { - return optionsVersion(options); - }); -} - -function optionsSave(options) { - return new Promise((resolve, reject) => { - chrome.storage.local.set({options: JSON.stringify(options)}, resolve); - }).then(() => { - instYomi().optionsSet(options); - fgOptionsSet(options); - }); -} - - /* * Dictionary */ diff --git a/ext/bg/popup.html b/ext/bg/popup.html index dec52795..ab2ee1e0 100644 --- a/ext/bg/popup.html +++ b/ext/bg/popup.html @@ -31,6 +31,7 @@ + diff --git a/ext/bg/settings.html b/ext/bg/settings.html index 19dfec22..ada3299b 100644 --- a/ext/bg/settings.html +++ b/ext/bg/settings.html @@ -277,6 +277,7 @@ + diff --git a/ext/mixed/js/audio.js b/ext/mixed/js/audio.js index 451fe1d9..eb8fde94 100644 --- a/ext/mixed/js/audio.js +++ b/ext/mixed/js/audio.js @@ -17,10 +17,6 @@ */ -/* - * Audio - */ - async function audioBuildUrl(definition, mode, cache={}) { if (mode === 'jpod101') { let kana = definition.reading; -- cgit v1.2.3 From 26e1cc517f6100fe665d8d066729a11fde2cdc26 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Tue, 18 Jul 2017 23:07:46 -0700 Subject: refactor --- ext/bg/background.html | 2 + ext/bg/js/dictionary.js | 233 ++++++++++++++++++++++++++++++++++++++++++++++ ext/bg/js/util.js | 237 ----------------------------------------------- ext/bg/popup.html | 2 + ext/bg/search.html | 2 + ext/bg/settings.html | 2 + ext/mixed/js/japanese.js | 31 +++++++ 7 files changed, 272 insertions(+), 237 deletions(-) create mode 100644 ext/bg/js/dictionary.js create mode 100644 ext/mixed/js/japanese.js (limited to 'ext/bg/js/util.js') diff --git a/ext/bg/background.html b/ext/bg/background.html index a9071cc7..3cfd894e 100644 --- a/ext/bg/background.html +++ b/ext/bg/background.html @@ -11,6 +11,8 @@ + + diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js new file mode 100644 index 00000000..6f4ec809 --- /dev/null +++ b/ext/bg/js/dictionary.js @@ -0,0 +1,233 @@ +/* + * Copyright (C) 2016 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 . + */ + + +function dictEnabledSet(options) { + const dictionaries = {}; + for (const title in options.dictionaries) { + const dictionary = options.dictionaries[title]; + if (dictionary.enabled) { + dictionaries[title] = dictionary; + } + } + + return dictionaries; +} + +function dictConfigured(options) { + for (const title in options.dictionaries) { + if (options.dictionaries[title].enabled) { + return true; + } + } + + return false; +} + +function dictRowsSort(rows, options) { + return rows.sort((ra, rb) => { + const pa = (options.dictionaries[ra.title] || {}).priority || 0; + const pb = (options.dictionaries[rb.title] || {}).priority || 0; + if (pa > pb) { + return -1; + } else if (pa < pb) { + return 1; + } else { + return 0; + } + }); +} + +function dictTermsSort(definitions, dictionaries=null) { + return definitions.sort((v1, v2) => { + const sl1 = v1.source.length; + const sl2 = v2.source.length; + if (sl1 > sl2) { + return -1; + } else if (sl1 < sl2) { + return 1; + } + + if (dictionaries !== null) { + const p1 = (dictionaries[v1.dictionary] || {}).priority || 0; + const p2 = (dictionaries[v2.dictionary] || {}).priority || 0; + if (p1 > p2) { + return -1; + } else if (p1 < p2) { + return 1; + } + } + + const s1 = v1.score; + const s2 = v2.score; + if (s1 > s2) { + return -1; + } else if (s1 < s2) { + return 1; + } + + const rl1 = v1.reasons.length; + const rl2 = v2.reasons.length; + if (rl1 < rl2) { + return -1; + } else if (rl1 > rl2) { + return 1; + } + + return v2.expression.localeCompare(v1.expression); + }); +} + +function dictTermsUndupe(definitions) { + const definitionGroups = {}; + for (const definition of definitions) { + const definitionExisting = definitionGroups[definition.id]; + if (!definitionGroups.hasOwnProperty(definition.id) || definition.expression.length > definitionExisting.expression.length) { + definitionGroups[definition.id] = definition; + } + } + + const definitionsUnique = []; + for (const key in definitionGroups) { + definitionsUnique.push(definitionGroups[key]); + } + + return definitionsUnique; +} + +function dictTermsGroup(definitions, dictionaries) { + const groups = {}; + for (const definition of definitions) { + const key = [definition.source, definition.expression].concat(definition.reasons); + if (definition.reading) { + key.push(definition.reading); + } + + const group = groups[key]; + if (group) { + group.push(definition); + } else { + groups[key] = [definition]; + } + } + + const results = []; + for (const key in groups) { + const groupDefs = groups[key]; + const firstDef = groupDefs[0]; + dictTermsSort(groupDefs, dictionaries); + results.push({ + definitions: groupDefs, + expression: firstDef.expression, + reading: firstDef.reading, + reasons: firstDef.reasons, + score: groupDefs.reduce((p, v) => v.score > p ? v.score : p, Number.MIN_SAFE_INTEGER), + source: firstDef.source + }); + } + + return dictTermsSort(results); +} + +function dictTagBuildSource(name) { + return dictTagSanitize({name, category: 'dictionary', order: 100}); +} + +function dictTagBuild(name, meta) { + const tag = {name}; + const symbol = name.split(':')[0]; + for (const prop in meta[symbol] || {}) { + tag[prop] = meta[symbol][prop]; + } + + return dictTagSanitize(tag); +} + +function dictTagSanitize(tag) { + tag.name = tag.name || 'untitled'; + tag.category = tag.category || 'default'; + tag.notes = tag.notes || ''; + tag.order = tag.order || 0; + return tag; +} + +function dictTagsSort(tags) { + return tags.sort((v1, v2) => { + const order1 = v1.order; + const order2 = v2.order; + if (order1 < order2) { + return -1; + } else if (order1 > order2) { + return 1; + } + + const name1 = v1.name; + const name2 = v2.name; + if (name1 < name2) { + return -1; + } else if (name1 > name2) { + return 1; + } + + return 0; + }); +} + +function dictFieldSplit(field) { + return field.length === 0 ? [] : field.split(' '); +} + +function dictFieldFormat(field, definition, mode, options) { + const markers = [ + 'audio', + 'character', + 'cloze-body', + 'cloze-prefix', + 'cloze-suffix', + 'dictionary', + 'expression', + 'furigana', + 'glossary', + 'glossary-brief', + 'kunyomi', + 'onyomi', + 'reading', + 'sentence', + 'tags', + 'url' + ]; + + for (const marker of markers) { + const data = { + marker, + definition, + group: options.general.groupResults, + html: options.anki.htmlCards, + modeTermKanji: mode === 'term-kanji', + modeTermKana: mode === 'term-kana', + modeKanji: mode === 'kanji' + }; + + field = field.replace( + `{${marker}}`, + Handlebars.templates['fields.html'](data).trim() + ); + } + + return field; +} diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js index 5d80fdb7..0a4592ea 100644 --- a/ext/bg/js/util.js +++ b/ext/bg/js/util.js @@ -30,24 +30,6 @@ function promiseCallback(promise, callback) { } -/* - * Japanese - */ - -function jpIsKanji(c) { - const code = c.charCodeAt(0); - return code >= 0x4e00 && code < 0x9fb0 || code >= 0x3400 && code < 0x4dc0; -} - -function jpIsKana(c) { - return wanakana.isKana(c); -} - -function jpKatakanaToHiragana(text) { - return wanakana._katakanaToHiragana(text); -} - - /* * Commands */ @@ -91,225 +73,6 @@ function fgOptionsSet(options) { } -/* - * Dictionary - */ - -function dictEnabledSet(options) { - const dictionaries = {}; - for (const title in options.dictionaries) { - const dictionary = options.dictionaries[title]; - if (dictionary.enabled) { - dictionaries[title] = dictionary; - } - } - - return dictionaries; -} - -function dictConfigured(options) { - for (const title in options.dictionaries) { - if (options.dictionaries[title].enabled) { - return true; - } - } - - return false; -} - -function dictRowsSort(rows, options) { - return rows.sort((ra, rb) => { - const pa = (options.dictionaries[ra.title] || {}).priority || 0; - const pb = (options.dictionaries[rb.title] || {}).priority || 0; - if (pa > pb) { - return -1; - } else if (pa < pb) { - return 1; - } else { - return 0; - } - }); -} - -function dictTermsSort(definitions, dictionaries=null) { - return definitions.sort((v1, v2) => { - const sl1 = v1.source.length; - const sl2 = v2.source.length; - if (sl1 > sl2) { - return -1; - } else if (sl1 < sl2) { - return 1; - } - - if (dictionaries !== null) { - const p1 = (dictionaries[v1.dictionary] || {}).priority || 0; - const p2 = (dictionaries[v2.dictionary] || {}).priority || 0; - if (p1 > p2) { - return -1; - } else if (p1 < p2) { - return 1; - } - } - - const s1 = v1.score; - const s2 = v2.score; - if (s1 > s2) { - return -1; - } else if (s1 < s2) { - return 1; - } - - const rl1 = v1.reasons.length; - const rl2 = v2.reasons.length; - if (rl1 < rl2) { - return -1; - } else if (rl1 > rl2) { - return 1; - } - - return v2.expression.localeCompare(v1.expression); - }); -} - -function dictTermsUndupe(definitions) { - const definitionGroups = {}; - for (const definition of definitions) { - const definitionExisting = definitionGroups[definition.id]; - if (!definitionGroups.hasOwnProperty(definition.id) || definition.expression.length > definitionExisting.expression.length) { - definitionGroups[definition.id] = definition; - } - } - - const definitionsUnique = []; - for (const key in definitionGroups) { - definitionsUnique.push(definitionGroups[key]); - } - - return definitionsUnique; -} - -function dictTermsGroup(definitions, dictionaries) { - const groups = {}; - for (const definition of definitions) { - const key = [definition.source, definition.expression].concat(definition.reasons); - if (definition.reading) { - key.push(definition.reading); - } - - const group = groups[key]; - if (group) { - group.push(definition); - } else { - groups[key] = [definition]; - } - } - - const results = []; - for (const key in groups) { - const groupDefs = groups[key]; - const firstDef = groupDefs[0]; - dictTermsSort(groupDefs, dictionaries); - results.push({ - definitions: groupDefs, - expression: firstDef.expression, - reading: firstDef.reading, - reasons: firstDef.reasons, - score: groupDefs.reduce((p, v) => v.score > p ? v.score : p, Number.MIN_SAFE_INTEGER), - source: firstDef.source - }); - } - - return dictTermsSort(results); -} - -function dictTagBuildSource(name) { - return dictTagSanitize({name, category: 'dictionary', order: 100}); -} - -function dictTagBuild(name, meta) { - const tag = {name}; - const symbol = name.split(':')[0]; - for (const prop in meta[symbol] || {}) { - tag[prop] = meta[symbol][prop]; - } - - return dictTagSanitize(tag); -} - -function dictTagSanitize(tag) { - tag.name = tag.name || 'untitled'; - tag.category = tag.category || 'default'; - tag.notes = tag.notes || ''; - tag.order = tag.order || 0; - return tag; -} - -function dictTagsSort(tags) { - return tags.sort((v1, v2) => { - const order1 = v1.order; - const order2 = v2.order; - if (order1 < order2) { - return -1; - } else if (order1 > order2) { - return 1; - } - - const name1 = v1.name; - const name2 = v2.name; - if (name1 < name2) { - return -1; - } else if (name1 > name2) { - return 1; - } - - return 0; - }); -} - -function dictFieldSplit(field) { - return field.length === 0 ? [] : field.split(' '); -} - -function dictFieldFormat(field, definition, mode, options) { - const markers = [ - 'audio', - 'character', - 'cloze-body', - 'cloze-prefix', - 'cloze-suffix', - 'dictionary', - 'expression', - 'furigana', - 'glossary', - 'glossary-brief', - 'kunyomi', - 'onyomi', - 'reading', - 'sentence', - 'tags', - 'url' - ]; - - for (const marker of markers) { - const data = { - marker, - definition, - group: options.general.groupResults, - html: options.anki.htmlCards, - modeTermKanji: mode === 'term-kanji', - modeTermKana: mode === 'term-kana', - modeKanji: mode === 'kanji' - }; - - field = field.replace( - `{${marker}}`, - Handlebars.templates['fields.html'](data).trim() - ); - } - - return field; -} - /* * JSON */ diff --git a/ext/bg/popup.html b/ext/bg/popup.html index ab2ee1e0..db9097bd 100644 --- a/ext/bg/popup.html +++ b/ext/bg/popup.html @@ -31,6 +31,8 @@ + + diff --git a/ext/bg/search.html b/ext/bg/search.html index 0fc3caf7..b30b8910 100644 --- a/ext/bg/search.html +++ b/ext/bg/search.html @@ -34,6 +34,8 @@ + + diff --git a/ext/bg/settings.html b/ext/bg/settings.html index ada3299b..8135ca9a 100644 --- a/ext/bg/settings.html +++ b/ext/bg/settings.html @@ -277,6 +277,8 @@ + + diff --git a/ext/mixed/js/japanese.js b/ext/mixed/js/japanese.js new file mode 100644 index 00000000..779e3d35 --- /dev/null +++ b/ext/mixed/js/japanese.js @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2016 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 . + */ + + +function jpIsKanji(c) { + const code = c.charCodeAt(0); + return code >= 0x4e00 && code < 0x9fb0 || code >= 0x3400 && code < 0x4dc0; +} + +function jpIsKana(c) { + return wanakana.isKana(c); +} + +function jpKatakanaToHiragana(text) { + return wanakana._katakanaToHiragana(text); +} -- cgit v1.2.3 From 62db3d74b8042dd3185a7a552920a2ce7a4bd4ab Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Wed, 19 Jul 2017 09:24:38 -0700 Subject: factor out handlebars from util --- ext/bg/background.html | 1 + ext/bg/js/handlebars.js | 55 +++++++++++++++++++++++++++++++++++++++++++++++++ ext/bg/js/util.js | 41 ------------------------------------ ext/bg/settings.html | 1 + 4 files changed, 57 insertions(+), 41 deletions(-) create mode 100644 ext/bg/js/handlebars.js (limited to 'ext/bg/js/util.js') diff --git a/ext/bg/background.html b/ext/bg/background.html index 3cfd894e..61bc17a0 100644 --- a/ext/bg/background.html +++ b/ext/bg/background.html @@ -11,6 +11,7 @@ + diff --git a/ext/bg/js/handlebars.js b/ext/bg/js/handlebars.js new file mode 100644 index 00000000..42b36927 --- /dev/null +++ b/ext/bg/js/handlebars.js @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2016 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 . + */ + + +function handlebarsEscape(text) { + return Handlebars.Utils.escapeExpression(text); +} + +function handlebarsDumpObject(options) { + const dump = JSON.stringify(options.fn(this), null, 4); + return handlebarsEscape(dump); +} + +function handlebarsKanjiLinks(options) { + let result = ''; + for (const c of options.fn(this)) { + if (jpIsKanji(c)) { + result += `${c}`; + } else { + result += c; + } + } + + return result; +} + +function handlebarsMultiLine(options) { + return options.fn(this).split('\n').join('
    '); +} + +function handlebarsRegister() { + Handlebars.partials = Handlebars.templates; + Handlebars.registerHelper('dumpObject', handlebarsDumpObject); + Handlebars.registerHelper('kanjiLinks', handlebarsKanjiLinks); + Handlebars.registerHelper('multiLine', handlebarsMultiLine); +} + +function handlebarsRender(template, data) { + return Handlebars.templates[template](data); +} diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js index 0a4592ea..6e86c2a6 100644 --- a/ext/bg/js/util.js +++ b/ext/bg/js/util.js @@ -98,44 +98,3 @@ function jsonRequest(url, action, params) { } }); } - -/* - * Helpers - */ - -function handlebarsEscape(text) { - return Handlebars.Utils.escapeExpression(text); -} - -function handlebarsDumpObject(options) { - const dump = JSON.stringify(options.fn(this), null, 4); - return handlebarsEscape(dump); -} - -function handlebarsKanjiLinks(options) { - let result = ''; - for (const c of options.fn(this)) { - if (jpIsKanji(c)) { - result += `${c}`; - } else { - result += c; - } - } - - return result; -} - -function handlebarsMultiLine(options) { - return options.fn(this).split('\n').join('
    '); -} - -function handlebarsRegister() { - Handlebars.partials = Handlebars.templates; - Handlebars.registerHelper('dumpObject', handlebarsDumpObject); - Handlebars.registerHelper('kanjiLinks', handlebarsKanjiLinks); - Handlebars.registerHelper('multiLine', handlebarsMultiLine); -} - -function handlebarsRender(template, data) { - return Handlebars.templates[template](data); -} diff --git a/ext/bg/settings.html b/ext/bg/settings.html index 8135ca9a..9b21b4d8 100644 --- a/ext/bg/settings.html +++ b/ext/bg/settings.html @@ -277,6 +277,7 @@ + -- cgit v1.2.3 From fe137e94c92cf0366735936b6ac82dc147b1ad33 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Wed, 19 Jul 2017 21:28:09 -0700 Subject: cleanup --- ext/bg/background.html | 1 + ext/bg/js/anki-connect.js | 2 +- ext/bg/js/translator.js | 2 +- ext/bg/js/util.js | 40 ---------------------------------------- ext/bg/js/yomichan.js | 8 ++++++++ ext/bg/popup.html | 1 + ext/bg/search.html | 1 + ext/bg/settings.html | 1 + ext/mixed/js/request.js | 40 ++++++++++++++++++++++++++++++++++++++++ 9 files changed, 54 insertions(+), 42 deletions(-) create mode 100644 ext/mixed/js/request.js (limited to 'ext/bg/js/util.js') diff --git a/ext/bg/background.html b/ext/bg/background.html index 61bc17a0..7d352561 100644 --- a/ext/bg/background.html +++ b/ext/bg/background.html @@ -14,6 +14,7 @@ + diff --git a/ext/bg/js/anki-connect.js b/ext/bg/js/anki-connect.js index a4d8ba3f..567e8d3f 100644 --- a/ext/bg/js/anki-connect.js +++ b/ext/bg/js/anki-connect.js @@ -64,6 +64,6 @@ class AnkiConnect { } ankiInvoke(action, params) { - return jsonRequest(this.server, 'POST', {action, params, version: this.localVersion}); + return requestJson(this.server, 'POST', {action, params, version: this.localVersion}); } } diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index 9232e529..1be485c7 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -31,7 +31,7 @@ class Translator { if (!this.deinflector) { const url = chrome.extension.getURL('/bg/lang/deinflect.json'); - const reasons = await jsonRequest(url, 'GET'); + const reasons = await requestJson(url, 'GET'); this.deinflector = new Deinflector(reasons); } } diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js index 6e86c2a6..c7ebbb0e 100644 --- a/ext/bg/js/util.js +++ b/ext/bg/js/util.js @@ -17,19 +17,6 @@ */ -/* - * Promise - */ - -function promiseCallback(promise, callback) { - return promise.then(result => { - callback({result}); - }).catch(error => { - callback({error}); - }); -} - - /* * Commands */ @@ -71,30 +58,3 @@ function fgBroadcast(action, params) { function fgOptionsSet(options) { fgBroadcast('optionsSet', options); } - - -/* - * JSON - */ - -function jsonRequest(url, action, params) { - return new Promise((resolve, reject) => { - const xhr = new XMLHttpRequest(); - xhr.overrideMimeType('application/json'); - xhr.addEventListener('load', () => resolve(xhr.responseText)); - xhr.addEventListener('error', () => reject('failed to execute network request')); - xhr.open(action, url); - if (params) { - xhr.send(JSON.stringify(params)); - } else { - xhr.send(); - } - }).then(responseText => { - try { - return JSON.parse(responseText); - } - catch (e) { - return Promise.reject('invalid JSON response'); - } - }); -} diff --git a/ext/bg/js/yomichan.js b/ext/bg/js/yomichan.js index acc560ce..eb083396 100644 --- a/ext/bg/js/yomichan.js +++ b/ext/bg/js/yomichan.js @@ -195,6 +195,14 @@ window.yomichan = new class { } onMessage({action, params}, sender, callback) { + const promiseCallback = (promise, callback) => { + return promise.then(result => { + callback({result}); + }).catch(error => { + callback({error}); + }); + }; + const handlers = { optionsGet: ({callback}) => { promiseCallback(optionsLoad(), callback); diff --git a/ext/bg/popup.html b/ext/bg/popup.html index db9097bd..b3d38533 100644 --- a/ext/bg/popup.html +++ b/ext/bg/popup.html @@ -32,6 +32,7 @@ + diff --git a/ext/bg/search.html b/ext/bg/search.html index b30b8910..45603f17 100644 --- a/ext/bg/search.html +++ b/ext/bg/search.html @@ -35,6 +35,7 @@ + diff --git a/ext/bg/settings.html b/ext/bg/settings.html index 9b21b4d8..4c7198c3 100644 --- a/ext/bg/settings.html +++ b/ext/bg/settings.html @@ -280,6 +280,7 @@ + diff --git a/ext/mixed/js/request.js b/ext/mixed/js/request.js new file mode 100644 index 00000000..94fd135a --- /dev/null +++ b/ext/mixed/js/request.js @@ -0,0 +1,40 @@ +/* + * 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 . + */ + + +function requestJson(url, action, params) { + return new Promise((resolve, reject) => { + const xhr = new XMLHttpRequest(); + xhr.overrideMimeType('application/json'); + xhr.addEventListener('load', () => resolve(xhr.responseText)); + xhr.addEventListener('error', () => reject('failed to execute network request')); + xhr.open(action, url); + if (params) { + xhr.send(JSON.stringify(params)); + } else { + xhr.send(); + } + }).then(responseText => { + try { + return JSON.parse(responseText); + } + catch (e) { + return Promise.reject('invalid JSON response'); + } + }); +} -- cgit v1.2.3 From ac2e079c98f87acfbafd2105461885a1cb199c76 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Wed, 19 Jul 2017 21:41:30 -0700 Subject: cleanup --- ext/bg/background.html | 2 +- ext/bg/js/instance.js | 30 +++++++++++++++++++++++++ ext/bg/js/options.js | 1 - ext/bg/js/popup.js | 2 ++ ext/bg/js/util.js | 60 -------------------------------------------------- ext/bg/js/yomichan.js | 6 +++++ ext/bg/popup.html | 2 +- ext/bg/search.html | 2 +- ext/bg/settings.html | 2 +- 9 files changed, 42 insertions(+), 65 deletions(-) create mode 100644 ext/bg/js/instance.js delete mode 100644 ext/bg/js/util.js (limited to 'ext/bg/js/util.js') diff --git a/ext/bg/background.html b/ext/bg/background.html index 7d352561..de3cbf20 100644 --- a/ext/bg/background.html +++ b/ext/bg/background.html @@ -10,7 +10,7 @@ - + diff --git a/ext/bg/js/instance.js b/ext/bg/js/instance.js new file mode 100644 index 00000000..0df267cc --- /dev/null +++ b/ext/bg/js/instance.js @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2016 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 . + */ + + +function instYomi() { + return chrome.extension.getBackgroundPage().yomichan; +} + +function instDb() { + return instYomi().translator.database; +} + +function instAnki() { + return instYomi().anki; +} diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js index a9345fdd..d611ae59 100644 --- a/ext/bg/js/options.js +++ b/ext/bg/js/options.js @@ -127,6 +127,5 @@ function optionsSave(options) { chrome.storage.local.set({options: JSON.stringify(options)}, resolve); }).then(() => { instYomi().optionsSet(options); - fgOptionsSet(options); }); } diff --git a/ext/bg/js/popup.js b/ext/bg/js/popup.js index 8577dd96..01994827 100644 --- a/ext/bg/js/popup.js +++ b/ext/bg/js/popup.js @@ -18,6 +18,8 @@ $(document).ready(() => { + const commandExec = command => instYomi().onCommand(command); + $('#open-search').click(() => commandExec('search')); $('#open-options').click(() => commandExec('options')); $('#open-help').click(() => commandExec('help')); diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js deleted file mode 100644 index c7ebbb0e..00000000 --- a/ext/bg/js/util.js +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2016 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 . - */ - - -/* - * Commands - */ - -function commandExec(command) { - instYomi().onCommand(command); -} - - -/* - * Instance - */ - -function instYomi() { - return chrome.extension.getBackgroundPage().yomichan; -} - -function instDb() { - return instYomi().translator.database; -} - -function instAnki() { - return instYomi().anki; -} - - -/* - * Foreground - */ - -function fgBroadcast(action, params) { - chrome.tabs.query({}, tabs => { - for (const tab of tabs) { - chrome.tabs.sendMessage(tab.id, {action, params}, () => null); - } - }); -} - -function fgOptionsSet(options) { - fgBroadcast('optionsSet', options); -} diff --git a/ext/bg/js/yomichan.js b/ext/bg/js/yomichan.js index eb083396..214bdef3 100644 --- a/ext/bg/js/yomichan.js +++ b/ext/bg/js/yomichan.js @@ -59,6 +59,12 @@ window.yomichan = new class { } else { this.anki = new AnkiNull(); } + + chrome.tabs.query({}, tabs => { + for (const tab of tabs) { + chrome.tabs.sendMessage(tab.id, {action: 'optionsSet', params: options}, () => null); + } + }); } noteFormat(definition, mode) { diff --git a/ext/bg/popup.html b/ext/bg/popup.html index b3d38533..baeb2ffb 100644 --- a/ext/bg/popup.html +++ b/ext/bg/popup.html @@ -30,7 +30,7 @@ - + diff --git a/ext/bg/search.html b/ext/bg/search.html index 45603f17..472907c2 100644 --- a/ext/bg/search.html +++ b/ext/bg/search.html @@ -33,7 +33,7 @@ - + diff --git a/ext/bg/settings.html b/ext/bg/settings.html index 4c7198c3..9c3995eb 100644 --- a/ext/bg/settings.html +++ b/ext/bg/settings.html @@ -276,7 +276,7 @@ - + -- cgit v1.2.3 From 7e635d6382b0d96f596e2440b93e5935230367aa Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 5 Aug 2017 19:23:17 -0700 Subject: more cleanup --- ext/bg/background.html | 1 + ext/bg/js/api.js | 37 ++++++++++++------------------------- ext/bg/js/backend.js | 4 ++-- ext/bg/js/settings.js | 33 --------------------------------- ext/bg/js/util.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ ext/bg/settings.html | 1 + 6 files changed, 62 insertions(+), 60 deletions(-) create mode 100644 ext/bg/js/util.js (limited to 'ext/bg/js/util.js') diff --git a/ext/bg/background.html b/ext/bg/background.html index 1e9f3809..40f37b11 100644 --- a/ext/bg/background.html +++ b/ext/bg/background.html @@ -19,6 +19,7 @@ + diff --git a/ext/bg/js/api.js b/ext/bg/js/api.js index bc2693e5..024ba75e 100644 --- a/ext/bg/js/api.js +++ b/ext/bg/js/api.js @@ -17,34 +17,21 @@ */ -/* - * Backend - */ - -function backend() { - return chrome.extension.getBackgroundPage().yomichan_backend; -} - - -/* - * API - */ - async function apiOptionsSet(options) { // In Firefox, setting options from the options UI somehow carries references // to the DOM across to the background page, causing the options object to // become a "DeadObject" after the options page is closed. The workaround used // here is to create a deep copy of the options object. - backend().onOptionsUpdated(JSON.parse(JSON.stringify(options))); + utilBackend().onOptionsUpdated(JSON.parse(JSON.stringify(options))); } async function apiOptionsGet() { - return backend().options; + return utilBackend().options; } async function apiTermsFind(text) { - const options = backend().options; - const translator = backend().translator; + const options = utilBackend().options; + const translator = utilBackend().translator; const searcher = options.general.groupResults ? translator.findTermsGrouped.bind(translator) : @@ -63,13 +50,13 @@ async function apiTermsFind(text) { } async function apiKanjiFind(text) { - const options = backend().options; - const definitions = await backend().translator.findKanji(text, dictEnabledSet(options)); + const options = utilBackend().options; + const definitions = await utilBackend().translator.findKanji(text, dictEnabledSet(options)); return definitions.slice(0, options.general.maxResults); } async function apiDefinitionAdd(definition, mode) { - const options = backend().options; + const options = utilBackend().options; if (mode !== 'kanji') { await audioInject( @@ -79,18 +66,18 @@ async function apiDefinitionAdd(definition, mode) { ); } - return backend().anki.addNote(dictNoteFormat(definition, mode, options)); + return utilBackend().anki.addNote(dictNoteFormat(definition, mode, options)); } async function apiDefinitionsAddable(definitions, modes) { const notes = []; for (const definition of definitions) { for (const mode of modes) { - notes.push(dictNoteFormat(definition, mode, backend().options)); + notes.push(dictNoteFormat(definition, mode, utilBackend().options)); } } - const results = await backend().anki.canAddNotes(notes); + const results = await utilBackend().anki.canAddNotes(notes); const states = []; for (let resultBase = 0; resultBase < results.length; resultBase += modes.length) { const state = {}; @@ -105,7 +92,7 @@ async function apiDefinitionsAddable(definitions, modes) { } async function apiNoteView(noteId) { - return backend().anki.guiBrowse(`nid:${noteId}`); + return utilBackend().anki.guiBrowse(`nid:${noteId}`); } async function apiTemplateRender(template, data) { @@ -127,7 +114,7 @@ async function apiCommandExec(command) { }, toggle: async () => { - const options = backend().options; + const options = utilBackend().options; options.general.enable = !options.general.enable; await optionsSave(options); await apiOptionsSet(options); diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js index 1c058433..f61e9742 100644 --- a/ext/bg/js/backend.js +++ b/ext/bg/js/backend.js @@ -50,9 +50,9 @@ window.yomichan_backend = new class { } if (options.anki.enable) { - backend().anki = new AnkiConnect(options.anki.server); + this.anki = new AnkiConnect(options.anki.server); } else { - backend().anki = new AnkiNull(); + this.anki = new AnkiNull(); } chrome.tabs.query({}, tabs => { diff --git a/ext/bg/js/settings.js b/ext/bg/js/settings.js index 1edbab01..ce9e14a2 100644 --- a/ext/bg/js/settings.js +++ b/ext/bg/js/settings.js @@ -17,39 +17,6 @@ */ -/* - * Utilities - */ - -function utilAnkiGetModelNames() { - return backend().anki.getModelNames(); -} - -function utilAnkiGetDeckNames() { - return backend().anki.getDeckNames(); -} - -function utilAnkiGetModelFieldNames(modelName) { - return backend().anki.getModelFieldNames(modelName); -} - -function utilDatabaseGetDictionaries() { - return backend().translator.database.getDictionaries(); -} - -function utilDatabasePurge() { - return backend().translator.database.purge(); -} - -function utilDatabaseImport(data, progress) { - return backend().translator.database.importDictionary(data, progress); -} - - -/* - * General - */ - async function formRead() { const optionsOld = await optionsLoad(); const optionsNew = $.extend(true, {}, optionsOld); diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js new file mode 100644 index 00000000..9dc57950 --- /dev/null +++ b/ext/bg/js/util.js @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2016 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 . + */ + + +function utilBackend() { + return chrome.extension.getBackgroundPage().yomichan_backend; +} + +function utilAnkiGetModelNames() { + return utilBackend().anki.getModelNames(); +} + +function utilAnkiGetDeckNames() { + return utilBackend().anki.getDeckNames(); +} + +function utilAnkiGetModelFieldNames(modelName) { + return utilBackend().anki.getModelFieldNames(modelName); +} + +function utilDatabaseGetDictionaries() { + return utilBackend().translator.database.getDictionaries(); +} + +function utilDatabasePurge() { + return utilBackend().translator.database.purge(); +} + +function utilDatabaseImport(data, progress) { + return utilBackend().translator.database.importDictionary(data, progress); +} diff --git a/ext/bg/settings.html b/ext/bg/settings.html index 7833a21d..719c67a2 100644 --- a/ext/bg/settings.html +++ b/ext/bg/settings.html @@ -283,6 +283,7 @@ + -- cgit v1.2.3 From bdf231082f4b4ca7c4c90d8b0cd40b6c4201723d Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Mon, 14 Aug 2017 21:43:09 -0700 Subject: lots of fixes to backend --- ext/bg/context.html | 5 +---- ext/bg/js/anki.js | 9 +++++++++ ext/bg/js/api.js | 2 +- ext/bg/js/backend.js | 20 +++++++++++++------ ext/bg/js/context.js | 4 ++-- ext/bg/js/database.js | 2 +- ext/bg/js/deinflector.js | 2 +- ext/bg/js/dictionary.js | 2 +- ext/bg/js/handlebars.js | 2 +- ext/bg/js/search.js | 5 ++--- ext/bg/js/settings.js | 50 ++++++++++++++++++++++++------------------------ ext/bg/js/util.js | 7 ++++++- ext/bg/settings.html | 3 +-- ext/fg/js/api.js | 22 ++++++++++++++------- ext/fg/js/frontend.js | 2 +- ext/fg/js/popup.js | 2 +- ext/mixed/js/display.js | 9 +++++---- 17 files changed, 87 insertions(+), 61 deletions(-) (limited to 'ext/bg/js/util.js') diff --git a/ext/bg/context.html b/ext/bg/context.html index 3828c9fe..8a72acc7 100644 --- a/ext/bg/context.html +++ b/ext/bg/context.html @@ -30,13 +30,10 @@ - - - - + diff --git a/ext/bg/js/anki.js b/ext/bg/js/anki.js index f0ec4571..c327969f 100644 --- a/ext/bg/js/anki.js +++ b/ext/bg/js/anki.js @@ -17,6 +17,10 @@ */ +/* + * AnkiConnect + */ + class AnkiConnect { constructor(server) { this.server = server; @@ -68,6 +72,11 @@ class AnkiConnect { } } + +/* + * AnkiNull + */ + class AnkiNull { async addNote(note) { return null; diff --git a/ext/bg/js/api.js b/ext/bg/js/api.js index 024ba75e..b55e306f 100644 --- a/ext/bg/js/api.js +++ b/ext/bg/js/api.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alex Yatskov + * Copyright (C) 2016-2017 Alex Yatskov * Author: Alex Yatskov * * This program is free software: you can redistribute it and/or modify diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js index e8c9452c..97e5602a 100644 --- a/ext/bg/js/backend.js +++ b/ext/bg/js/backend.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alex Yatskov + * Copyright (C) 2016-2017 Alex Yatskov * Author: Alex Yatskov * * This program is free software: you can redistribute it and/or modify @@ -77,7 +77,11 @@ class Backend { const handlers = { optionsGet: ({callback}) => { - forward(optionsLoad(), callback); + forward(apiOptionsGet(), callback); + }, + + optionsSet: ({options, callback}) => { + forward(apiOptionsSet(options), callback); }, kanjiFind: ({text, callback}) => { @@ -88,10 +92,6 @@ class Backend { forward(apiTermsFind(text), callback); }, - templateRender: ({template, data, callback}) => { - forward(apiTemplateRender(template, data), callback); - }, - definitionAdd: ({definition, mode, callback}) => { forward(apiDefinitionAdd(definition, mode), callback); }, @@ -102,6 +102,14 @@ class Backend { noteView: ({noteId}) => { forward(apiNoteView(noteId), callback); + }, + + templateRender: ({template, data, callback}) => { + forward(apiTemplateRender(template, data), callback); + }, + + commandExec: ({command, callback}) => { + forward(apiCommandExec(command), callback); } }; diff --git a/ext/bg/js/context.js b/ext/bg/js/context.js index 77cb5166..689d6863 100644 --- a/ext/bg/js/context.js +++ b/ext/bg/js/context.js @@ -17,7 +17,7 @@ */ -$(document).ready(() => { +$(document).ready(utilAsync(() => { $('#open-search').click(() => apiCommandExec('search')); $('#open-options').click(() => apiCommandExec('options')); $('#open-help').click(() => apiCommandExec('help')); @@ -28,4 +28,4 @@ $(document).ready(() => { toggle.bootstrapToggle(); toggle.change(() => apiCommandExec('toggle')); }); -}); +})); diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js index b38e00db..e00cb7a3 100644 --- a/ext/bg/js/database.js +++ b/ext/bg/js/database.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alex Yatskov + * Copyright (C) 2016-2017 Alex Yatskov * Author: Alex Yatskov * * This program is free software: you can redistribute it and/or modify diff --git a/ext/bg/js/deinflector.js b/ext/bg/js/deinflector.js index 8b67761b..0abde99d 100644 --- a/ext/bg/js/deinflector.js +++ b/ext/bg/js/deinflector.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alex Yatskov + * Copyright (C) 2016-2017 Alex Yatskov * Author: Alex Yatskov * * This program is free software: you can redistribute it and/or modify diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js index 6f9b30e4..c8d431b9 100644 --- a/ext/bg/js/dictionary.js +++ b/ext/bg/js/dictionary.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alex Yatskov + * Copyright (C) 2016-2017 Alex Yatskov * Author: Alex Yatskov * * This program is free software: you can redistribute it and/or modify diff --git a/ext/bg/js/handlebars.js b/ext/bg/js/handlebars.js index df98bef1..debb0690 100644 --- a/ext/bg/js/handlebars.js +++ b/ext/bg/js/handlebars.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alex Yatskov + * Copyright (C) 2016-2017 Alex Yatskov * Author: Alex Yatskov * * This program is free software: you can redistribute it and/or modify diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js index 87f50c32..54cda8ec 100644 --- a/ext/bg/js/search.js +++ b/ext/bg/js/search.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alex Yatskov + * Copyright (C) 2016-2017 Alex Yatskov * Author: Alex Yatskov * * This program is free software: you can redistribute it and/or modify @@ -41,9 +41,8 @@ class DisplaySearch extends Display { } async onSearch(e) { - e.preventDefault(); - try { + e.preventDefault(); this.intro.slideUp(); const {length, definitions} = await apiTermsFind(this.query.val()); super.termsShow(definitions, await apiOptionsGet()); diff --git a/ext/bg/js/settings.js b/ext/bg/js/settings.js index ce9e14a2..89b1581f 100644 --- a/ext/bg/js/settings.js +++ b/ext/bg/js/settings.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alex Yatskov + * Copyright (C) 2016-2017 Alex Yatskov * Author: Alex Yatskov * * This program is free software: you can redistribute it and/or modify @@ -90,12 +90,12 @@ function formUpdateVisibility(options) { } } -async function onFormOptionsChanged(e) {(async () => { - if (!e.originalEvent && !e.isTrigger) { - return; - } - +async function onFormOptionsChanged(e) { try { + if (!e.originalEvent && !e.isTrigger) { + return; + } + ankiErrorShow(); ankiSpinnerShow(true); @@ -116,9 +116,9 @@ async function onFormOptionsChanged(e) {(async () => { } finally { ankiSpinnerShow(false); } -})();} +} -function onReady() {(async () => { +async function onReady() { const options = await optionsLoad(); $('#show-usage-guide').prop('checked', options.general.showGuide); @@ -139,16 +139,16 @@ function onReady() {(async () => { $('#scan-length').val(options.scanning.length); $('#scan-modifier-key').val(options.scanning.modifier); - $('#dict-purge').click(onDictionaryPurge); - $('#dict-file').change(onDictionaryImport); + $('#dict-purge').click(utilAsync(onDictionaryPurge)); + $('#dict-file').change(utilAsync(onDictionaryImport)); $('#anki-enable').prop('checked', options.anki.enable); $('#card-tags').val(options.anki.tags.join(' ')); $('#generate-html-cards').prop('checked', options.anki.htmlCards); $('#sentence-detection-extent').val(options.anki.sentenceExt); $('#interface-server').val(options.anki.server); - $('input, select').not('.anki-model').change(onFormOptionsChanged); - $('.anki-model').change(onAnkiModelChanged); + $('input, select').not('.anki-model').change(utilAsync(onFormOptionsChanged)); + $('.anki-model').change(utilAsync(onAnkiModelChanged)); try { await dictionaryGroupsPopulate(options); @@ -163,9 +163,9 @@ function onReady() {(async () => { } formUpdateVisibility(options); -})();} +} -$(document).ready(onReady); +$(document).ready(utilAsync(onReady)); /* @@ -237,7 +237,7 @@ async function dictionaryGroupsPopulate(options) { }); } -async function onDictionaryPurge(e) {(async () => { +async function onDictionaryPurge(e) { e.preventDefault(); const dictControls = $('#dict-importer, #dict-groups').hide(); @@ -261,9 +261,9 @@ async function onDictionaryPurge(e) {(async () => { dictControls.show(); dictProgress.hide(); } -})();} +} -function onDictionaryImport(e) {(async () => { +async function onDictionaryImport(e) { const dictFile = $('#dict-file'); const dictControls = $('#dict-importer').hide(); const dictProgress = $('#dict-import-progress').show(); @@ -291,7 +291,7 @@ function onDictionaryImport(e) {(async () => { dictControls.show(); dictProgress.hide(); } -})();} +} /* @@ -398,7 +398,7 @@ async function ankiFieldsPopulate(element, options) { container.append($(html)); } - tab.find('.anki-field-value').change(onFormOptionsChanged); + tab.find('.anki-field-value').change(utilAsync(onFormOptionsChanged)); tab.find('.marker-link').click(onAnkiMarkerClicked); } @@ -408,12 +408,12 @@ function onAnkiMarkerClicked(e) { $(link).closest('.input-group').find('.anki-field-value').val(`{${link.text}}`).trigger('change'); } -function onAnkiModelChanged(e) {(async () => { - if (!e.originalEvent) { - return; - } - +async function onAnkiModelChanged(e) { try { + if (!e.originalEvent) { + return; + } + ankiErrorShow(); ankiSpinnerShow(true); @@ -431,4 +431,4 @@ function onAnkiModelChanged(e) {(async () => { } finally { ankiSpinnerShow(false); } -})();} +} diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js index 9dc57950..11ec23eb 100644 --- a/ext/bg/js/util.js +++ b/ext/bg/js/util.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alex Yatskov + * Copyright (C) 2016-2017 Alex Yatskov * Author: Alex Yatskov * * This program is free software: you can redistribute it and/or modify @@ -16,6 +16,11 @@ * along with this program. If not, see . */ +function utilAsync(func) { + return function(...args) { + func.apply(this, args); + }; +} function utilBackend() { return chrome.extension.getBackgroundPage().yomichan_backend; diff --git a/ext/bg/settings.html b/ext/bg/settings.html index 719c67a2..237750b3 100644 --- a/ext/bg/settings.html +++ b/ext/bg/settings.html @@ -276,8 +276,7 @@ - - + diff --git a/ext/fg/js/api.js b/ext/fg/js/api.js index b4d75c3c..174531ba 100644 --- a/ext/fg/js/api.js +++ b/ext/fg/js/api.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alex Yatskov + * Copyright (C) 2016-2017 Alex Yatskov * Author: Alex Yatskov * * This program is free software: you can redistribute it and/or modify @@ -17,6 +17,10 @@ */ +function apiOptionsSet(options) { + return utilInvoke('optionsSet', {options}); +} + function apiOptionsGet() { return utilInvoke('optionsGet'); } @@ -29,18 +33,22 @@ function apiKanjiFind(text) { return utilInvoke('kanjiFind', {text}); } -function apiTemplateRender(template, data) { - return utilInvoke('templateRender', {data, template}); +function apiDefinitionAdd(definition, mode) { + return utilInvoke('definitionAdd', {definition, mode}); } function apiDefinitionsAddable(definitions, modes) { return utilInvoke('definitionsAddable', {definitions, modes}).catch(() => null); } -function apiDefinitionAdd(definition, mode) { - return utilInvoke('definitionAdd', {definition, mode}); -} - function apiNoteView(noteId) { return utilInvoke('noteView', {noteId}); } + +function apiTemplateRender(template, data) { + return utilInvoke('templateRender', {data, template}); +} + +function apiCommandExec(command) { + return utilInvoke('commandExec', {command}); +} diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js index 005139e6..cc4d99c8 100644 --- a/ext/fg/js/frontend.js +++ b/ext/fg/js/frontend.js @@ -230,7 +230,7 @@ class Frontend { const sentence = docSentenceExtract(textSource, this.options.anki.sentenceExt); const url = window.location.href; - this.popup.showKanji( + this.popup.kanjiShow( textSource.getRect(), definitions, this.options, diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js index 8e61169a..8cb16b5a 100644 --- a/ext/fg/js/popup.js +++ b/ext/fg/js/popup.js @@ -102,7 +102,7 @@ class Popup { async kanjiShow(elementRect, definitions, options, context) { await this.show(elementRect, options); - this.invokeApi('termsShow', {definitions, options, context}); + this.invokeApi('kanjiShow', {definitions, options, context}); } invokeApi(action, params={}) { diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 97dd7d5c..21748f5d 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -42,7 +42,7 @@ class Display { onSourceTermView(e) { e.preventDefault(); - this.sourceBack(); + this.sourceTermView(); } async onKanjiLookup(e) { @@ -154,7 +154,7 @@ class Display { 66: /* b */ () => { if (e.altKey) { - this.sourceBack(); + this.sourceTermView(); return true; } }, @@ -276,6 +276,7 @@ class Display { this.entryScrollIntoView(context && context.index || 0); $('.action-add-note').click(this.onNoteAdd.bind(this)); + $('.action-view-note').click(this.onNoteView.bind(this)); $('.source-term').click(this.onSourceTermView.bind(this)); await this.adderButtonUpdate(['kanji'], sequence); @@ -288,7 +289,7 @@ class Display { try { this.spinner.show(); - const states = apiDefinitionsAddable(this.definitions, modes); + const states = await apiDefinitionsAddable(this.definitions, modes); if (!states || sequence !== this.sequence) { return; } @@ -332,7 +333,7 @@ class Display { this.index = index; } - sourceBack() { + sourceTermView() { if (this.context && this.context.source) { const context = { url: this.context.source.url, -- cgit v1.2.3 From 84d2204d966342fa03635b4b8a860bb48a418bc0 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Tue, 15 Aug 2017 21:51:48 -0700 Subject: firefox fixes --- ext/bg/js/api.js | 8 ++------ ext/bg/js/util.js | 4 ++++ 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'ext/bg/js/util.js') diff --git a/ext/bg/js/api.js b/ext/bg/js/api.js index 8b4c3896..4b6729ad 100644 --- a/ext/bg/js/api.js +++ b/ext/bg/js/api.js @@ -18,15 +18,11 @@ async function apiOptionsSet(options) { - // In Firefox, setting options from the options UI somehow carries references - // to the DOM across to the background page, causing the options object to - // become a "DeadObject" after the options page is closed. The workaround used - // here is to create a deep copy of the options object. - utilBackend().onOptionsUpdated(JSON.parse(JSON.stringify(options))); + utilBackend().onOptionsUpdated(utilIsolate(options)); } async function apiOptionsGet() { - return utilBackend().options; + return utilIsolate(utilBackend().options); } async function apiTermsFind(text) { diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js index 11ec23eb..a92fd0bc 100644 --- a/ext/bg/js/util.js +++ b/ext/bg/js/util.js @@ -22,6 +22,10 @@ function utilAsync(func) { }; } +function utilIsolate(data) { + return JSON.parse(JSON.stringify(data)); +} + function utilBackend() { return chrome.extension.getBackgroundPage().yomichan_backend; } -- cgit v1.2.3