Merge branch 'master' into firefox-amo

This commit is contained in:
Alex Yatskov 2017-08-17 19:39:32 -07:00
commit 39fbabfe62
44 changed files with 2664 additions and 2429 deletions

View File

@ -229,6 +229,7 @@ exact versions used for distribution.
* Dexie: [homepage](http://dexie.org/) - [snapshot](https://github.com/dfahlander/Dexie.js/archive/v2.0.0-beta.10.zip) * Dexie: [homepage](http://dexie.org/) - [snapshot](https://github.com/dfahlander/Dexie.js/archive/v2.0.0-beta.10.zip)
* Handlebars: [homepage](http://handlebarsjs.com/) - [snapshot](http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars.min-714a4c4.js) * Handlebars: [homepage](http://handlebarsjs.com/) - [snapshot](http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars.min-714a4c4.js)
* JQuery: [homepage](https://blog.jquery.com/) - [snapshot](https://code.jquery.com/jquery-3.2.1.min.js) * JQuery: [homepage](https://blog.jquery.com/) - [snapshot](https://code.jquery.com/jquery-3.2.1.min.js)
* JSZip: [homepage](http://stuk.github.io/jszip/) - [snapshot](https://raw.githubusercontent.com/Stuk/jszip/de7f52fbcba485737bef7923a83f0fad92d9f5bc/dist/jszip.min.js)
* WanaKana: [homepage](http://wanakana.com/) - [snapshot](https://raw.githubusercontent.com/WaniKani/WanaKana/f2152985f5f2953d74edfe1b6a78e0e329a7cdfb/lib/wanakana.min.js) * WanaKana: [homepage](http://wanakana.com/) - [snapshot](https://raw.githubusercontent.com/WaniKani/WanaKana/f2152985f5f2953d74edfe1b6a78e0e329a7cdfb/lib/wanakana.min.js)
## Frequently Asked Questions ## ## Frequently Asked Questions ##
@ -288,4 +289,16 @@ exact versions used for distribution.
## License ## ## License ##
GPL 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 <http://www.gnu.org/licenses/>.

View File

@ -4,18 +4,25 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
</head> </head>
<body> <body>
<script src="/mixed/lib/handlebars.min.js"></script>
<script src="/mixed/lib/dexie.min.js"></script> <script src="/mixed/lib/dexie.min.js"></script>
<script src="/mixed/lib/wanakana.min.js"></script> <script src="/mixed/lib/handlebars.min.js"></script>
<script src="/mixed/lib/jszip.min.js"></script> <script src="/mixed/lib/jszip.min.js"></script>
<script src="/mixed/js/util.js"></script> <script src="/mixed/lib/wanakana.min.js"></script>
<script src="/bg/js/templates.js"></script>
<script src="/bg/js/util.js"></script> <script src="/bg/js/anki.js"></script>
<script src="/bg/js/anki-connect.js"></script> <script src="/bg/js/api.js"></script>
<script src="/bg/js/anki-null.js"></script> <script src="/bg/js/audio.js"></script>
<script src="/bg/js/database.js"></script> <script src="/bg/js/database.js"></script>
<script src="/bg/js/deinflector.js"></script> <script src="/bg/js/deinflector.js"></script>
<script src="/bg/js/dictionary.js"></script>
<script src="/bg/js/handlebars.js"></script>
<script src="/bg/js/options.js"></script>
<script src="/bg/js/request.js"></script>
<script src="/bg/js/templates.js"></script>
<script src="/bg/js/translator.js"></script> <script src="/bg/js/translator.js"></script>
<script src="/bg/js/yomichan.js"></script> <script src="/bg/js/util.js"></script>
<script src="/mixed/js/japanese.js"></script>
<script src="/bg/js/backend.js"></script>
</body> </body>
</html> </html>

View File

@ -27,10 +27,14 @@
<button type="button" id="open-help" title="Help" class="btn btn-default btn-xs glyphicon glyphicon-question-sign"></button> <button type="button" id="open-help" title="Help" class="btn btn-default btn-xs glyphicon glyphicon-question-sign"></button>
</div> </div>
</p> </p>
<script src="/mixed/lib/jquery.min.js"></script> <script src="/mixed/lib/jquery.min.js"></script>
<script src="/mixed/lib/bootstrap-toggle/bootstrap-toggle.min.js"></script> <script src="/mixed/lib/bootstrap-toggle/bootstrap-toggle.min.js"></script>
<script src="/mixed/lib/handlebars.min.js"></script>
<script src="/bg/js/api.js"></script>
<script src="/bg/js/options.js"></script>
<script src="/bg/js/util.js"></script> <script src="/bg/js/util.js"></script>
<script src="/bg/js/popup.js"></script>
<script src="/bg/js/context.js"></script>
</body> </body>
</html> </html>

View File

@ -1,84 +0,0 @@
/*
* Copyright (C) 2016 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net>
*
* 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 <http://www.gnu.org/licenses/>.
*/
class AnkiConnect {
constructor(server) {
this.server = server;
this.asyncPools = {};
this.localVersion = 2;
this.remoteVersion = null;
}
addNote(note) {
return this.checkVersion().then(() => this.ankiInvoke('addNote', {note}, null));
}
canAddNotes(notes) {
return this.checkVersion().then(() => this.ankiInvoke('canAddNotes', {notes}, 'notes'));
}
getDeckNames() {
return this.checkVersion().then(() => this.ankiInvoke('deckNames', {}, null));
}
getModelNames() {
return this.checkVersion().then(() => this.ankiInvoke('modelNames', {}, null));
}
getModelFieldNames(modelName) {
return this.checkVersion().then(() => this.ankiInvoke('modelFieldNames', {modelName}, null));
}
checkVersion() {
if (this.localVersion === this.remoteVersion) {
return Promise.resolve(true);
}
return this.ankiInvoke('version', {}, null).then(version => {
this.remoteVersion = 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 !== null && this.asyncPools.hasOwnProperty(pool)) {
this.asyncPools[pool].abort();
}
const xhr = new XMLHttpRequest();
xhr.addEventListener('loadend', () => {
if (pool !== null) {
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}));
});
}
}

104
ext/bg/js/anki.js Normal file
View File

@ -0,0 +1,104 @@
/*
* Copyright (C) 2016 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net>
*
* 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 <http://www.gnu.org/licenses/>.
*/
/*
* AnkiConnect
*/
class AnkiConnect {
constructor(server) {
this.server = server;
this.localVersion = 2;
this.remoteVersion = 0;
}
async addNote(note) {
await this.checkVersion();
return await this.ankiInvoke('addNote', {note});
}
async canAddNotes(notes) {
await this.checkVersion();
return await this.ankiInvoke('canAddNotes', {notes});
}
async getDeckNames() {
await this.checkVersion();
return await this.ankiInvoke('deckNames');
}
async getModelNames() {
await this.checkVersion();
return await this.ankiInvoke('modelNames');
}
async getModelFieldNames(modelName) {
await this.checkVersion();
return await this.ankiInvoke('modelFieldNames', {modelName});
}
async guiBrowse(query) {
await this.checkVersion();
return await this.ankiInvoke('guiBrowse', {query});
}
async checkVersion() {
if (this.remoteVersion < this.localVersion) {
this.remoteVersion = await this.ankiInvoke('version');
if (this.remoteVersion < this.localVersion) {
throw 'extension and plugin versions incompatible';
}
}
}
ankiInvoke(action, params) {
return requestJson(this.server, 'POST', {action, params, version: this.localVersion});
}
}
/*
* AnkiNull
*/
class AnkiNull {
async addNote(note) {
return null;
}
async canAddNotes(notes) {
return [];
}
async getDeckNames() {
return [];
}
async getModelNames() {
return [];
}
async getModelFieldNames(modelName) {
return [];
}
async guiBrowse(query) {
return [];
}
}

128
ext/bg/js/api.js Normal file
View File

@ -0,0 +1,128 @@
/*
* Copyright (C) 2016-2017 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net>
*
* 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 <http://www.gnu.org/licenses/>.
*/
async function apiOptionsSet(options) {
utilBackend().onOptionsUpdated(options);
}
async function apiOptionsGet() {
return utilBackend().options;
}
async function apiTermsFind(text) {
const options = utilBackend().options;
const translator = utilBackend().translator;
const searcher = options.general.groupResults ?
translator.findTermsGrouped.bind(translator) :
translator.findTerms.bind(translator);
const {definitions, length} = await searcher(
text,
dictEnabledSet(options),
options.scanning.alphanumeric
);
return {
length,
definitions: definitions.slice(0, options.general.maxResults)
};
}
async function apiKanjiFind(text) {
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 = utilBackend().options;
if (mode !== 'kanji') {
await audioInject(
definition,
options.anki.terms.fields,
options.general.audioSource
);
}
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, utilBackend().options));
}
}
const results = await utilBackend().anki.canAddNotes(notes);
const states = [];
for (let resultBase = 0; resultBase < results.length; resultBase += modes.length) {
const state = {};
for (let modeOffset = 0; modeOffset < modes.length; ++modeOffset) {
state[modes[modeOffset]] = results[resultBase + modeOffset];
}
states.push(state);
}
return states;
}
async function apiNoteView(noteId) {
return utilBackend().anki.guiBrowse(`nid:${noteId}`);
}
async function apiTemplateRender(template, data) {
return handlebarsRender(template, data);
}
async function apiCommandExec(command) {
const handlers = {
search: () => {
chrome.tabs.create({url: chrome.extension.getURL('/bg/search.html')});
},
help: () => {
chrome.tabs.create({url: 'https://foosoft.net/projects/yomichan/'});
},
options: () => {
chrome.runtime.openOptionsPage();
},
toggle: async () => {
const options = utilBackend().options;
options.general.enable = !options.general.enable;
await optionsSave(options);
await apiOptionsSet(options);
}
};
const handler = handlers[command];
if (handler) {
handler();
}
}
async function apiAudioGetUrl(definition, source) {
return audioBuildUrl(definition, source);
}

View File

@ -17,30 +17,7 @@
*/ */
/* async function audioBuildUrl(definition, mode, cache={}) {
* Cloze
*/
function clozeBuild(sentence, source) {
const result = {
sentence: sentence.text.trim()
};
if (source) {
result.prefix = sentence.text.substring(0, sentence.offset).trim();
result.body = source.trim();
result.suffix = sentence.text.substring(sentence.offset + source.length).trim();
}
return result;
}
/*
* Audio
*/
function audioBuildUrl(definition, mode, cache={}) {
if (mode === 'jpod101') { if (mode === 'jpod101') {
let kana = definition.reading; let kana = definition.reading;
let kanji = definition.expression; let kanji = definition.expression;
@ -102,8 +79,36 @@ function audioBuildUrl(definition, mode, cache={}) {
} }
} }
}); });
} else { } else if (mode === 'jisho') {
return Promise.reject('unsupported audio source'); return new Promise((resolve, reject) => {
const response = cache[definition.expression];
if (response) {
resolve(response);
} else {
const xhr = new XMLHttpRequest();
xhr.open('GET', `http://jisho.org/search/${definition.expression}`);
xhr.addEventListener('error', () => reject('failed to scrape audio data'));
xhr.addEventListener('load', () => {
cache[definition.expression] = xhr.responseText;
resolve(xhr.responseText);
});
xhr.send();
}
}).then(response => {
try {
const dom = new DOMParser().parseFromString(response, 'text/html');
const audio = dom.getElementById(`audio_${definition.expression}:${definition.reading}`);
if (audio) {
return audio.getElementsByTagName('source').item(0).getAttribute('src');
}
} catch (e) {
// NOP
}
});
}
else {
return Promise.resolve();
} }
} }
@ -121,16 +126,7 @@ function audioBuildFilename(definition) {
} }
} }
function audioInject(definition, fields, mode) { async function audioInject(definition, fields, mode) {
if (mode === 'disabled') {
return Promise.resolve(true);
}
const filename = audioBuildFilename(definition);
if (!filename) {
return Promise.resolve(true);
}
let usesAudio = false; let usesAudio = false;
for (const name in fields) { for (const name in fields) {
if (fields[name].includes('{audio}')) { if (fields[name].includes('{audio}')) {
@ -140,11 +136,19 @@ function audioInject(definition, fields, mode) {
} }
if (!usesAudio) { if (!usesAudio) {
return Promise.resolve(true); return true;
} }
return audioBuildUrl(definition, mode).then(url => { try {
definition.audio = {url, filename}; const url = await audioBuildUrl(definition, mode);
const filename = audioBuildFilename(definition);
if (url && filename) {
definition.audio = {url, filename};
}
return true; return true;
}).catch(() => false); } catch (e) {
return false;
}
} }

131
ext/bg/js/backend.js Normal file
View File

@ -0,0 +1,131 @@
/*
* Copyright (C) 2016-2017 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net>
*
* 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 <http://www.gnu.org/licenses/>.
*/
class Backend {
constructor() {
this.translator = new Translator();
this.anki = new AnkiNull();
this.options = null;
}
async prepare() {
await this.translator.prepare();
await apiOptionsSet(await optionsLoad());
chrome.commands.onCommand.addListener(this.onCommand.bind(this));
chrome.runtime.onMessage.addListener(this.onMessage.bind(this));
if (this.options.general.showGuide) {
chrome.tabs.create({url: chrome.extension.getURL('/bg/guide.html')});
}
}
onOptionsUpdated(options) {
this.options = utilIsolate(options);
if (!options.general.enable) {
chrome.browserAction.setBadgeBackgroundColor({color: '#555555'});
chrome.browserAction.setBadgeText({text: 'off'});
} else if (!dictConfigured(options)) {
chrome.browserAction.setBadgeBackgroundColor({color: '#f0ad4e'});
chrome.browserAction.setBadgeText({text: '!'});
} else {
chrome.browserAction.setBadgeText({text: ''});
}
if (options.anki.enable) {
this.anki = new AnkiConnect(options.anki.server);
} else {
this.anki = new AnkiNull();
}
chrome.tabs.query({}, tabs => {
for (const tab of tabs) {
chrome.tabs.sendMessage(tab.id, {action: 'optionsSet', params: options}, () => null);
}
});
}
onCommand(command) {
apiCommandExec(command);
}
onMessage({action, params}, sender, callback) {
const forward = (promise, callback) => {
return promise.then(result => {
callback({result});
}).catch(error => {
callback({error});
});
};
const handlers = {
optionsGet: ({callback}) => {
forward(apiOptionsGet(), callback);
},
optionsSet: ({options, callback}) => {
forward(apiOptionsSet(options), callback);
},
kanjiFind: ({text, callback}) => {
forward(apiKanjiFind(text), callback);
},
termsFind: ({text, callback}) => {
forward(apiTermsFind(text), callback);
},
definitionAdd: ({definition, mode, callback}) => {
forward(apiDefinitionAdd(definition, mode), callback);
},
definitionsAddable: ({definitions, modes, callback}) => {
forward(apiDefinitionsAddable(definitions, modes), callback);
},
noteView: ({noteId}) => {
forward(apiNoteView(noteId), callback);
},
templateRender: ({template, data, callback}) => {
forward(apiTemplateRender(template, data), callback);
},
commandExec: ({command, callback}) => {
forward(apiCommandExec(command), callback);
},
audioGetUrl: ({definition, source, callback}) => {
forward(apiAudioGetUrl(definition, source), callback);
}
};
const handler = handlers[action];
if (handler) {
params.callback = callback;
handler(params);
}
return true;
}
}
window.yomichan_backend = new Backend();
window.yomichan_backend.prepare();

View File

@ -17,15 +17,15 @@
*/ */
$(document).ready(() => { $(document).ready(utilAsync(() => {
$('#open-search').click(() => commandExec('search')); $('#open-search').click(() => apiCommandExec('search'));
$('#open-options').click(() => commandExec('options')); $('#open-options').click(() => apiCommandExec('options'));
$('#open-help').click(() => commandExec('help')); $('#open-help').click(() => apiCommandExec('help'));
optionsLoad().then(options => { optionsLoad().then(options => {
const toggle = $('#enable-search'); const toggle = $('#enable-search');
toggle.prop('checked', options.general.enable).change(); toggle.prop('checked', options.general.enable).change();
toggle.bootstrapToggle(); toggle.bootstrapToggle();
toggle.change(() => commandExec('toggle')); toggle.change(() => apiCommandExec('toggle'));
}); });
}); }));

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2016 Alex Yatskov <alex@foosoft.net> * Copyright (C) 2016-2017 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net> * Author: Alex Yatskov <alex@foosoft.net>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@ -20,59 +20,62 @@
class Database { class Database {
constructor() { constructor() {
this.db = null; this.db = null;
this.dbVersion = 2; this.version = 2;
this.tagMetaCache = {}; this.tagCache = {};
} }
sanitize() { async sanitize() {
const db = new Dexie('dict'); try {
return db.open().then(() => { const db = new Dexie('dict');
await db.open();
db.close(); db.close();
if (db.verno !== this.dbVersion) { if (db.verno !== this.version) {
return db.delete(); await db.delete();
} }
}).catch(() => {}); } catch(e) {
// NOP
}
} }
prepare() { async prepare() {
if (this.db !== null) { if (this.db) {
return Promise.reject('database already initialized'); throw 'database already initialized';
} }
return this.sanitize().then(() => { await this.sanitize();
this.db = new Dexie('dict');
this.db.version(this.dbVersion).stores({
terms: '++id,dictionary,expression,reading',
kanji: '++,dictionary,character',
tagMeta: '++,dictionary',
dictionaries: '++,title,version'
});
return this.db.open(); this.db = new Dexie('dict');
this.db.version(this.version).stores({
terms: '++id,dictionary,expression,reading',
kanji: '++,dictionary,character',
tagMeta: '++,dictionary',
dictionaries: '++,title,version'
}); });
await this.db.open();
} }
purge() { async purge() {
if (this.db === null) { if (!this.db) {
return Promise.reject('database not initialized'); throw 'database not initialized';
} }
this.db.close(); this.db.close();
return this.db.delete().then(() => { await this.db.delete();
this.db = null; this.db = null;
this.tagMetaCache = {}; this.tagCache = {};
return this.prepare();
}); await this.prepare();
} }
findTerms(term, dictionaries) { async findTerms(term, titles) {
if (this.db === null) { if (!this.db) {
return Promise.reject('database not initialized'); throw 'database not initialized';
} }
const results = []; const results = [];
return this.db.terms.where('expression').equals(term).or('reading').equals(term).each(row => { await this.db.terms.where('expression').equals(term).or('reading').equals(term).each(row => {
if (dictionaries.includes(row.dictionary)) { if (titles.includes(row.dictionary)) {
results.push({ results.push({
expression: row.expression, expression: row.expression,
reading: row.reading, reading: row.reading,
@ -84,25 +87,24 @@ class Database {
id: row.id id: row.id
}); });
} }
}).then(() => {
return this.cacheTagMeta(dictionaries);
}).then(() => {
for (const result of results) {
result.tagMeta = this.tagMetaCache[result.dictionary] || {};
}
return results;
}); });
await this.cacheTagMeta(titles);
for (const result of results) {
result.tagMeta = this.tagCache[result.dictionary] || {};
}
return results;
} }
findKanji(kanji, dictionaries) { async findKanji(kanji, titles) {
if (this.db === null) { if (!this.db) {
return Promise.reject('database not initialized'); return Promise.reject('database not initialized');
} }
const results = []; const results = [];
return this.db.kanji.where('character').equals(kanji).each(row => { await this.db.kanji.where('character').equals(kanji).each(row => {
if (dictionaries.includes(row.dictionary)) { if (titles.includes(row.dictionary)) {
results.push({ results.push({
character: row.character, character: row.character,
onyomi: dictFieldSplit(row.onyomi), onyomi: dictFieldSplit(row.onyomi),
@ -112,83 +114,79 @@ class Database {
dictionary: row.dictionary dictionary: row.dictionary
}); });
} }
}).then(() => {
return this.cacheTagMeta(dictionaries);
}).then(() => {
for (const result of results) {
result.tagMeta = this.tagMetaCache[result.dictionary] || {};
}
return results;
}); });
}
cacheTagMeta(dictionaries) { await this.cacheTagMeta(titles);
if (this.db === null) { for (const result of results) {
return Promise.reject('database not initialized'); result.tagMeta = this.tagCache[result.dictionary] || {};
} }
const promises = []; return results;
for (const dictionary of dictionaries) { }
if (this.tagMetaCache[dictionary]) {
continue;
}
const tagMeta = {}; async cacheTagMeta(titles) {
promises.push( if (!this.db) {
this.db.tagMeta.where('dictionary').equals(dictionary).each(row => { throw 'database not initialized';
}
for (const title of titles) {
if (!this.tagCache[title]) {
const tagMeta = {};
await this.db.tagMeta.where('dictionary').equals(title).each(row => {
tagMeta[row.name] = {category: row.category, notes: row.notes, order: row.order}; tagMeta[row.name] = {category: row.category, notes: row.notes, order: row.order};
}).then(() => { });
this.tagMetaCache[dictionary] = tagMeta;
})
);
}
return Promise.all(promises); this.tagCache[title] = tagMeta;
}
}
} }
getDictionaries() { async getDictionaries() {
if (this.db === null) { if (this.db) {
return Promise.reject('database not initialized'); return this.db.dictionaries.toArray();
} else {
throw 'database not initialized';
} }
return this.db.dictionaries.toArray();
} }
importDictionary(archive, callback) { async importDictionary(archive, callback) {
if (this.db === null) { if (!this.db) {
return Promise.reject('database not initialized'); return Promise.reject('database not initialized');
} }
let summary = null; let summary = null;
const indexLoaded = (title, version, revision, tagMeta, hasTerms, hasKanji) => { const indexLoaded = async (title, version, revision, tagMeta, hasTerms, hasKanji) => {
summary = {title, version, revision, hasTerms, hasKanji}; summary = {title, version, revision, hasTerms, hasKanji};
return this.db.dictionaries.where('title').equals(title).count().then(count => {
if (count > 0) {
return Promise.reject(`dictionary "${title}" is already imported`);
}
return this.db.dictionaries.add({title, version, revision, hasTerms, hasKanji}).then(() => { const count = await this.db.dictionaries.where('title').equals(title).count();
const rows = []; if (count > 0) {
for (const tag in tagMeta || {}) { throw `dictionary "${title}" is already imported`;
const meta = tagMeta[tag]; }
const row = dictTagSanitize({
name: tag,
category: meta.category,
notes: meta.notes,
order: meta.order,
dictionary: title
});
rows.push(row); await this.db.dictionaries.add({title, version, revision, hasTerms, hasKanji});
}
return this.db.tagMeta.bulkAdd(rows); const rows = [];
for (const tag in tagMeta || {}) {
const meta = tagMeta[tag];
const row = dictTagSanitize({
name: tag,
category: meta.category,
notes: meta.notes,
order: meta.order,
dictionary: title
}); });
});
rows.push(row);
}
await this.db.tagMeta.bulkAdd(rows);
}; };
const termsLoaded = (title, entries, total, current) => { const termsLoaded = async (title, entries, total, current) => {
if (callback) {
callback(total, current);
}
const rows = []; const rows = [];
for (const [expression, reading, tags, rules, score, ...glossary] of entries) { for (const [expression, reading, tags, rules, score, ...glossary] of entries) {
rows.push({ rows.push({
@ -202,14 +200,14 @@ class Database {
}); });
} }
return this.db.terms.bulkAdd(rows).then(() => { await this.db.terms.bulkAdd(rows);
if (callback) {
callback(total, current);
}
});
}; };
const kanjiLoaded = (title, entries, total, current) => { const kanjiLoaded = async (title, entries, total, current) => {
if (callback) {
callback(total, current);
}
const rows = []; const rows = [];
for (const [character, onyomi, kunyomi, tags, ...meanings] of entries) { for (const [character, onyomi, kunyomi, tags, ...meanings] of entries) {
rows.push({ rows.push({
@ -222,13 +220,56 @@ class Database {
}); });
} }
return this.db.kanji.bulkAdd(rows).then(() => { await this.db.kanji.bulkAdd(rows);
if (callback) {
callback(total, current);
}
});
}; };
return zipLoadDb(archive, indexLoaded, termsLoaded, kanjiLoaded).then(() => summary); 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';
}
}
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2016 Alex Yatskov <alex@foosoft.net> * Copyright (C) 2016-2017 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net> * Author: Alex Yatskov <alex@foosoft.net>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@ -26,26 +26,7 @@ class Deinflection {
this.children = []; this.children = [];
} }
deinflect(definer, reasons) { async deinflect(definer, reasons) {
const define = () => {
return definer(this.term).then(definitions => {
if (this.rules.length === 0) {
this.definitions = definitions;
} else {
for (const rule of this.rules) {
for (const definition of definitions) {
if (definition.rules.includes(rule)) {
this.definitions.push(definition);
}
}
}
}
return this.definitions.length > 0;
});
};
const promises = [];
for (const reason in reasons) { for (const reason in reasons) {
for (const variant of reasons[reason]) { for (const variant of reasons[reason]) {
let accept = this.rules.length === 0; let accept = this.rules.length === 0;
@ -68,20 +49,31 @@ class Deinflection {
} }
const child = new Deinflection(term, {reason, rules: variant.rulesOut}); const child = new Deinflection(term, {reason, rules: variant.rulesOut});
promises.push( if (await child.deinflect(definer, reasons)) {
child.deinflect(definer, reasons).then(valid => valid && this.children.push(child)) this.children.push(child);
); }
} }
} }
return Promise.all(promises).then(define).then(valid => { const definitions = await definer(this.term);
if (valid && this.children.length > 0) { if (this.rules.length === 0) {
const child = new Deinflection(this.term, {rules: this.rules, definitions: this.definitions}); this.definitions = definitions;
this.children.push(child); } else {
for (const rule of this.rules) {
for (const definition of definitions) {
if (definition.rules.includes(rule)) {
this.definitions.push(definition);
}
}
} }
}
return valid || this.children.length > 0; if (this.definitions.length > 0 && this.children.length > 0) {
}); const child = new Deinflection(this.term, {rules: this.rules, definitions: this.definitions});
this.children.push(child);
}
return this.definitions.length > 0 || this.children.length > 0;
} }
gather() { gather() {
@ -112,16 +104,16 @@ class Deinflection {
class Deinflector { class Deinflector {
constructor() { constructor(reasons) {
this.reasons = {};
}
setReasons(reasons) {
this.reasons = reasons; this.reasons = reasons;
} }
deinflect(term, definer) { async deinflect(term, definer) {
const node = new Deinflection(term); const node = new Deinflection(term);
return node.deinflect(definer, this.reasons).then(success => success ? node.gather() : []); if (await node.deinflect(definer, this.reasons)) {
return node.gather();
} else {
return [];
}
} }
} }

273
ext/bg/js/dictionary.js Normal file
View File

@ -0,0 +1,273 @@
/*
* Copyright (C) 2016-2017 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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}}`,
handlebarsRender('fields.html', data)
);
}
return field;
}
function dictNoteFormat(definition, mode, options) {
const note = {fields: {}, tags: options.anki.tags};
let fields = [];
if (mode === 'kanji') {
fields = options.anki.kanji.fields;
note.deckName = options.anki.kanji.deck;
note.modelName = options.anki.kanji.model;
} else {
fields = options.anki.terms.fields;
note.deckName = options.anki.terms.deck;
note.modelName = options.anki.terms.model;
if (definition.audio) {
const audio = {
url: definition.audio.url,
filename: definition.audio.filename,
skipHash: '7e2c2f954ef6051373ba916f000168dc',
fields: []
};
for (const name in fields) {
if (fields[name].includes('{audio}')) {
audio.fields.push(name);
}
}
if (audio.fields.length > 0) {
note.audio = audio;
}
}
}
for (const name in fields) {
note.fields[name] = dictFieldFormat(fields[name], definition, mode, options);
}
return note;
}

View File

@ -1,63 +0,0 @@
/*
* Copyright (C) 2016 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net>
*
* 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 <http://www.gnu.org/licenses/>.
*/
window.displayWindow = new class extends Display {
constructor() {
super($('#spinner'), $('#content'));
const search = $('#search');
search.click(this.onSearch.bind(this));
const query = $('#query');
query.on('input', () => search.prop('disabled', query.val().length === 0));
window.wanakana.bind(query.get(0));
}
definitionAdd(definition, mode) {
return instYomi().definitionAdd(definition, mode);
}
definitionsAddable(definitions, modes) {
return instYomi().definitionsAddable(definitions, modes).catch(() => []);
}
templateRender(template, data) {
return instYomi().templateRender(template, data);
}
kanjiFind(character) {
return instYomi().kanjiFind(character);
}
handleError(error) {
window.alert(`Error: ${error}`);
}
clearSearch() {
$('#query').focus().select();
}
onSearch(e) {
e.preventDefault();
$('#intro').slideUp();
instYomi().termsFind($('#query').val()).then(({length, definitions}) => {
super.showTermDefs(definitions, instYomi().options);
}).catch(this.handleError.bind(this));
}
};

55
ext/bg/js/handlebars.js Normal file
View File

@ -0,0 +1,55 @@
/*
* Copyright (C) 2016-2017 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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 += `<a href="#" class="kanji-link">${c}</a>`;
} else {
result += c;
}
}
return result;
}
function handlebarsMultiLine(options) {
return options.fn(this).split('\n').join('<br>');
}
function handlebarsRender(template, data) {
if (Handlebars.partials !== Handlebars.templates) {
Handlebars.partials = Handlebars.templates;
Handlebars.registerHelper('dumpObject', handlebarsDumpObject);
Handlebars.registerHelper('kanjiLinks', handlebarsKanjiLinks);
Handlebars.registerHelper('multiLine', handlebarsMultiLine);
}
return Handlebars.templates[template](data);
}

View File

@ -17,388 +17,115 @@
*/ */
/* function optionsSetDefaults(options) {
* General 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
},
function formRead() { scanning: {
return optionsLoad().then(optionsOld => { middleMouse: true,
const optionsNew = $.extend(true, {}, optionsOld); selectText: true,
alphanumeric: true,
delay: 15,
length: 10,
modifier: 'shift'
},
optionsNew.general.showGuide = $('#show-usage-guide').prop('checked'); dictionaries: {},
optionsNew.general.audioSource = $('#audio-playback-source').val();
optionsNew.general.audioVolume = parseFloat($('#audio-playback-volume').val());
optionsNew.general.groupResults = $('#group-terms-results').prop('checked');
optionsNew.general.debugInfo = $('#show-debug-info').prop('checked');
optionsNew.general.showAdvanced = $('#show-advanced-options').prop('checked');
optionsNew.general.maxResults = parseInt($('#max-displayed-results').val(), 10);
optionsNew.general.popupWidth = parseInt($('#popup-width').val(), 10);
optionsNew.general.popupHeight = parseInt($('#popup-height').val(), 10);
optionsNew.general.popupOffset = parseInt($('#popup-offset').val(), 10);
optionsNew.scanning.middleMouse = $('#middle-mouse-button-scan').prop('checked'); anki: {
optionsNew.scanning.selectText = $('#select-matched-text').prop('checked'); enable: false,
optionsNew.scanning.alphanumeric = $('#search-alphanumeric').prop('checked'); server: 'http://127.0.0.1:8765',
optionsNew.scanning.delay = parseInt($('#scan-delay').val(), 10); tags: ['yomichan'],
optionsNew.scanning.length = parseInt($('#scan-length').val(), 10); htmlCards: true,
optionsNew.scanning.modifier = $('#scan-modifier-key').val(); sentenceExt: 200,
terms: {deck: '', model: '', fields: {}},
optionsNew.anki.enable = $('#anki-enable').prop('checked'); kanji: {deck: '', model: '', fields: {}}
optionsNew.anki.tags = $('#card-tags').val().split(/[,; ]+/);
optionsNew.anki.htmlCards = $('#generate-html-cards').prop('checked');
optionsNew.anki.sentenceExt = parseInt($('#sentence-detection-extent').val(), 10);
optionsNew.anki.server = $('#interface-server').val();
if (optionsOld.anki.enable && !$('#anki-error').is(':visible')) {
optionsNew.anki.terms.deck = $('#anki-terms-deck').val();
optionsNew.anki.terms.model = $('#anki-terms-model').val();
optionsNew.anki.terms.fields = ankiFieldsToDict($('#terms .anki-field-value'));
optionsNew.anki.kanji.deck = $('#anki-kanji-deck').val();
optionsNew.anki.kanji.model = $('#anki-kanji-model').val();
optionsNew.anki.kanji.fields = ankiFieldsToDict($('#kanji .anki-field-value'));
} }
};
$('.dict-group').each((index, element) => { const combine = (target, source) => {
const dictionary = $(element); for (const key in source) {
const title = dictionary.data('title'); if (!target.hasOwnProperty(key)) {
const priority = parseInt(dictionary.find('.dict-priority').val(), 10); target[key] = source[key];
const enabled = dictionary.find('.dict-enabled').prop('checked');
optionsNew.dictionaries[title] = {priority, enabled};
});
return {optionsNew, optionsOld};
});
}
function updateVisibility(options) {
const general = $('#anki-general');
if (options.anki.enable) {
general.show();
} else {
general.hide();
}
const advanced = $('.options-advanced');
if (options.general.showAdvanced) {
advanced.show();
} else {
advanced.hide();
}
const debug = $('#debug');
if (options.general.debugInfo) {
const text = JSON.stringify(options, null, 4);
debug.html(handlebarsEscape(text));
debug.show();
} else {
debug.hide();
}
}
function onOptionsChanged(e) {
if (!e.originalEvent && !e.isTrigger) {
return;
}
formRead().then(({optionsNew, optionsOld}) => {
return optionsSave(optionsNew).then(() => {
updateVisibility(optionsNew);
const ankiUpdated =
optionsNew.anki.enable !== optionsOld.anki.enable ||
optionsNew.anki.server !== optionsOld.anki.server;
if (ankiUpdated) {
ankiErrorShow(null);
ankiSpinnerShow(true);
return ankiDeckAndModelPopulate(optionsNew);
} }
}); }
}).catch(ankiErrorShow).then(() => ankiSpinnerShow(false)); };
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;
} }
$(document).ready(() => { function optionsVersion(options) {
handlebarsRegister(); 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';
}
}
];
optionsLoad().then(options => { optionsSetDefaults(options);
$('#show-usage-guide').prop('checked', options.general.showGuide); if (!options.hasOwnProperty('version')) {
$('#audio-playback-source').val(options.general.audioSource); options.version = fixups.length;
$('#audio-playback-volume').val(options.general.audioVolume);
$('#group-terms-results').prop('checked', options.general.groupResults);
$('#show-debug-info').prop('checked', options.general.debugInfo);
$('#show-advanced-options').prop('checked', options.general.showAdvanced);
$('#max-displayed-results').val(options.general.maxResults);
$('#popup-width').val(options.general.popupWidth);
$('#popup-height').val(options.general.popupHeight);
$('#popup-offset').val(options.general.popupOffset);
$('#middle-mouse-button-scan').prop('checked', options.scanning.middleMouse);
$('#select-matched-text').prop('checked', options.scanning.selectText);
$('#search-alphanumeric').prop('checked', options.scanning.alphanumeric);
$('#scan-delay').val(options.scanning.delay);
$('#scan-length').val(options.scanning.length);
$('#scan-modifier-key').val(options.scanning.modifier);
$('#dict-purge').click(onDictionaryPurge);
$('#dict-file').change(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(onOptionsChanged);
$('.anki-model').change(onAnkiModelChanged);
dictionaryGroupsPopulate(options);
ankiDeckAndModelPopulate(options);
updateVisibility(options);
});
});
/*
* Dictionary
*/
function dictionaryErrorShow(error) {
const dialog = $('#dict-error');
if (error) {
dialog.show().find('span').text(error);
} else {
dialog.hide();
} }
}
function dictionarySpinnerShow(show) { while (options.version < fixups.length) {
const spinner = $('#dict-spinner'); fixups[options.version++]();
if (show) {
spinner.show();
} else {
spinner.hide();
} }
return options;
} }
function dictionaryGroupsSort() { function optionsLoad() {
const dictGroups = $('#dict-groups'); return new Promise((resolve, reject) => {
const dictGroupChildren = dictGroups.children('.dict-group').sort((ca, cb) => { chrome.storage.local.get(null, store => resolve(store.options));
const pa = parseInt($(ca).find('.dict-priority').val(), 10); }).then(optionsStr => {
const pb = parseInt($(cb).find('.dict-priority').val(), 10); return optionsStr ? JSON.parse(optionsStr) : {};
if (pa < pb) { }).catch(error => {
return 1; return {};
} else if (pa > pb) {
return -1;
} else {
return 0;
}
});
dictGroups.append(dictGroupChildren);
}
function dictionaryGroupsPopulate(options) {
dictionaryErrorShow(null);
dictionarySpinnerShow(true);
const dictGroups = $('#dict-groups').empty();
const dictWarning = $('#dict-warning').hide();
return instDb().getDictionaries().then(rows => {
if (rows.length === 0) {
dictWarning.show();
}
for (const row of dictRowsSort(rows, options)) {
const dictOptions = options.dictionaries[row.title] || {enabled: false, priority: 0};
const dictHtml = handlebarsRender('dictionary.html', {
title: row.title,
version: row.version,
revision: row.revision,
priority: dictOptions.priority,
enabled: dictOptions.enabled
});
dictGroups.append($(dictHtml));
}
updateVisibility(options);
$('.dict-enabled, .dict-priority').change(e => {
dictionaryGroupsSort();
onOptionsChanged(e);
});
}).catch(dictionaryErrorShow).then(() => dictionarySpinnerShow(false));
}
function onDictionaryPurge(e) {
e.preventDefault();
dictionaryErrorShow(null);
dictionarySpinnerShow(true);
const dictControls = $('#dict-importer, #dict-groups').hide();
const dictProgress = $('#dict-purge-progress').show();
instDb().purge().catch(dictionaryErrorShow).then(() => {
dictionarySpinnerShow(false);
dictControls.show();
dictProgress.hide();
return optionsLoad();
}).then(options => { }).then(options => {
options.dictionaries = {}; return optionsVersion(options);
optionsSave(options).then(() => dictionaryGroupsPopulate(options));
}); });
} }
function onDictionaryImport(e) { function optionsSave(options) {
dictionaryErrorShow(null); return new Promise((resolve, reject) => {
dictionarySpinnerShow(true); chrome.storage.local.set({options: JSON.stringify(options)}, resolve);
}).then(() => {
const dictFile = $('#dict-file'); apiOptionsSet(options);
const dictImporter = $('#dict-importer').hide();
const dictProgress = $('#dict-import-progress').show();
const setProgress = percent => dictProgress.find('.progress-bar').css('width', `${percent}%`);
const updateProgress = (total, current) => setProgress(current / total * 100.0);
setProgress(0.0);
optionsLoad().then(options => {
return instDb().importDictionary(e.target.files[0], updateProgress).then(summary => {
options.dictionaries[summary.title] = {enabled: true, priority: 0};
return optionsSave(options);
}).then(() => dictionaryGroupsPopulate(options));
}).catch(dictionaryErrorShow).then(() => {
dictFile.val('');
dictionarySpinnerShow(false);
dictProgress.hide();
dictImporter.show();
});
}
/*
* Anki
*/
function ankiSpinnerShow(show) {
const spinner = $('#anki-spinner');
if (show) {
spinner.show();
} else {
spinner.hide();
}
}
function ankiErrorShow(error) {
const dialog = $('#anki-error');
if (error) {
dialog.show().find('span').text(error);
}
else {
dialog.hide();
}
}
function ankiFieldsToDict(selection) {
const result = {};
selection.each((index, element) => {
result[$(element).data('field')] = $(element).val();
});
return result;
}
function ankiDeckAndModelPopulate(options) {
ankiErrorShow(null);
ankiSpinnerShow(true);
const ankiFormat = $('#anki-format').hide();
return Promise.all([instAnki().getDeckNames(), instAnki().getModelNames()]).then(([deckNames, modelNames]) => {
const ankiDeck = $('.anki-deck');
ankiDeck.find('option').remove();
deckNames.sort().forEach(name => ankiDeck.append($('<option/>', {value: name, text: name})));
$('#anki-terms-deck').val(options.anki.terms.deck);
$('#anki-kanji-deck').val(options.anki.kanji.deck);
const ankiModel = $('.anki-model');
ankiModel.find('option').remove();
modelNames.sort().forEach(name => ankiModel.append($('<option/>', {value: name, text: name})));
return Promise.all([
ankiFieldsPopulate($('#anki-terms-model').val(options.anki.terms.model), options),
ankiFieldsPopulate($('#anki-kanji-model').val(options.anki.kanji.model), options)
]);
}).then(() => ankiFormat.show()).catch(ankiErrorShow).then(() => ankiSpinnerShow(false));
}
function ankiFieldsPopulate(element, options) {
const tab = element.closest('.tab-pane');
const tabId = tab.attr('id');
const container = tab.find('tbody').empty();
const modelName = element.val();
if (modelName === null) {
return Promise.resolve();
}
const markers = {
'terms': [
'audio',
'cloze-body',
'cloze-prefix',
'cloze-suffix',
'dictionary',
'expression',
'furigana',
'glossary',
'reading',
'sentence',
'tags',
'url'
],
'kanji': [
'character',
'dictionary',
'glossary',
'kunyomi',
'onyomi',
'sentence',
'tags',
'url'
]
}[tabId] || {};
return instAnki().getModelFieldNames(modelName).then(names => {
names.forEach(name => {
const value = options.anki[tabId].fields[name] || '';
const html = Handlebars.templates['model.html']({name, markers, value});
container.append($(html));
});
tab.find('.anki-field-value').change(onOptionsChanged);
tab.find('.marker-link').click(e => {
e.preventDefault();
const link = e.target;
$(link).closest('.input-group').find('.anki-field-value').val(`{${link.text}}`).trigger('change');
});
});
}
function onAnkiModelChanged(e) {
if (!e.originalEvent) {
return;
}
ankiErrorShow(null);
ankiSpinnerShow(true);
const element = $(this);
formRead().then(({optionsNew, optionsOld}) => {
const tab = element.closest('.tab-pane');
const tabId = tab.attr('id');
optionsNew.anki[tabId].fields = {};
ankiFieldsPopulate(element, optionsNew).then(() => {
optionsSave(optionsNew);
}).catch(ankiErrorShow).then(() => ankiSpinnerShow(false));
}); });
} }

40
ext/bg/js/request.js Normal file
View File

@ -0,0 +1,40 @@
/*
* Copyright (C) 2017 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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');
}
});
}

55
ext/bg/js/search.js Normal file
View File

@ -0,0 +1,55 @@
/*
* Copyright (C) 2016-2017 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net>
*
* 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 <http://www.gnu.org/licenses/>.
*/
class DisplaySearch extends Display {
constructor() {
super($('#spinner'), $('#content'));
this.search = $('#search').click(this.onSearch.bind(this));
this.query = $('#query').on('input', this.onSearchInput.bind(this));
this.intro = $('#intro');
window.wanakana.bind(this.query.get(0));
}
onError(error) {
window.alert(`Error: ${error}`);
}
onSearchClear() {
this.query.focus().select();
}
onSearchInput() {
this.search.prop('disabled', this.query.val().length === 0);
}
async onSearch(e) {
try {
e.preventDefault();
this.intro.slideUp();
const {length, definitions} = await apiTermsFind(this.query.val());
super.termsShow(definitions, await apiOptionsGet());
} catch (e) {
this.onError(e);
}
}
}
window.yomichan_search = new DisplaySearch();

432
ext/bg/js/settings.js Normal file
View File

@ -0,0 +1,432 @@
/*
* Copyright (C) 2016-2017 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net>
*
* 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 <http://www.gnu.org/licenses/>.
*/
async function formRead() {
const optionsOld = await optionsLoad();
const optionsNew = $.extend(true, {}, optionsOld);
optionsNew.general.showGuide = $('#show-usage-guide').prop('checked');
optionsNew.general.audioSource = $('#audio-playback-source').val();
optionsNew.general.audioVolume = parseFloat($('#audio-playback-volume').val());
optionsNew.general.groupResults = $('#group-terms-results').prop('checked');
optionsNew.general.debugInfo = $('#show-debug-info').prop('checked');
optionsNew.general.showAdvanced = $('#show-advanced-options').prop('checked');
optionsNew.general.maxResults = parseInt($('#max-displayed-results').val(), 10);
optionsNew.general.popupWidth = parseInt($('#popup-width').val(), 10);
optionsNew.general.popupHeight = parseInt($('#popup-height').val(), 10);
optionsNew.general.popupOffset = parseInt($('#popup-offset').val(), 10);
optionsNew.scanning.middleMouse = $('#middle-mouse-button-scan').prop('checked');
optionsNew.scanning.selectText = $('#select-matched-text').prop('checked');
optionsNew.scanning.alphanumeric = $('#search-alphanumeric').prop('checked');
optionsNew.scanning.delay = parseInt($('#scan-delay').val(), 10);
optionsNew.scanning.length = parseInt($('#scan-length').val(), 10);
optionsNew.scanning.modifier = $('#scan-modifier-key').val();
optionsNew.anki.enable = $('#anki-enable').prop('checked');
optionsNew.anki.tags = $('#card-tags').val().split(/[,; ]+/);
optionsNew.anki.htmlCards = $('#generate-html-cards').prop('checked');
optionsNew.anki.sentenceExt = parseInt($('#sentence-detection-extent').val(), 10);
optionsNew.anki.server = $('#interface-server').val();
if (optionsOld.anki.enable && !ankiErrorShown()) {
optionsNew.anki.terms.deck = $('#anki-terms-deck').val();
optionsNew.anki.terms.model = $('#anki-terms-model').val();
optionsNew.anki.terms.fields = ankiFieldsToDict($('#terms .anki-field-value'));
optionsNew.anki.kanji.deck = $('#anki-kanji-deck').val();
optionsNew.anki.kanji.model = $('#anki-kanji-model').val();
optionsNew.anki.kanji.fields = ankiFieldsToDict($('#kanji .anki-field-value'));
}
$('.dict-group').each((index, element) => {
const dictionary = $(element);
const title = dictionary.data('title');
const priority = parseInt(dictionary.find('.dict-priority').val(), 10);
const enabled = dictionary.find('.dict-enabled').prop('checked');
optionsNew.dictionaries[title] = {priority, enabled};
});
return {optionsNew, optionsOld};
}
function formUpdateVisibility(options) {
const general = $('#anki-general');
if (options.anki.enable) {
general.show();
} else {
general.hide();
}
const advanced = $('.options-advanced');
if (options.general.showAdvanced) {
advanced.show();
} else {
advanced.hide();
}
const debug = $('#debug');
if (options.general.debugInfo) {
const text = JSON.stringify(options, null, 4);
debug.html(handlebarsEscape(text));
debug.show();
} else {
debug.hide();
}
}
async function onFormOptionsChanged(e) {
try {
if (!e.originalEvent && !e.isTrigger) {
return;
}
const {optionsNew, optionsOld} = await formRead();
await optionsSave(optionsNew);
formUpdateVisibility(optionsNew);
const ankiUpdated =
optionsNew.anki.enable !== optionsOld.anki.enable ||
optionsNew.anki.server !== optionsOld.anki.server;
if (ankiUpdated) {
ankiSpinnerShow(true);
await ankiDeckAndModelPopulate(optionsNew);
ankiErrorShow();
}
} catch (e) {
ankiErrorShow(e);
} finally {
ankiSpinnerShow(false);
}
}
async function onReady() {
const options = await optionsLoad();
$('#show-usage-guide').prop('checked', options.general.showGuide);
$('#audio-playback-source').val(options.general.audioSource);
$('#audio-playback-volume').val(options.general.audioVolume);
$('#group-terms-results').prop('checked', options.general.groupResults);
$('#show-debug-info').prop('checked', options.general.debugInfo);
$('#show-advanced-options').prop('checked', options.general.showAdvanced);
$('#max-displayed-results').val(options.general.maxResults);
$('#popup-width').val(options.general.popupWidth);
$('#popup-height').val(options.general.popupHeight);
$('#popup-offset').val(options.general.popupOffset);
$('#middle-mouse-button-scan').prop('checked', options.scanning.middleMouse);
$('#select-matched-text').prop('checked', options.scanning.selectText);
$('#search-alphanumeric').prop('checked', options.scanning.alphanumeric);
$('#scan-delay').val(options.scanning.delay);
$('#scan-length').val(options.scanning.length);
$('#scan-modifier-key').val(options.scanning.modifier);
$('#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(utilAsync(onFormOptionsChanged));
$('.anki-model').change(utilAsync(onAnkiModelChanged));
try {
await dictionaryGroupsPopulate(options);
} catch (e) {
dictionaryErrorShow(e);
}
try {
await ankiDeckAndModelPopulate(options);
} catch (e) {
ankiErrorShow(e);
}
formUpdateVisibility(options);
}
$(document).ready(utilAsync(onReady));
/*
* Dictionary
*/
function dictionaryErrorShow(error) {
const dialog = $('#dict-error');
if (error) {
dialog.show().find('span').text(error);
} else {
dialog.hide();
}
}
function dictionarySpinnerShow(show) {
const spinner = $('#dict-spinner');
if (show) {
spinner.show();
} else {
spinner.hide();
}
}
function dictionaryGroupsSort() {
const dictGroups = $('#dict-groups');
const dictGroupChildren = dictGroups.children('.dict-group').sort((ca, cb) => {
const pa = parseInt($(ca).find('.dict-priority').val(), 10);
const pb = parseInt($(cb).find('.dict-priority').val(), 10);
if (pa < pb) {
return 1;
} else if (pa > pb) {
return -1;
} else {
return 0;
}
});
dictGroups.append(dictGroupChildren);
}
async function dictionaryGroupsPopulate(options) {
const dictGroups = $('#dict-groups').empty();
const dictWarning = $('#dict-warning').hide();
const dictRows = await utilDatabaseGetDictionaries();
if (dictRows.length === 0) {
dictWarning.show();
}
for (const dictRow of dictRowsSort(dictRows, options)) {
const dictOptions = options.dictionaries[dictRow.title] || {enabled: false, priority: 0};
const dictHtml = handlebarsRender('dictionary.html', {
title: dictRow.title,
version: dictRow.version,
revision: dictRow.revision,
priority: dictOptions.priority,
enabled: dictOptions.enabled
});
dictGroups.append($(dictHtml));
}
formUpdateVisibility(options);
$('.dict-enabled, .dict-priority').change(e => {
dictionaryGroupsSort();
onFormOptionsChanged(e);
});
}
async function onDictionaryPurge(e) {
e.preventDefault();
const dictControls = $('#dict-importer, #dict-groups').hide();
const dictProgress = $('#dict-purge-progress').show();
try {
dictionaryErrorShow();
dictionarySpinnerShow(true);
await utilDatabasePurge();
const options = await optionsLoad();
options.dictionaries = {};
await optionsSave(options);
await dictionaryGroupsPopulate(options);
} catch (e) {
dictionaryErrorShow(e);
} finally {
dictionarySpinnerShow(false);
dictControls.show();
dictProgress.hide();
}
}
async function onDictionaryImport(e) {
const dictFile = $('#dict-file');
const dictControls = $('#dict-importer').hide();
const dictProgress = $('#dict-import-progress').show();
try {
dictionaryErrorShow();
dictionarySpinnerShow(true);
const setProgress = percent => dictProgress.find('.progress-bar').css('width', `${percent}%`);
const updateProgress = (total, current) => setProgress(current / total * 100.0);
setProgress(0.0);
const options = await optionsLoad();
const summary = await utilDatabaseImport(e.target.files[0], updateProgress);
options.dictionaries[summary.title] = {enabled: true, priority: 0};
await optionsSave(options);
await dictionaryGroupsPopulate(options);
} catch (e) {
dictionaryErrorShow(e);
} finally {
dictionarySpinnerShow(false);
dictFile.val('');
dictControls.show();
dictProgress.hide();
}
}
/*
* Anki
*/
function ankiSpinnerShow(show) {
const spinner = $('#anki-spinner');
if (show) {
spinner.show();
} else {
spinner.hide();
}
}
function ankiErrorShow(error) {
const dialog = $('#anki-error');
if (error) {
dialog.show().find('span').text(error);
}
else {
dialog.hide();
}
}
function ankiErrorShown() {
return $('#anki-error').is(':visible');
}
function ankiFieldsToDict(selection) {
const result = {};
selection.each((index, element) => {
result[$(element).data('field')] = $(element).val();
});
return result;
}
async function ankiDeckAndModelPopulate(options) {
const ankiFormat = $('#anki-format').hide();
const ankiTermsModel = $('#anki-terms-model').val(options.anki.terms.model);
const ankiKanjiModel = $('#anki-kanji-model').val(options.anki.kanji.model);
$('#anki-terms-deck').val(options.anki.terms.deck);
$('#anki-kanji-deck').val(options.anki.kanji.deck);
const deckNames = await utilAnkiGetDeckNames();
const ankiDeck = $('.anki-deck');
ankiDeck.find('option').remove();
deckNames.sort().forEach(name => ankiDeck.append($('<option/>', {value: name, text: name})));
const modelNames = await utilAnkiGetModelNames();
const ankiModel = $('.anki-model');
ankiModel.find('option').remove();
modelNames.sort().forEach(name => ankiModel.append($('<option/>', {value: name, text: name})));
await ankiFieldsPopulate(ankiTermsModel, options);
await ankiFieldsPopulate(ankiKanjiModel, options);
ankiFormat.show();
}
async function ankiFieldsPopulate(element, options) {
const modelName = element.val();
if (!modelName) {
return;
}
const tab = element.closest('.tab-pane');
const tabId = tab.attr('id');
const container = tab.find('tbody').empty();
const markers = {
'terms': [
'audio',
'cloze-body',
'cloze-prefix',
'cloze-suffix',
'dictionary',
'expression',
'furigana',
'glossary',
'glossary-brief',
'reading',
'sentence',
'tags',
'url'
],
'kanji': [
'character',
'dictionary',
'glossary',
'kunyomi',
'onyomi',
'sentence',
'tags',
'url'
]
}[tabId] || {};
for (const name of await utilAnkiGetModelFieldNames(modelName)) {
const value = options.anki[tabId].fields[name] || '';
const html = Handlebars.templates['model.html']({name, markers, value});
container.append($(html));
}
tab.find('.anki-field-value').change(utilAsync(onFormOptionsChanged));
tab.find('.marker-link').click(onAnkiMarkerClicked);
}
function onAnkiMarkerClicked(e) {
e.preventDefault();
const link = e.target;
$(link).closest('.input-group').find('.anki-field-value').val(`{${link.text}}`).trigger('change');
}
async function onAnkiModelChanged(e) {
try {
if (!e.originalEvent) {
return;
}
const element = $(this);
const tab = element.closest('.tab-pane');
const tabId = tab.attr('id');
const {optionsNew, optionsOld} = await formRead();
optionsNew.anki[tabId].fields = {};
await optionsSave(optionsNew);
ankiSpinnerShow(true);
await ankiFieldsPopulate(element, optionsNew);
ankiErrorShow();
} catch (e) {
ankiErrorShow(e);
} finally {
ankiSpinnerShow(false);
}
}

View File

@ -3,7 +3,7 @@
templates['dictionary.html'] = template({"1":function(container,depth0,helpers,partials,data) { templates['dictionary.html'] = template({"1":function(container,depth0,helpers,partials,data) {
return "checked"; return "checked";
},"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) { },"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
var stack1, helper, alias1=depth0 != null ? depth0 : {}, alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; var stack1, helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression;
return "<div class=\"dict-group well well-sm\" data-title=\"" return "<div class=\"dict-group well well-sm\" data-title=\""
+ alias4(((helper = (helper = helpers.title || (depth0 != null ? depth0.title : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"title","hash":{},"data":data}) : helper))) + alias4(((helper = (helper = helpers.title || (depth0 != null ? depth0.title : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"title","hash":{},"data":data}) : helper)))
@ -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) { templates['fields.html'] = template({"1":function(container,depth0,helpers,partials,data) {
var stack1; 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 : (container.nullContext || {}),(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) { },"2":function(container,depth0,helpers,partials,data) {
var stack1, alias1=depth0 != null ? depth0 : {}; var stack1, alias1=depth0 != null ? depth0 : (container.nullContext || {});
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 : "") 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(7, data, 0),"inverse":container.program(11, data, 0),"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) { },"3":function(container,depth0,helpers,partials,data) {
var stack1; var stack1;
return "<i>(" return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.tags : depth0),{"name":"if","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(4, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ ")</i> ";
},"4":function(container,depth0,helpers,partials,data) { },"4":function(container,depth0,helpers,partials,data) {
var stack1, helper, alias1=depth0 != null ? depth0 : {}; var stack1;
return "<i>("
+ ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.tags : depth0),{"name":"each","hash":{},"fn":container.program(5, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ ")</i> ";
},"5":function(container,depth0,helpers,partials,data) {
var stack1, helper, alias1=depth0 != null ? depth0 : (container.nullContext || {});
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))) 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 : ""); + ((stack1 = helpers.unless.call(alias1,(data && data.last),{"name":"unless","hash":{},"fn":container.program(6, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "");
},"5":function(container,depth0,helpers,partials,data) { },"6":function(container,depth0,helpers,partials,data) {
return ", "; return ", ";
},"7":function(container,depth0,helpers,partials,data) { },"8":function(container,depth0,helpers,partials,data) {
var stack1; var stack1;
return "<ul>" return "<ul>"
+ ((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 : (container.nullContext || {}),(depth0 != null ? depth0.glossary : depth0),{"name":"each","hash":{},"fn":container.program(9, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ "</ul>"; + "</ul>";
},"8":function(container,depth0,helpers,partials,data) { },"9":function(container,depth0,helpers,partials,data) {
var stack1, helper, options, buffer = var stack1, helper, options, buffer =
"<li>"; "<li>";
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 : (container.nullContext || {}),options) : helper));
if (!helpers.multiLine) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)} if (!helpers.multiLine) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)}
if (stack1 != null) { buffer += stack1; } if (stack1 != null) { buffer += stack1; }
return buffer + "</li>"; return buffer + "</li>";
},"9":function(container,depth0,helpers,partials,data) { },"10":function(container,depth0,helpers,partials,data) {
return container.escapeExpression(container.lambda(depth0, depth0)); 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 = ""; 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 : (container.nullContext || {}),options) : helper));
if (!helpers.multiLine) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)} if (!helpers.multiLine) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)}
if (stack1 != null) { buffer += stack1; } if (stack1 != null) { buffer += stack1; }
return buffer; return buffer;
},"12":function(container,depth0,helpers,partials,data) { },"13":function(container,depth0,helpers,partials,data) {
var stack1; var stack1;
return container.escapeExpression(container.lambda(((stack1 = (depth0 != null ? depth0.glossary : depth0)) != null ? stack1["0"] : stack1), depth0)); return container.escapeExpression(container.lambda(((stack1 = (depth0 != null ? depth0.glossary : depth0)) != null ? stack1["0"] : stack1), depth0));
},"14":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) { },"15":function(container,depth0,helpers,partials,data) {
var stack1, alias1=depth0 != null ? depth0 : (container.nullContext || {});
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; var stack1;
return "(" return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.tags : depth0),{"name":"if","hash":{},"fn":container.program(17, 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(4, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ ") ";
},"17":function(container,depth0,helpers,partials,data) { },"17":function(container,depth0,helpers,partials,data) {
var stack1; 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 : ""); return "("
},"18":function(container,depth0,helpers,partials,data) { + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.tags : depth0),{"name":"each","hash":{},"fn":container.program(5, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ ") ";
},"19":function(container,depth0,helpers,partials,data) {
var stack1;
return ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(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; var stack1;
return container.escapeExpression(container.lambda(depth0, depth0)) 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 : ""); + ((stack1 = helpers.unless.call(depth0 != null ? depth0 : (container.nullContext || {}),(data && data.last),{"name":"unless","hash":{},"fn":container.program(6, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "");
},"20":function(container,depth0,helpers,partials,data) {
return "";
},"22":function(container,depth0,helpers,partials,data) { },"22":function(container,depth0,helpers,partials,data) {
var stack1; return "";
return container.escapeExpression(container.lambda(((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.character : stack1), depth0));
},"24":function(container,depth0,helpers,partials,data) { },"24":function(container,depth0,helpers,partials,data) {
var stack1; var stack1;
return container.escapeExpression(container.lambda(((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.dictionary : stack1), depth0)); return container.escapeExpression(container.lambda(((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.character : stack1), depth0));
},"26":function(container,depth0,helpers,partials,data) { },"26":function(container,depth0,helpers,partials,data) {
var stack1; 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 : ""); return container.escapeExpression(container.lambda(((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.dictionary : stack1), depth0));
},"27":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) { },"28":function(container,depth0,helpers,partials,data) {
var stack1; var stack1;
return container.escapeExpression(container.lambda(((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.reading : stack1), depth0)); return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),(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 : (container.nullContext || {}),((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) { },"30":function(container,depth0,helpers,partials,data) {
var stack1; var stack1;
return container.escapeExpression(container.lambda(((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.expression : stack1), depth0)); return container.escapeExpression(container.lambda(((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.reading : stack1), depth0));
},"32":function(container,depth0,helpers,partials,data) { },"32":function(container,depth0,helpers,partials,data) {
var stack1; 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 : ""); return container.escapeExpression(container.lambda(((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.expression : stack1), depth0));
},"33":function(container,depth0,helpers,partials,data) { },"34":function(container,depth0,helpers,partials,data) {
var stack1; 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 : ""); return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.html : depth0),{"name":"if","hash":{},"fn":container.program(35, data, 0),"inverse":container.program(38, data, 0),"data":data})) != null ? stack1 : "");
},"34":function(container,depth0,helpers,partials,data) { },"35":function(container,depth0,helpers,partials,data) {
var stack1;
return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),((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; var stack1, alias1=container.lambda, alias2=container.escapeExpression;
return "<ruby>" return "<ruby>"
@ -131,147 +139,151 @@ templates['fields.html'] = template({"1":function(container,depth0,helpers,parti
+ "<rt>" + "<rt>"
+ alias2(alias1(((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.reading : stack1), depth0)) + alias2(alias1(((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.reading : stack1), depth0))
+ "</rt></ruby>"; + "</rt></ruby>";
},"36":function(container,depth0,helpers,partials,data) { },"38":function(container,depth0,helpers,partials,data) {
var stack1; 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 : ""); return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),((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 : "");
},"37":function(container,depth0,helpers,partials,data) { },"39":function(container,depth0,helpers,partials,data) {
var stack1, alias1=container.lambda, alias2=container.escapeExpression; var stack1, alias1=container.lambda, alias2=container.escapeExpression;
return alias2(alias1(((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.expression : stack1), depth0)) 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)) + 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 : {}; var stack1, alias1=depth0 != null ? depth0 : (container.nullContext || {});
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 : "") 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(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.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(64, data, 0, blockParams, depths),"inverse":container.noop,"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 : "");
},"40":function(container,depth0,helpers,partials,data) {
return "<div style=\"text-align: left;\">";
},"42":function(container,depth0,helpers,partials,data) { },"42":function(container,depth0,helpers,partials,data) {
var stack1; return "<div style=\"text-align: left;\">";
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) {
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) { },"44":function(container,depth0,helpers,partials,data) {
var stack1; var stack1;
return "<ol>" return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),((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 : "");
+ ((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 : "")
+ "</ol>";
},"45":function(container,depth0,helpers,partials,data) { },"45":function(container,depth0,helpers,partials,data) {
var stack1;
return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),(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 "<ol>"
+ ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),((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 : "")
+ "</ol>";
},"47":function(container,depth0,helpers,partials,data) {
return "<li>" return "<li>"
+ container.escapeExpression(container.lambda(depth0, depth0)) + container.escapeExpression(container.lambda(depth0, depth0))
+ "</li>"; + "</li>";
},"47":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) { },"49":function(container,depth0,helpers,partials,data) {
var stack1; var stack1;
return ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),((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)); 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) {
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) {
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) { },"53":function(container,depth0,helpers,partials,data,blockParams,depths) {
var stack1; 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 : ""); return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),(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) { },"54":function(container,depth0,helpers,partials,data,blockParams,depths) {
var stack1; var stack1;
return "<ol>" return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),((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 : "");
+ ((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 : "")
+ "</ol>";
},"55":function(container,depth0,helpers,partials,data,blockParams,depths) { },"55":function(container,depth0,helpers,partials,data,blockParams,depths) {
var stack1; var stack1;
return "<li>" return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),(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 : "");
+ ((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 : "") },"56":function(container,depth0,helpers,partials,data,blockParams,depths) {
+ "</li>"; var stack1;
return "<ol>"
+ ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),((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 : "")
+ "</ol>";
},"57":function(container,depth0,helpers,partials,data,blockParams,depths) { },"57":function(container,depth0,helpers,partials,data,blockParams,depths) {
var stack1; 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 : ""); return "<li>"
},"58":function(container,depth0,helpers,partials,data,blockParams,depths) { + ((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 : "")
+ "</li>";
},"59":function(container,depth0,helpers,partials,data,blockParams,depths) {
var stack1;
return ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),((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; var stack1;
return " * " 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 : "");
},"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 : "");
},"62":function(container,depth0,helpers,partials,data) { },"62":function(container,depth0,helpers,partials,data) {
var stack1; 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) { },"64":function(container,depth0,helpers,partials,data) {
return "</div>";
},"66":function(container,depth0,helpers,partials,data) {
var stack1; 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 "</div>";
},"68":function(container,depth0,helpers,partials,data) { },"68":function(container,depth0,helpers,partials,data) {
var stack1; 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) { },"70":function(container,depth0,helpers,partials,data) {
var stack1; 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 : (container.nullContext || {}),((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) { },"72":function(container,depth0,helpers,partials,data) {
var stack1; 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 : ""); return ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),((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 : "");
},"73":function(container,depth0,helpers,partials,data) { },"74":function(container,depth0,helpers,partials,data) {
var stack1; var stack1;
return container.escapeExpression(container.lambda(((stack1 = ((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.cloze : stack1)) != null ? stack1.sentence : stack1), depth0)); return ((stack1 = helpers.unless.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.modeTermKana : depth0),{"name":"unless","hash":{},"fn":container.program(30, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "");
},"75":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) { },"76":function(container,depth0,helpers,partials,data) {
var stack1; var stack1;
return container.escapeExpression(container.lambda(((stack1 = ((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.cloze : stack1)) != null ? stack1.prefix : stack1), depth0)); return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),((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 : "");
},"78":function(container,depth0,helpers,partials,data) { },"77":function(container,depth0,helpers,partials,data) {
var stack1; 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 : ""); return container.escapeExpression(container.lambda(((stack1 = ((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.cloze : stack1)) != null ? stack1.sentence : stack1), depth0));
},"79":function(container,depth0,helpers,partials,data) { },"79":function(container,depth0,helpers,partials,data) {
var stack1; var stack1;
return container.escapeExpression(container.lambda(((stack1 = ((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.cloze : stack1)) != null ? stack1.body : stack1), depth0)); return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),((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 : "");
},"81":function(container,depth0,helpers,partials,data) { },"80":function(container,depth0,helpers,partials,data) {
var stack1; 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 : ""); return container.escapeExpression(container.lambda(((stack1 = ((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.cloze : stack1)) != null ? stack1.prefix : stack1), depth0));
},"82":function(container,depth0,helpers,partials,data) { },"82":function(container,depth0,helpers,partials,data) {
var stack1; var stack1;
return container.escapeExpression(container.lambda(((stack1 = ((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.cloze : stack1)) != null ? stack1.suffix : stack1), depth0)); return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),((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 : "");
},"84":function(container,depth0,helpers,partials,data) { },"83":function(container,depth0,helpers,partials,data) {
var stack1; 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 : ""); return container.escapeExpression(container.lambda(((stack1 = ((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.cloze : stack1)) != null ? stack1.body : stack1), depth0));
},"85":function(container,depth0,helpers,partials,data) {
var stack1;
return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),((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) { },"86":function(container,depth0,helpers,partials,data) {
var stack1; 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 : ""); return container.escapeExpression(container.lambda(((stack1 = ((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.cloze : stack1)) != null ? stack1.suffix : stack1), depth0));
},"87":function(container,depth0,helpers,partials,data) { },"88":function(container,depth0,helpers,partials,data) {
var stack1;
return ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),((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 : (container.nullContext || {}),(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; var stack1, alias1=container.lambda, alias2=container.escapeExpression;
return "<a href=\"" return "<a href=\""
@ -279,46 +291,47 @@ templates['fields.html'] = template({"1":function(container,depth0,helpers,parti
+ "\">" + "\">"
+ alias2(alias1(((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.url : stack1), depth0)) + alias2(alias1(((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.url : stack1), depth0))
+ "</a>"; + "</a>";
},"89":function(container,depth0,helpers,partials,data) { },"93":function(container,depth0,helpers,partials,data) {
var stack1; var stack1;
return container.escapeExpression(container.lambda(((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.url : stack1), depth0)); 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) { },"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data,blockParams,depths) {
var stack1; 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 : ""); + ((stack1 = container.invokePartial(helpers.lookup.call(depth0 != null ? depth0 : (container.nullContext || {}),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) { },"main_d": function(fn, props, container, depth0, data, blockParams, depths) {
var decorators = container.decorators; 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(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":["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":["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":["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(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(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(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(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(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(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":["glossary-brief"],"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":["kunyomi"],"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":["onyomi"],"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(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(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(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(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(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(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(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(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(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(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(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; return fn;
} }
,"useDecorators":true,"usePartial":true,"useData":true,"useDepths":true}); ,"useDecorators":true,"usePartial":true,"useData":true,"useDepths":true});
templates['kanji.html'] = template({"1":function(container,depth0,helpers,partials,data) { templates['kanji.html'] = template({"1":function(container,depth0,helpers,partials,data) {
var stack1, helper, alias1=depth0 != null ? depth0 : {}; var stack1, helper, alias1=depth0 != null ? depth0 : (container.nullContext || {});
return "<div class=\"entry\" data-type=\"kanji\">\n <div class=\"actions\">\n <img src=\"/mixed/img/entry-current.png\" class=\"current\" title=\"Current entry (Alt + Up/Down/Home/End/PgUp/PgDn)\" alt>\n" return "<div class=\"entry\" data-type=\"kanji\">\n <div class=\"actions\">\n"
+ ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.addable : depth0),{"name":"if","hash":{},"fn":container.program(2, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.addable : depth0),{"name":"if","hash":{},"fn":container.program(2, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.source : depth0),{"name":"if","hash":{},"fn":container.program(4, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.source : depth0),{"name":"if","hash":{},"fn":container.program(4, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ " </div>\n\n <div class=\"glyph\">" + " <img src=\"/mixed/img/entry-current.png\" class=\"current\" title=\"Current entry (Alt + Up/Down/Home/End/PgUp/PgDn)\" alt>\n </div>\n\n <div class=\"glyph\">"
+ container.escapeExpression(((helper = (helper = helpers.character || (depth0 != null ? depth0.character : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(alias1,{"name":"character","hash":{},"data":data}) : helper))) + container.escapeExpression(((helper = (helper = helpers.character || (depth0 != null ? depth0.character : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(alias1,{"name":"character","hash":{},"data":data}) : helper)))
+ "</div>\n\n <div class=\"reading\">\n <table>\n <tr>\n <th>Kunyomi:</th>\n <td>\n" + "</div>\n\n <div class=\"reading\">\n <table>\n <tr>\n <th>Kunyomi:</th>\n <td>\n"
+ ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.kunyomi : depth0),{"name":"each","hash":{},"fn":container.program(6, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.kunyomi : depth0),{"name":"each","hash":{},"fn":container.program(6, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
@ -332,7 +345,7 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia
+ ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.debug : depth0),{"name":"if","hash":{},"fn":container.program(18, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.debug : depth0),{"name":"if","hash":{},"fn":container.program(18, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ "</div>\n"; + "</div>\n";
},"2":function(container,depth0,helpers,partials,data) { },"2":function(container,depth0,helpers,partials,data) {
return " <a href=\"#\" class=\"action-add-note pending disabled\" data-mode=\"kanji\"><img src=\"/mixed/img/add-kanji.png\" title=\"Add Kanji (Alt + K)\" alt></a>\n"; return " <a href=\"#\" class=\"action-view-note pending disabled\"><img src=\"/mixed/img/view-note.png\" title=\"View added note (Alt + V)\" alt></a>\n <a href=\"#\" class=\"action-add-note pending disabled\" data-mode=\"kanji\"><img src=\"/mixed/img/add-kanji.png\" title=\"Add Kanji (Alt + K)\" alt></a>\n";
},"4":function(container,depth0,helpers,partials,data) { },"4":function(container,depth0,helpers,partials,data) {
return " <a href=\"#\" class=\"source-term\"><img src=\"/mixed/img/source-term.png\" title=\"Source term (Alt + B)\" alt></a>\n"; return " <a href=\"#\" class=\"source-term\"><img src=\"/mixed/img/source-term.png\" title=\"Source term (Alt + B)\" alt></a>\n";
},"6":function(container,depth0,helpers,partials,data) { },"6":function(container,depth0,helpers,partials,data) {
@ -340,12 +353,12 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia
return " " return " "
+ container.escapeExpression(container.lambda(depth0, depth0)) + container.escapeExpression(container.lambda(depth0, depth0))
+ ((stack1 = helpers.unless.call(depth0 != null ? depth0 : {},(data && data.last),{"name":"unless","hash":{},"fn":container.program(7, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + ((stack1 = helpers.unless.call(depth0 != null ? depth0 : (container.nullContext || {}),(data && data.last),{"name":"unless","hash":{},"fn":container.program(7, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ "\n"; + "\n";
},"7":function(container,depth0,helpers,partials,data) { },"7":function(container,depth0,helpers,partials,data) {
return ", "; return ", ";
},"9":function(container,depth0,helpers,partials,data) { },"9":function(container,depth0,helpers,partials,data) {
var helper, alias1=depth0 != null ? depth0 : {}, alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; var helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression;
return " <span class=\"label label-default tag-" return " <span class=\"label label-default tag-"
+ alias4(((helper = (helper = helpers.category || (depth0 != null ? depth0.category : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"category","hash":{},"data":data}) : helper))) + alias4(((helper = (helper = helpers.category || (depth0 != null ? depth0.category : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"category","hash":{},"data":data}) : helper)))
@ -358,12 +371,12 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia
var stack1; var stack1;
return " <ol>\n" return " <ol>\n"
+ ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.glossary : depth0),{"name":"each","hash":{},"fn":container.program(12, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.glossary : depth0),{"name":"each","hash":{},"fn":container.program(12, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ " </ol>\n"; + " </ol>\n";
},"12":function(container,depth0,helpers,partials,data) { },"12":function(container,depth0,helpers,partials,data) {
var stack1, helper, options, buffer = var stack1, helper, options, buffer =
" <li><span class=\"glossary-item\">"; " <li><span class=\"glossary-item\">";
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)); 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 : (container.nullContext || {}),options) : helper));
if (!helpers.multiLine) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)} if (!helpers.multiLine) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)}
if (stack1 != null) { buffer += stack1; } if (stack1 != null) { buffer += stack1; }
return buffer + "</span></li>\n"; return buffer + "</span></li>\n";
@ -372,7 +385,7 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia
},"15":function(container,depth0,helpers,partials,data) { },"15":function(container,depth0,helpers,partials,data) {
var stack1, helper, options, buffer = var stack1, helper, options, buffer =
" <div class=\"glossary-item\">"; " <div class=\"glossary-item\">";
stack1 = ((helper = (helper = helpers.multiLine || (depth0 != null ? depth0.multiLine : depth0)) != null ? helper : helpers.helperMissing),(options={"name":"multiLine","hash":{},"fn":container.program(16, 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(16, data, 0),"inverse":container.noop,"data":data}),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),options) : helper));
if (!helpers.multiLine) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)} if (!helpers.multiLine) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)}
if (stack1 != null) { buffer += stack1; } if (stack1 != null) { buffer += stack1; }
return buffer + "</div>\n"; return buffer + "</div>\n";
@ -383,7 +396,7 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia
},"18":function(container,depth0,helpers,partials,data) { },"18":function(container,depth0,helpers,partials,data) {
var stack1, helper, options, buffer = var stack1, helper, options, buffer =
" <pre>"; " <pre>";
stack1 = ((helper = (helper = helpers.dumpObject || (depth0 != null ? depth0.dumpObject : depth0)) != null ? helper : helpers.helperMissing),(options={"name":"dumpObject","hash":{},"fn":container.program(19, data, 0),"inverse":container.noop,"data":data}),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : {},options) : helper)); stack1 = ((helper = (helper = helpers.dumpObject || (depth0 != null ? depth0.dumpObject : depth0)) != null ? helper : helpers.helperMissing),(options={"name":"dumpObject","hash":{},"fn":container.program(19, data, 0),"inverse":container.noop,"data":data}),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),options) : helper));
if (!helpers.dumpObject) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)} if (!helpers.dumpObject) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)}
if (stack1 != null) { buffer += stack1; } if (stack1 != null) { buffer += stack1; }
return buffer + "</pre>\n"; return buffer + "</pre>\n";
@ -394,11 +407,11 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia
},"21":function(container,depth0,helpers,partials,data,blockParams,depths) { },"21":function(container,depth0,helpers,partials,data,blockParams,depths) {
var stack1; var stack1;
return ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.definitions : depth0),{"name":"each","hash":{},"fn":container.program(22, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : ""); return ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"each","hash":{},"fn":container.program(22, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "");
},"22":function(container,depth0,helpers,partials,data,blockParams,depths) { },"22":function(container,depth0,helpers,partials,data,blockParams,depths) {
var stack1; var stack1;
return ((stack1 = helpers.unless.call(depth0 != null ? depth0 : {},(data && data.first),{"name":"unless","hash":{},"fn":container.program(23, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") return ((stack1 = helpers.unless.call(depth0 != null ? depth0 : (container.nullContext || {}),(data && data.first),{"name":"unless","hash":{},"fn":container.program(23, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ "\n" + "\n"
+ ((stack1 = container.invokePartial(partials.kanji,depth0,{"name":"kanji","hash":{"root":(depths[1] != null ? depths[1].root : depths[1]),"source":(depths[1] != null ? depths[1].source : depths[1]),"addable":(depths[1] != null ? depths[1].addable : depths[1]),"debug":(depths[1] != null ? depths[1].debug : depths[1])},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : ""); + ((stack1 = container.invokePartial(partials.kanji,depth0,{"name":"kanji","hash":{"root":(depths[1] != null ? depths[1].root : depths[1]),"source":(depths[1] != null ? depths[1].source : depths[1]),"addable":(depths[1] != null ? depths[1].addable : depths[1]),"debug":(depths[1] != null ? depths[1].debug : depths[1])},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "");
},"23":function(container,depth0,helpers,partials,data) { },"23":function(container,depth0,helpers,partials,data) {
@ -409,7 +422,7 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia
var stack1; var stack1;
return "\n" return "\n"
+ ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.definitions : depth0),{"name":"if","hash":{},"fn":container.program(21, data, 0, blockParams, depths),"inverse":container.program(25, data, 0, blockParams, depths),"data":data})) != null ? stack1 : ""); + ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"if","hash":{},"fn":container.program(21, data, 0, blockParams, depths),"inverse":container.program(25, data, 0, blockParams, depths),"data":data})) != null ? stack1 : "");
},"main_d": function(fn, props, container, depth0, data, blockParams, depths) { },"main_d": function(fn, props, container, depth0, data, blockParams, depths) {
var decorators = container.decorators; var decorators = container.decorators;
@ -424,7 +437,7 @@ templates['model.html'] = template({"1":function(container,depth0,helpers,partia
+ container.escapeExpression(container.lambda(depth0, depth0)) + container.escapeExpression(container.lambda(depth0, depth0))
+ "</a></li>\n"; + "</a></li>\n";
},"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) { },"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
var stack1, helper, alias1=depth0 != null ? depth0 : {}, alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; var stack1, helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression;
return "<tr>\n <td class=\"col-sm-2\">" return "<tr>\n <td class=\"col-sm-2\">"
+ alias4(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"name","hash":{},"data":data}) : helper))) + alias4(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"name","hash":{},"data":data}) : helper)))
@ -437,7 +450,7 @@ templates['model.html'] = template({"1":function(container,depth0,helpers,partia
+ " </ul>\n </div>\n </div>\n </td>\n</tr>\n"; + " </ul>\n </div>\n </div>\n </td>\n</tr>\n";
},"useData":true}); },"useData":true});
templates['terms.html'] = template({"1":function(container,depth0,helpers,partials,data) { templates['terms.html'] = template({"1":function(container,depth0,helpers,partials,data) {
var stack1, alias1=depth0 != null ? depth0 : {}; var stack1, alias1=depth0 != null ? depth0 : (container.nullContext || {});
return ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.tags : depth0),{"name":"if","hash":{},"fn":container.program(2, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") return ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.tags : depth0),{"name":"if","hash":{},"fn":container.program(2, 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(5, data, 0),"inverse":container.program(9, data, 0),"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(5, data, 0),"inverse":container.program(9, data, 0),"data":data})) != null ? stack1 : "");
@ -445,10 +458,10 @@ templates['terms.html'] = template({"1":function(container,depth0,helpers,partia
var stack1; var stack1;
return "<div>\n" return "<div>\n"
+ ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.tags : depth0),{"name":"each","hash":{},"fn":container.program(3, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.tags : depth0),{"name":"each","hash":{},"fn":container.program(3, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ "</div>\n"; + "</div>\n";
},"3":function(container,depth0,helpers,partials,data) { },"3":function(container,depth0,helpers,partials,data) {
var helper, alias1=depth0 != null ? depth0 : {}, alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; var helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression;
return " <span class=\"label label-default tag-" return " <span class=\"label label-default tag-"
+ alias4(((helper = (helper = helpers.category || (depth0 != null ? depth0.category : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"category","hash":{},"data":data}) : helper))) + alias4(((helper = (helper = helpers.category || (depth0 != null ? depth0.category : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"category","hash":{},"data":data}) : helper)))
@ -461,12 +474,12 @@ templates['terms.html'] = template({"1":function(container,depth0,helpers,partia
var stack1; var stack1;
return "<ul>\n" return "<ul>\n"
+ ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.glossary : depth0),{"name":"each","hash":{},"fn":container.program(6, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.glossary : depth0),{"name":"each","hash":{},"fn":container.program(6, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ "</ul>\n"; + "</ul>\n";
},"6":function(container,depth0,helpers,partials,data) { },"6":function(container,depth0,helpers,partials,data) {
var stack1, helper, options, buffer = var stack1, helper, options, buffer =
" <li><span class=\"glossary-item\">"; " <li><span class=\"glossary-item\">";
stack1 = ((helper = (helper = helpers.multiLine || (depth0 != null ? depth0.multiLine : depth0)) != null ? helper : helpers.helperMissing),(options={"name":"multiLine","hash":{},"fn":container.program(7, 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(7, data, 0),"inverse":container.noop,"data":data}),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),options) : helper));
if (!helpers.multiLine) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)} if (!helpers.multiLine) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)}
if (stack1 != null) { buffer += stack1; } if (stack1 != null) { buffer += stack1; }
return buffer + "</span></li>\n"; return buffer + "</span></li>\n";
@ -475,7 +488,7 @@ templates['terms.html'] = template({"1":function(container,depth0,helpers,partia
},"9":function(container,depth0,helpers,partials,data) { },"9":function(container,depth0,helpers,partials,data) {
var stack1, helper, options, buffer = var stack1, helper, options, buffer =
"<div class=\"glossary-item\">"; "<div class=\"glossary-item\">";
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)); 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 : (container.nullContext || {}),options) : helper));
if (!helpers.multiLine) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)} if (!helpers.multiLine) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)}
if (stack1 != null) { buffer += stack1; } if (stack1 != null) { buffer += stack1; }
return buffer + "</div>\n"; return buffer + "</div>\n";
@ -484,12 +497,12 @@ templates['terms.html'] = template({"1":function(container,depth0,helpers,partia
return container.escapeExpression(container.lambda(((stack1 = (depth0 != null ? depth0.glossary : depth0)) != null ? stack1["0"] : stack1), depth0)); return container.escapeExpression(container.lambda(((stack1 = (depth0 != null ? depth0.glossary : depth0)) != null ? stack1["0"] : stack1), depth0));
},"12":function(container,depth0,helpers,partials,data) { },"12":function(container,depth0,helpers,partials,data) {
var stack1, alias1=depth0 != null ? depth0 : {}; var stack1, alias1=depth0 != null ? depth0 : (container.nullContext || {});
return "<div class=\"entry\" data-type=\"term\">\n <div class=\"actions\">\n <img src=\"/mixed/img/entry-current.png\" class=\"current\" title=\"Current entry (Alt + Up/Down/Home/End/PgUp/PgDn)\" alt>\n" return "<div class=\"entry\" data-type=\"term\">\n <div class=\"actions\">\n"
+ ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.addable : depth0),{"name":"if","hash":{},"fn":container.program(13, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.addable : depth0),{"name":"if","hash":{},"fn":container.program(13, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.playback : depth0),{"name":"if","hash":{},"fn":container.program(15, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.playback : depth0),{"name":"if","hash":{},"fn":container.program(15, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ " </div>\n\n" + " <img src=\"/mixed/img/entry-current.png\" class=\"current\" title=\"Current entry (Alt + Up/Down/Home/End/PgUp/PgDn)\" alt>\n </div>\n\n"
+ ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.reading : depth0),{"name":"if","hash":{},"fn":container.program(17, data, 0),"inverse":container.program(20, data, 0),"data":data})) != null ? stack1 : "") + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.reading : depth0),{"name":"if","hash":{},"fn":container.program(17, data, 0),"inverse":container.program(20, data, 0),"data":data})) != null ? stack1 : "")
+ "\n" + "\n"
+ ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.reasons : depth0),{"name":"if","hash":{},"fn":container.program(22, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.reasons : depth0),{"name":"if","hash":{},"fn":container.program(22, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
@ -499,11 +512,11 @@ templates['terms.html'] = template({"1":function(container,depth0,helpers,partia
+ ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.debug : depth0),{"name":"if","hash":{},"fn":container.program(34, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.debug : depth0),{"name":"if","hash":{},"fn":container.program(34, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ "</div>\n"; + "</div>\n";
},"13":function(container,depth0,helpers,partials,data) { },"13":function(container,depth0,helpers,partials,data) {
return " <a href=\"#\" class=\"action-add-note pending disabled\" data-mode=\"term-kanji\"><img src=\"/mixed/img/add-term-kanji.png\" title=\"Add expression (Alt + E)\" alt></a>\n <a href=\"#\" class=\"action-add-note pending disabled\" data-mode=\"term-kana\"><img src=\"/mixed/img/add-term-kana.png\" title=\"Add reading (Alt + R)\" alt></a>\n"; return " <a href=\"#\" class=\"action-view-note pending disabled\"><img src=\"/mixed/img/view-note.png\" title=\"View added note (Alt + V)\" alt></a>\n <a href=\"#\" class=\"action-add-note pending disabled\" data-mode=\"term-kanji\"><img src=\"/mixed/img/add-term-kanji.png\" title=\"Add expression (Alt + E)\" alt></a>\n <a href=\"#\" class=\"action-add-note pending disabled\" data-mode=\"term-kana\"><img src=\"/mixed/img/add-term-kana.png\" title=\"Add reading (Alt + R)\" alt></a>\n";
},"15":function(container,depth0,helpers,partials,data) { },"15":function(container,depth0,helpers,partials,data) {
return " <a href=\"#\" class=\"action-play-audio\"><img src=\"/mixed/img/play-audio.png\" title=\"Play audio (Alt + P)\" alt></a>\n"; return " <a href=\"#\" class=\"action-play-audio\"><img src=\"/mixed/img/play-audio.png\" title=\"Play audio (Alt + P)\" alt></a>\n";
},"17":function(container,depth0,helpers,partials,data) { },"17":function(container,depth0,helpers,partials,data) {
var stack1, helper, options, alias1=depth0 != null ? depth0 : {}, alias2=helpers.helperMissing, alias3="function", buffer = var stack1, helper, options, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", buffer =
" <div class=\"expression\"><ruby>"; " <div class=\"expression\"><ruby>";
stack1 = ((helper = (helper = helpers.kanjiLinks || (depth0 != null ? depth0.kanjiLinks : depth0)) != null ? helper : alias2),(options={"name":"kanjiLinks","hash":{},"fn":container.program(18, data, 0),"inverse":container.noop,"data":data}),(typeof helper === alias3 ? helper.call(alias1,options) : helper)); stack1 = ((helper = (helper = helpers.kanjiLinks || (depth0 != null ? depth0.kanjiLinks : depth0)) != null ? helper : alias2),(options={"name":"kanjiLinks","hash":{},"fn":container.program(18, data, 0),"inverse":container.noop,"data":data}),(typeof helper === alias3 ? helper.call(alias1,options) : helper));
if (!helpers.kanjiLinks) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)} if (!helpers.kanjiLinks) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)}
@ -514,11 +527,11 @@ templates['terms.html'] = template({"1":function(container,depth0,helpers,partia
},"18":function(container,depth0,helpers,partials,data) { },"18":function(container,depth0,helpers,partials,data) {
var helper; var helper;
return container.escapeExpression(((helper = (helper = helpers.expression || (depth0 != null ? depth0.expression : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : {},{"name":"expression","hash":{},"data":data}) : helper))); return container.escapeExpression(((helper = (helper = helpers.expression || (depth0 != null ? depth0.expression : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),{"name":"expression","hash":{},"data":data}) : helper)));
},"20":function(container,depth0,helpers,partials,data) { },"20":function(container,depth0,helpers,partials,data) {
var stack1, helper, options, buffer = var stack1, helper, options, buffer =
" <div class=\"expression\">"; " <div class=\"expression\">";
stack1 = ((helper = (helper = helpers.kanjiLinks || (depth0 != null ? depth0.kanjiLinks : depth0)) != null ? helper : helpers.helperMissing),(options={"name":"kanjiLinks","hash":{},"fn":container.program(18, data, 0),"inverse":container.noop,"data":data}),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : {},options) : helper)); stack1 = ((helper = (helper = helpers.kanjiLinks || (depth0 != null ? depth0.kanjiLinks : depth0)) != null ? helper : helpers.helperMissing),(options={"name":"kanjiLinks","hash":{},"fn":container.program(18, data, 0),"inverse":container.noop,"data":data}),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),options) : helper));
if (!helpers.kanjiLinks) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)} if (!helpers.kanjiLinks) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)}
if (stack1 != null) { buffer += stack1; } if (stack1 != null) { buffer += stack1; }
return buffer + "</div>\n"; return buffer + "</div>\n";
@ -526,7 +539,7 @@ templates['terms.html'] = template({"1":function(container,depth0,helpers,partia
var stack1; var stack1;
return " <div class=\"reasons\">\n" return " <div class=\"reasons\">\n"
+ ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.reasons : depth0),{"name":"each","hash":{},"fn":container.program(23, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.reasons : depth0),{"name":"each","hash":{},"fn":container.program(23, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ " </div>\n"; + " </div>\n";
},"23":function(container,depth0,helpers,partials,data) { },"23":function(container,depth0,helpers,partials,data) {
var stack1; var stack1;
@ -534,19 +547,19 @@ templates['terms.html'] = template({"1":function(container,depth0,helpers,partia
return " <span class=\"reasons\">" return " <span class=\"reasons\">"
+ container.escapeExpression(container.lambda(depth0, depth0)) + container.escapeExpression(container.lambda(depth0, depth0))
+ "</span> " + "</span> "
+ ((stack1 = helpers.unless.call(depth0 != null ? depth0 : {},(data && data.last),{"name":"unless","hash":{},"fn":container.program(24, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + ((stack1 = helpers.unless.call(depth0 != null ? depth0 : (container.nullContext || {}),(data && data.last),{"name":"unless","hash":{},"fn":container.program(24, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ "\n"; + "\n";
},"24":function(container,depth0,helpers,partials,data) { },"24":function(container,depth0,helpers,partials,data) {
return "&laquo;"; return "&laquo;";
},"26":function(container,depth0,helpers,partials,data) { },"26":function(container,depth0,helpers,partials,data) {
var stack1; var stack1;
return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},((stack1 = (depth0 != null ? depth0.definitions : depth0)) != null ? stack1["1"] : stack1),{"name":"if","hash":{},"fn":container.program(27, data, 0),"inverse":container.program(30, data, 0),"data":data})) != null ? stack1 : ""); return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),((stack1 = (depth0 != null ? depth0.definitions : depth0)) != null ? stack1["1"] : stack1),{"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) { },"27":function(container,depth0,helpers,partials,data) {
var stack1; var stack1;
return " <ol>\n" return " <ol>\n"
+ ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.definitions : depth0),{"name":"each","hash":{},"fn":container.program(28, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"each","hash":{},"fn":container.program(28, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ " </ol>\n"; + " </ol>\n";
},"28":function(container,depth0,helpers,partials,data) { },"28":function(container,depth0,helpers,partials,data) {
var stack1; var stack1;
@ -565,7 +578,7 @@ templates['terms.html'] = template({"1":function(container,depth0,helpers,partia
},"34":function(container,depth0,helpers,partials,data) { },"34":function(container,depth0,helpers,partials,data) {
var stack1, helper, options, buffer = var stack1, helper, options, buffer =
" <pre>"; " <pre>";
stack1 = ((helper = (helper = helpers.dumpObject || (depth0 != null ? depth0.dumpObject : depth0)) != null ? helper : helpers.helperMissing),(options={"name":"dumpObject","hash":{},"fn":container.program(35, data, 0),"inverse":container.noop,"data":data}),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : {},options) : helper)); stack1 = ((helper = (helper = helpers.dumpObject || (depth0 != null ? depth0.dumpObject : depth0)) != null ? helper : helpers.helperMissing),(options={"name":"dumpObject","hash":{},"fn":container.program(35, data, 0),"inverse":container.noop,"data":data}),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),options) : helper));
if (!helpers.dumpObject) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)} if (!helpers.dumpObject) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)}
if (stack1 != null) { buffer += stack1; } if (stack1 != null) { buffer += stack1; }
return buffer + "</pre>\n"; return buffer + "</pre>\n";
@ -576,11 +589,11 @@ templates['terms.html'] = template({"1":function(container,depth0,helpers,partia
},"37":function(container,depth0,helpers,partials,data,blockParams,depths) { },"37":function(container,depth0,helpers,partials,data,blockParams,depths) {
var stack1; var stack1;
return ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.definitions : depth0),{"name":"each","hash":{},"fn":container.program(38, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : ""); return ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"each","hash":{},"fn":container.program(38, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "");
},"38":function(container,depth0,helpers,partials,data,blockParams,depths) { },"38":function(container,depth0,helpers,partials,data,blockParams,depths) {
var stack1; var stack1;
return ((stack1 = helpers.unless.call(depth0 != null ? depth0 : {},(data && data.first),{"name":"unless","hash":{},"fn":container.program(39, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") return ((stack1 = helpers.unless.call(depth0 != null ? depth0 : (container.nullContext || {}),(data && data.first),{"name":"unless","hash":{},"fn":container.program(39, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ "\n" + "\n"
+ ((stack1 = container.invokePartial(partials.term,depth0,{"name":"term","hash":{"playback":(depths[1] != null ? depths[1].playback : depths[1]),"addable":(depths[1] != null ? depths[1].addable : depths[1]),"grouped":(depths[1] != null ? depths[1].grouped : depths[1]),"debug":(depths[1] != null ? depths[1].debug : depths[1])},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : ""); + ((stack1 = container.invokePartial(partials.term,depth0,{"name":"term","hash":{"playback":(depths[1] != null ? depths[1].playback : depths[1]),"addable":(depths[1] != null ? depths[1].addable : depths[1]),"grouped":(depths[1] != null ? depths[1].grouped : depths[1]),"debug":(depths[1] != null ? depths[1].debug : depths[1])},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "");
},"39":function(container,depth0,helpers,partials,data) { },"39":function(container,depth0,helpers,partials,data) {
@ -591,7 +604,7 @@ templates['terms.html'] = template({"1":function(container,depth0,helpers,partia
var stack1; var stack1;
return "\n\n" return "\n\n"
+ ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.definitions : depth0),{"name":"if","hash":{},"fn":container.program(37, data, 0, blockParams, depths),"inverse":container.program(41, data, 0, blockParams, depths),"data":data})) != null ? stack1 : ""); + ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"if","hash":{},"fn":container.program(37, data, 0, blockParams, depths),"inverse":container.program(41, data, 0, blockParams, depths),"data":data})) != null ? stack1 : "");
},"main_d": function(fn, props, container, depth0, data, blockParams, depths) { },"main_d": function(fn, props, container, depth0, data, blockParams, depths) {
var decorators = container.decorators; var decorators = container.decorators;

View File

@ -19,135 +19,106 @@
class Translator { class Translator {
constructor() { constructor() {
this.loaded = false; this.database = null;
this.ruleMeta = null; this.deinflector = null;
this.database = new Database();
this.deinflector = new Deinflector();
} }
prepare() { async prepare() {
if (this.loaded) { if (!this.database) {
return Promise.resolve(); this.database = new Database();
await this.database.prepare();
} }
const promises = [ if (!this.deinflector) {
jsonLoadInt('/bg/lang/deinflect.json'), const url = chrome.extension.getURL('/bg/lang/deinflect.json');
this.database.prepare() const reasons = await requestJson(url, 'GET');
]; this.deinflector = new Deinflector(reasons);
}
return Promise.all(promises).then(([reasons]) => {
this.deinflector.setReasons(reasons);
this.loaded = true;
});
} }
findTerms(text, dictionaries, alphanumeric) { async findTermsGrouped(text, dictionaries, alphanumeric) {
const titles = Object.keys(dictionaries); const {length, definitions} = await this.findTerms(text, dictionaries, alphanumeric);
const cache = {}; return {length, definitions: dictTermsGroup(definitions, dictionaries)};
}
async findTerms(text, dictionaries, alphanumeric) {
if (!alphanumeric && text.length > 0) { if (!alphanumeric && text.length > 0) {
const c = text[0]; const c = text[0];
if (!jpIsKana(c) && !jpIsKanji(c)) { if (!jpIsKana(c) && !jpIsKanji(c)) {
return Promise.resolve({length: 0, definitions: []}); return {length: 0, definitions: []};
} }
} }
return this.findTermsDeinflected(text, titles, cache).then(deinfLiteral => { const cache = {};
const textHiragana = wanakana._katakanaToHiragana(text);
if (text === textHiragana) {
return deinfLiteral;
} else {
return this.findTermsDeinflected(textHiragana, titles, cache).then(deinfHiragana => deinfLiteral.concat(deinfHiragana));
}
}).then(deinflections => {
let definitions = [];
for (const deinflection of deinflections) {
for (const definition of deinflection.definitions) {
const tags = definition.tags.map(tag => dictTagBuild(tag, definition.tagMeta));
tags.push(dictTagBuildSource(definition.dictionary));
definitions.push({
source: deinflection.source,
reasons: deinflection.reasons,
score: definition.score,
id: definition.id,
dictionary: definition.dictionary,
expression: definition.expression,
reading: definition.reading,
glossary: definition.glossary,
tags: dictTagsSort(tags)
});
}
}
definitions = dictTermsUndupe(definitions);
definitions = dictTermsSort(definitions, dictionaries);
let length = 0;
for (const definition of definitions) {
length = Math.max(length, definition.source.length);
}
return {length, definitions};
});
}
findTermsGrouped(text, dictionaries, alphanumeric) {
return this.findTerms(text, dictionaries, alphanumeric).then(({length, definitions}) => {
return {length, definitions: dictTermsGroup(definitions, dictionaries)};
});
}
findKanji(text, dictionaries) {
const titles = Object.keys(dictionaries); const titles = Object.keys(dictionaries);
const processed = {}; let deinflections = await this.findTermsDeinflected(text, titles, cache);
const promises = []; const textHiragana = jpKatakanaToHiragana(text);
if (text !== textHiragana) {
deinflections = deinflections.concat(await this.findTermsDeinflected(textHiragana, titles, cache));
}
let definitions = [];
for (const deinflection of deinflections) {
for (const definition of deinflection.definitions) {
const tags = definition.tags.map(tag => dictTagBuild(tag, definition.tagMeta));
tags.push(dictTagBuildSource(definition.dictionary));
definitions.push({
source: deinflection.source,
reasons: deinflection.reasons,
score: definition.score,
id: definition.id,
dictionary: definition.dictionary,
expression: definition.expression,
reading: definition.reading,
glossary: definition.glossary,
tags: dictTagsSort(tags)
});
}
}
definitions = dictTermsUndupe(definitions);
definitions = dictTermsSort(definitions, dictionaries);
let length = 0;
for (const definition of definitions) {
length = Math.max(length, definition.source.length);
}
return {length, definitions};
}
async findTermsDeinflected(text, titles, cache) {
const definer = async term => {
if (cache.hasOwnProperty(term)) {
return cache[term];
} else {
return cache[term] = await this.database.findTerms(term, titles);
}
};
let deinflections = [];
for (let i = text.length; i > 0; --i) {
const textSlice = text.slice(0, i);
deinflections = deinflections.concat(await this.deinflector.deinflect(textSlice, definer));
}
return deinflections;
}
async findKanji(text, dictionaries) {
let definitions = [];
const processed = {};
const titles = Object.keys(dictionaries);
for (const c of text) { for (const c of text) {
if (!processed[c]) { if (!processed[c]) {
promises.push(this.database.findKanji(c, titles)); definitions = definitions.concat(await this.database.findKanji(c, titles));
processed[c] = true; processed[c] = true;
} }
} }
return Promise.all(promises).then(defSets => {
const definitions = defSets.reduce((a, b) => a.concat(b), []);
for (const definition of definitions) {
const tags = definition.tags.map(tag => dictTagBuild(tag, definition.tagMeta));
tags.push(dictTagBuildSource(definition.dictionary));
definition.tags = dictTagsSort(tags);
}
return definitions;
});
}
findTermsDeinflected(text, dictionaries, cache) {
const definer = term => {
if (cache.hasOwnProperty(term)) {
return Promise.resolve(cache[term]);
}
return this.database.findTerms(term, dictionaries).then(definitions => cache[term] = definitions);
};
const promises = [];
for (let i = text.length; i > 0; --i) {
promises.push(this.deinflector.deinflect(text.slice(0, i), definer));
}
return Promise.all(promises).then(results => {
let deinflections = [];
for (const result of results) {
deinflections = deinflections.concat(result);
}
return deinflections;
});
}
processKanji(definitions) {
for (const definition of definitions) { for (const definition of definitions) {
const tags = definition.tags.map(tag => dictTagBuild(tag, definition.tagMeta)); const tags = definition.tags.map(tag => dictTagBuild(tag, definition.tagMeta));
tags.push(dictTagBuildSource(definition.dictionary));
definition.tags = dictTagsSort(tags); definition.tags = dictTagsSort(tags);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2016 Alex Yatskov <alex@foosoft.net> * Copyright (C) 2016-2017 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net> * Author: Alex Yatskov <alex@foosoft.net>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@ -16,542 +16,40 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
function utilAsync(func) {
/* return function(...args) {
* Promise func.apply(this, args);
*/
function promiseCallback(promise, callback) {
return promise.then(result => {
callback({result});
}).catch(error => {
callback({error});
});
}
/*
* 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);
}
/*
* 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);
}
/*
* 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) { function utilIsolate(data) {
const fixups = [ return JSON.parse(JSON.stringify(data));
() => {},
() => {},
() => {},
() => {},
() => {
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() { function utilBackend() {
return new Promise((resolve, reject) => { return chrome.extension.getBackgroundPage().yomichan_backend;
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) { function utilAnkiGetModelNames() {
return new Promise((resolve, reject) => { return utilBackend().anki.getModelNames();
chrome.storage.local.set({options: JSON.stringify(options)}, resolve);
}).then(() => {
instYomi().optionsSet(options);
fgOptionsSet(options);
});
} }
function utilAnkiGetDeckNames() {
/* return utilBackend().anki.getDeckNames();
* 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) { function utilAnkiGetModelFieldNames(modelName) {
for (const title in options.dictionaries) { return utilBackend().anki.getModelFieldNames(modelName);
if (options.dictionaries[title].enabled) {
return true;
}
}
return false;
} }
function dictRowsSort(rows, options) { function utilDatabaseGetDictionaries() {
return rows.sort((ra, rb) => { return utilBackend().translator.database.getDictionaries();
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) { function utilDatabasePurge() {
return definitions.sort((v1, v2) => { return utilBackend().translator.database.purge();
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) { function utilDatabaseImport(data, progress) {
const definitionGroups = {}; return utilBackend().translator.database.importDictionary(data, progress);
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',
'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
*/
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));
}
/*
* 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
*/
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 += `<a href="#" class="kanji-link">${c}</a>`;
} else {
result += c;
}
}
return result;
}
function handlebarsMultiLine(options) {
return options.fn(this).split('\n').join('<br>');
}
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);
} }

View File

@ -1,225 +0,0 @@
/*
* Copyright (C) 2016 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net>
*
* 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 <http://www.gnu.org/licenses/>.
*/
window.yomichan = new class {
constructor() {
handlebarsRegister();
this.translator = new Translator();
this.anki = new AnkiNull();
this.options = null;
this.translator.prepare().then(optionsLoad).then(this.optionsSet.bind(this)).then(() => {
chrome.commands.onCommand.addListener(this.onCommand.bind(this));
chrome.runtime.onMessage.addListener(this.onMessage.bind(this));
if (this.options.general.showGuide) {
chrome.tabs.create({url: chrome.extension.getURL('/bg/guide.html')});
}
});
}
optionsSet(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.
this.options = JSON.parse(JSON.stringify(options));
if (!this.options.general.enable) {
chrome.browserAction.setBadgeBackgroundColor({color: '#d9534f'});
chrome.browserAction.setBadgeText({text: 'off'});
} else if (!dictConfigured(this.options)) {
chrome.browserAction.setBadgeBackgroundColor({color: '#f0ad4e'});
chrome.browserAction.setBadgeText({text: '!'});
} else {
chrome.browserAction.setBadgeText({text: ''});
}
if (this.options.anki.enable) {
this.anki = new AnkiConnect(this.options.anki.server);
} else {
this.anki = new AnkiNull();
}
}
noteFormat(definition, mode) {
const note = {
fields: {},
tags: this.options.anki.tags
};
let fields = [];
if (mode === 'kanji') {
fields = this.options.anki.kanji.fields;
note.deckName = this.options.anki.kanji.deck;
note.modelName = this.options.anki.kanji.model;
} else {
fields = this.options.anki.terms.fields;
note.deckName = this.options.anki.terms.deck;
note.modelName = this.options.anki.terms.model;
if (definition.audio) {
const audio = {
url: definition.audio.url,
filename: definition.audio.filename,
skipHash: '7e2c2f954ef6051373ba916f000168dc',
fields: []
};
for (const name in fields) {
if (fields[name].includes('{audio}')) {
audio.fields.push(name);
}
}
if (audio.fields.length > 0) {
note.audio = audio;
}
}
}
for (const name in fields) {
note.fields[name] = dictFieldFormat(
fields[name],
definition,
mode,
this.options
);
}
return note;
}
termsFind(text) {
const searcher = this.options.general.groupResults ?
this.translator.findTermsGrouped.bind(this.translator) :
this.translator.findTerms.bind(this.translator);
return searcher(text, dictEnabledSet(this.options), this.options.scanning.alphanumeric).then(({definitions, length}) => {
return {length, definitions: definitions.slice(0, this.options.general.maxResults)};
});
}
kanjiFind(text) {
return this.translator.findKanji(text, dictEnabledSet(this.options)).then(definitions => {
return definitions.slice(0, this.options.general.maxResults);
});
}
definitionAdd(definition, mode) {
let promise = Promise.resolve();
if (mode !== 'kanji') {
promise = audioInject(definition, this.options.anki.terms.fields, this.options.general.audioSource);
}
return promise.then(() => {
const note = this.noteFormat(definition, mode);
return this.anki.addNote(note);
});
}
definitionsAddable(definitions, modes) {
const notes = [];
for (const definition of definitions) {
for (const mode of modes) {
notes.push(this.noteFormat(definition, mode));
}
}
return this.anki.canAddNotes(notes).then(raw => {
const states = [];
for (let resultBase = 0; resultBase < raw.length; resultBase += modes.length) {
const state = {};
for (let modeOffset = 0; modeOffset < modes.length; ++modeOffset) {
state[modes[modeOffset]] = raw[resultBase + modeOffset];
}
states.push(state);
}
return states;
});
}
templateRender(template, data) {
return Promise.resolve(handlebarsRender(template, data));
}
onCommand(command) {
const handlers = {
search: () => {
chrome.tabs.create({url: chrome.extension.getURL('/bg/search.html')});
},
help: () => {
chrome.tabs.create({url: 'https://foosoft.net/projects/yomichan/'});
},
options: () => {
chrome.runtime.openOptionsPage();
},
toggle: () => {
this.options.general.enable = !this.options.general.enable;
optionsSave(this.options).then(() => this.optionsSet(this.options));
}
};
const handler = handlers[command];
if (handler) {
handler();
}
}
onMessage({action, params}, sender, callback) {
const handlers = {
optionsGet: ({callback}) => {
promiseCallback(optionsLoad(), callback);
},
kanjiFind: ({text, callback}) => {
promiseCallback(this.kanjiFind(text), callback);
},
termsFind: ({text, callback}) => {
promiseCallback(this.termsFind(text), callback);
},
templateRender: ({template, data, callback}) => {
promiseCallback(this.templateRender(template, data), callback);
},
definitionAdd: ({definition, mode, callback}) => {
promiseCallback(this.definitionAdd(definition, mode), callback);
},
definitionsAddable: ({definitions, modes, callback}) => {
promiseCallback(this.definitionsAddable(definitions, modes), callback);
}
};
const handler = handlers[action];
if (handler) {
params.callback = callback;
handler(params);
}
return true;
}
};

View File

@ -10,7 +10,7 @@
<div class="container-fluid"> <div class="container-fluid">
<h3>Yomichan License</h3> <h3>Yomichan License</h3>
<pre> <pre>
Copyright (C) 2016 Alex Yatskov Copyright (C) 2016-2017 Alex Yatskov
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by

View File

@ -5,7 +5,7 @@
<title>Yomichan Search</title> <title>Yomichan Search</title>
<link rel="stylesheet" type="text/css" href="/mixed/lib/bootstrap/css/bootstrap.min.css"> <link rel="stylesheet" type="text/css" href="/mixed/lib/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="/mixed/lib/bootstrap/css/bootstrap-theme.min.css"> <link rel="stylesheet" type="text/css" href="/mixed/lib/bootstrap/css/bootstrap-theme.min.css">
<link rel="stylesheet" type="text/css" href="/mixed/css/frame.css"> <link rel="stylesheet" type="text/css" href="/mixed/css/display.css">
</head> </head>
<body> <body>
<div class="container-fluid"> <div class="container-fluid">
@ -32,11 +32,19 @@
<div id="content"></div> <div id="content"></div>
</div> </div>
<script src="/mixed/lib/handlebars.min.js"></script>
<script src="/mixed/lib/jquery.min.js"></script> <script src="/mixed/lib/jquery.min.js"></script>
<script src="/bg/js/util.js"></script>
<script src="/mixed/js/util.js"></script>
<script src="/mixed/js/display.js"></script>
<script src="/mixed/lib/wanakana.min.js"></script> <script src="/mixed/lib/wanakana.min.js"></script>
<script src="/bg/js/display-window.js"></script>
<script src="/bg/js/api.js"></script>
<script src="/bg/js/audio.js"></script>
<script src="/bg/js/dictionary.js"></script>
<script src="/bg/js/handlebars.js"></script>
<script src="/bg/js/templates.js"></script>
<script src="/bg/js/util.js"></script>
<script src="/mixed/js/display.js"></script>
<script src="/mixed/js/japanese.js"></script>
<script src="/bg/js/search.js"></script>
</body> </body>
</html> </html>

View File

@ -48,6 +48,7 @@
<option value="disabled">Disabled</option> <option value="disabled">Disabled</option>
<option value="jpod101">JapanesePod101</option> <option value="jpod101">JapanesePod101</option>
<option value="jpod101-alternate">JapanesePod101 (alternate)</option> <option value="jpod101-alternate">JapanesePod101 (alternate)</option>
<option value="jisho">Jisho.org</option>
</select> </select>
</div> </div>
@ -275,8 +276,15 @@
<script src="/mixed/lib/jquery.min.js"></script> <script src="/mixed/lib/jquery.min.js"></script>
<script src="/mixed/lib/bootstrap/js/bootstrap.min.js"></script> <script src="/mixed/lib/bootstrap/js/bootstrap.min.js"></script>
<script src="/mixed/lib/handlebars.min.js"></script> <script src="/mixed/lib/handlebars.min.js"></script>
<script src="/bg/js/anki.js"></script>
<script src="/bg/js/api.js"></script>
<script src="/bg/js/dictionary.js"></script>
<script src="/bg/js/handlebars.js"></script>
<script src="/bg/js/options.js"></script>
<script src="/bg/js/templates.js"></script> <script src="/bg/js/templates.js"></script>
<script src="/bg/js/util.js"></script> <script src="/bg/js/util.js"></script>
<script src="/bg/js/options.js"></script>
<script src="/bg/js/settings.js"></script>
</body> </body>
</html> </html>

View File

@ -17,7 +17,7 @@
*/ */
iframe#yomichan-popup { iframe#yomichan-float {
all: initial; all: initial;
background-color: #fff; background-color: #fff;
border: 1px solid #999; border: 1px solid #999;

View File

@ -5,7 +5,7 @@
<title></title> <title></title>
<link rel="stylesheet" href="/mixed/lib/bootstrap/css/bootstrap.min.css"> <link rel="stylesheet" href="/mixed/lib/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="/mixed/lib/bootstrap/css/bootstrap-theme.min.css"> <link rel="stylesheet" href="/mixed/lib/bootstrap/css/bootstrap-theme.min.css">
<link rel="stylesheet" href="/mixed/css/frame.css"> <link rel="stylesheet" href="/mixed/css/display.css">
<style type="text/css"> <style type="text/css">
.entry, .note { .entry, .note {
padding-left: 10px; padding-left: 10px;
@ -18,9 +18,9 @@
<img src="/mixed/img/spinner.gif"> <img src="/mixed/img/spinner.gif">
</div> </div>
<div id="content"></div> <div id="definitions"></div>
<div id="orphan"> <div id="error-orphaned">
<div class="container-fluid"> <div class="container-fluid">
<h1>Yomichan Updated!</h1> <h1>Yomichan Updated!</h1>
<p> <p>
@ -32,9 +32,11 @@
<script src="/mixed/lib/jquery.min.js"></script> <script src="/mixed/lib/jquery.min.js"></script>
<script src="/mixed/lib/wanakana.min.js"></script> <script src="/mixed/lib/wanakana.min.js"></script>
<script src="/fg/js/api.js"></script>
<script src="/fg/js/util.js"></script> <script src="/fg/js/util.js"></script>
<script src="/mixed/js/util.js"></script>
<script src="/mixed/js/display.js"></script> <script src="/mixed/js/display.js"></script>
<script src="/fg/js/display-frame.js"></script>
<script src="/fg/js/float.js"></script>
</body> </body>
</html> </html>

58
ext/fg/js/api.js Normal file
View File

@ -0,0 +1,58 @@
/*
* Copyright (C) 2016-2017 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net>
*
* 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 <http://www.gnu.org/licenses/>.
*/
function apiOptionsSet(options) {
return utilInvoke('optionsSet', {options});
}
function apiOptionsGet() {
return utilInvoke('optionsGet');
}
function apiTermsFind(text) {
return utilInvoke('termsFind', {text});
}
function apiKanjiFind(text) {
return utilInvoke('kanjiFind', {text});
}
function apiDefinitionAdd(definition, mode) {
return utilInvoke('definitionAdd', {definition, mode});
}
function apiDefinitionsAddable(definitions, modes) {
return utilInvoke('definitionsAddable', {definitions, modes}).catch(() => null);
}
function apiNoteView(noteId) {
return utilInvoke('noteView', {noteId});
}
function apiTemplateRender(template, data) {
return utilInvoke('templateRender', {data, template});
}
function apiCommandExec(command) {
return utilInvoke('commandExec', {command});
}
function apiAudioGetUrl(definition, source) {
return utilInvoke('audioGetUrl', {definition, source});
}

163
ext/fg/js/document.js Normal file
View File

@ -0,0 +1,163 @@
/*
* Copyright (C) 2016-2017 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net>
*
* 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 <http://www.gnu.org/licenses/>.
*/
function docOffsetCalc(element) {
const scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
const scrollLeft = window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft;
const clientTop = document.documentElement.clientTop || document.body.clientTop || 0;
const clientLeft = document.documentElement.clientLeft || document.body.clientLeft || 0;
const rect = element.getBoundingClientRect();
const top = Math.round(rect.top + scrollTop - clientTop);
const left = Math.round(rect.left + scrollLeft - clientLeft);
return {top, left};
}
function docImposterCreate(element) {
const styleProps = window.getComputedStyle(element);
const stylePairs = [];
for (const key of styleProps) {
stylePairs.push(`${key}: ${styleProps[key]};`);
}
const offset = docOffsetCalc(element);
const imposter = document.createElement('div');
imposter.className = 'yomichan-imposter';
imposter.innerText = element.value;
imposter.style.cssText = stylePairs.join('\n');
imposter.style.position = 'absolute';
imposter.style.top = `${offset.top}px`;
imposter.style.left = `${offset.left}px`;
imposter.style.opacity = 0;
imposter.style.zIndex = 2147483646;
if (element.nodeName === 'TEXTAREA' && styleProps.overflow === 'visible') {
imposter.style.overflow = 'auto';
}
document.body.appendChild(imposter);
imposter.scrollTop = element.scrollTop;
imposter.scrollLeft = element.scrollLeft;
}
function docImposterDestroy() {
for (const element of document.getElementsByClassName('yomichan-imposter')) {
element.parentNode.removeChild(element);
}
}
function docRangeFromPoint(point) {
const element = document.elementFromPoint(point.x, point.y);
if (element) {
if (element.nodeName === 'IMG' || element.nodeName === 'BUTTON') {
return new TextSourceElement(element);
} else if (element.nodeName === 'INPUT' || element.nodeName === 'TEXTAREA') {
docImposterCreate(element);
}
}
if (!document.caretRangeFromPoint) {
document.caretRangeFromPoint = (x, y) => {
const position = document.caretPositionFromPoint(x,y);
if (position) {
const range = document.createRange();
range.setStart(position.offsetNode, position.offset);
range.setEnd(position.offsetNode, position.offset);
return range;
}
};
}
const range = document.caretRangeFromPoint(point.x, point.y);
if (range) {
return new TextSourceRange(range);
}
}
function docSentenceExtract(source, extent) {
const quotesFwd = {'「': '」', '『': '』', "'": "'", '"': '"'};
const quotesBwd = {'」': '「', '』': '『', "'": "'", '"': '"'};
const terminators = '…。..?!';
const sourceLocal = source.clone();
const position = sourceLocal.setStartOffset(extent);
sourceLocal.setEndOffset(position + extent);
const content = sourceLocal.text();
let quoteStack = [];
let startPos = 0;
for (let i = position; i >= startPos; --i) {
const c = content[i];
if (c === '\n') {
startPos = i + 1;
break;
}
if (quoteStack.length === 0 && (terminators.includes(c) || c in quotesFwd)) {
startPos = i + 1;
break;
}
if (quoteStack.length > 0 && c === quoteStack[0]) {
quoteStack.pop();
} else if (c in quotesBwd) {
quoteStack = [quotesBwd[c]].concat(quoteStack);
}
}
quoteStack = [];
let endPos = content.length;
for (let i = position; i <= endPos; ++i) {
const c = content[i];
if (c === '\n') {
endPos = i + 1;
break;
}
if (quoteStack.length === 0) {
if (terminators.includes(c)) {
endPos = i + 1;
break;
}
else if (c in quotesBwd) {
endPos = i;
break;
}
}
if (quoteStack.length > 0 && c === quoteStack[0]) {
quoteStack.pop();
} else if (c in quotesFwd) {
quoteStack = [quotesFwd[c]].concat(quoteStack);
}
}
const text = content.substring(startPos, endPos);
const padding = text.length - text.replace(/^\s+/, '').length;
return {
text: text.trim(),
offset: position - startPos - padding
};
}

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2016 Alex Yatskov <alex@foosoft.net> * Copyright (C) 2016-2017 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net> * Author: Alex Yatskov <alex@foosoft.net>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@ -17,61 +17,45 @@
*/ */
window.displayFrame = new class extends Display { class DisplayFloat extends Display {
constructor() { constructor() {
super($('#spinner'), $('#content')); super($('#spinner'), $('#definitions'));
$(window).on('message', this.onMessage.bind(this)); $(window).on('message', utilAsync(this.onMessage.bind(this)));
} }
definitionAdd(definition, mode) { onError(error) {
return bgDefinitionAdd(definition, mode); if (window.yomichan_orphaned) {
} this.onOrphaned();
definitionsAddable(definitions, modes) {
return bgDefinitionsAddable(definitions, modes);
}
templateRender(template, data) {
return bgTemplateRender(template, data);
}
kanjiFind(character) {
return bgKanjiFind(character);
}
handleError(error) {
if (window.orphaned) {
this.showOrphaned();
} else { } else {
window.alert(`Error: ${error}`); window.alert(`Error: ${error}`);
} }
} }
clearSearch() { onOrphaned() {
$('#definitions').hide();
$('#error-orphaned').show();
}
onSearchClear() {
window.parent.postMessage('popupClose', '*'); window.parent.postMessage('popupClose', '*');
} }
selectionCopy() { onSelectionCopy() {
window.parent.postMessage('selectionCopy', '*'); window.parent.postMessage('selectionCopy', '*');
} }
showOrphaned() {
$('#content').hide();
$('#orphan').show();
}
onMessage(e) { onMessage(e) {
const handlers = { const handlers = {
showTermDefs: ({definitions, options, context}) => { termsShow: ({definitions, options, context}) => {
this.showTermDefs(definitions, options, context); this.termsShow(definitions, options, context);
}, },
showKanjiDefs: ({definitions, options, context}) => { kanjiShow: ({definitions, options, context}) => {
this.showKanjiDefs(definitions, options, context); this.kanjiShow(definitions, options, context);
}, },
showOrphaned: () => { orphaned: () => {
this.showOrphaned(); this.onOrphaned();
} }
}; };
@ -85,8 +69,8 @@ window.displayFrame = new class extends Display {
onKeyDown(e) { onKeyDown(e) {
const handlers = { const handlers = {
67: /* c */ () => { 67: /* c */ () => {
if (e.ctrlKey && window.getSelection().toString() === '') { if (e.ctrlKey && !window.getSelection().toString()) {
this.selectionCopy(); this.onSelectionCopy();
return true; return true;
} }
} }
@ -99,4 +83,6 @@ window.displayFrame = new class extends Display {
super.onKeyDown(e); super.onKeyDown(e);
} }
} }
}; }
window.yomichan_display = new DisplayFloat();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2016 Alex Yatskov <alex@foosoft.net> * Copyright (C) 2016-2017 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net> * Author: Alex Yatskov <alex@foosoft.net>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@ -17,38 +17,31 @@
*/ */
window.driver = new class { class Frontend {
constructor() { constructor() {
this.popup = new Popup(); this.popup = new Popup();
this.popupTimer = null; this.popupTimer = null;
this.lastMousePos = null;
this.mouseDownLeft = false; this.mouseDownLeft = false;
this.mouseDownMiddle = false; this.mouseDownMiddle = false;
this.lastTextSource = null; this.textSourceLast = null;
this.pendingLookup = false; this.pendingLookup = false;
this.options = null; this.options = null;
}
async prepare() {
try {
this.options = await apiOptionsGet();
bgOptionsGet().then(options => {
this.options = options;
window.addEventListener('mouseover', this.onMouseOver.bind(this));
window.addEventListener('mousedown', this.onMouseDown.bind(this));
window.addEventListener('mouseup', this.onMouseUp.bind(this));
window.addEventListener('mousemove', this.onMouseMove.bind(this));
window.addEventListener('resize', e => this.searchClear());
window.addEventListener('message', this.onFrameMessage.bind(this)); window.addEventListener('message', this.onFrameMessage.bind(this));
window.addEventListener('mousedown', this.onMouseDown.bind(this));
window.addEventListener('mousemove', this.onMouseMove.bind(this));
window.addEventListener('mouseover', this.onMouseOver.bind(this));
window.addEventListener('mouseup', this.onMouseUp.bind(this));
window.addEventListener('resize', this.onResize.bind(this));
chrome.runtime.onMessage.addListener(this.onBgMessage.bind(this)); chrome.runtime.onMessage.addListener(this.onBgMessage.bind(this));
}).catch(this.handleError.bind(this)); } catch (e) {
} this.onError(e);
popupTimerSet(callback) {
this.popupTimerClear();
this.popupTimer = window.setTimeout(callback, this.options.scanning.delay);
}
popupTimerClear() {
if (this.popupTimer) {
window.clearTimeout(this.popupTimer);
this.popupTimer = null;
} }
} }
@ -59,7 +52,6 @@ window.driver = new class {
} }
onMouseMove(e) { onMouseMove(e) {
this.lastMousePos = {x: e.clientX, y: e.clientY};
this.popupTimerClear(); this.popupTimerClear();
if (!this.options.general.enable) { if (!this.options.general.enable) {
@ -70,6 +62,10 @@ window.driver = new class {
return; return;
} }
if (this.pendingLookup) {
return;
}
const mouseScan = this.mouseDownMiddle && this.options.scanning.middleMouse; const mouseScan = this.mouseDownMiddle && this.options.scanning.middleMouse;
const keyScan = const keyScan =
this.options.scanning.modifier === 'alt' && e.altKey || this.options.scanning.modifier === 'alt' && e.altKey ||
@ -81,16 +77,24 @@ window.driver = new class {
return; return;
} }
const searchFunc = () => this.searchAt(this.lastMousePos); const search = async () => {
try {
await this.searchAt({x: e.clientX, y: e.clientY});
this.pendingLookup = false;
} catch (e) {
this.onError(e);
}
};
if (this.options.scanning.modifier === 'none') { if (this.options.scanning.modifier === 'none') {
this.popupTimerSet(searchFunc); this.popupTimerSet(search);
} else { } else {
searchFunc(); search();
} }
} }
onMouseDown(e) { onMouseDown(e) {
this.lastMousePos = {x: e.clientX, y: e.clientY}; this.mousePosLast = {x: e.clientX, y: e.clientY};
this.popupTimerClear(); this.popupTimerClear();
this.searchClear(); this.searchClear();
@ -126,6 +130,10 @@ window.driver = new class {
} }
} }
onResize() {
this.searchClear();
}
onBgMessage({action, params}, sender, callback) { onBgMessage({action, params}, sender, callback) {
const handlers = { const handlers = {
optionsSet: options => { optionsSet: options => {
@ -144,106 +152,122 @@ window.driver = new class {
callback(); callback();
} }
searchAt(point) { onError(error) {
if (this.pendingLookup) { window.alert(`Error: ${error}`);
return; }
}
const textSource = docRangeFromPoint(point); popupTimerSet(callback) {
if (!textSource || !textSource.containsPoint(point)) { this.popupTimerClear();
docImposterDestroy(); this.popupTimer = window.setTimeout(callback, this.options.scanning.delay);
return; }
}
if (this.lastTextSource && this.lastTextSource.equals(textSource)) { popupTimerClear() {
return; if (this.popupTimer) {
window.clearTimeout(this.popupTimer);
this.popupTimer = null;
} }
}
this.pendingLookup = true; async searchAt(point) {
this.searchTerms(textSource).then(found => { let textSource = null;
if (!found) {
return this.searchKanji(textSource); try {
if (this.pendingLookup) {
return;
} }
}).catch(error => {
this.handleError(error, textSource); textSource = docRangeFromPoint(point);
}).then(() => { if (!textSource || !textSource.containsPoint(point)) {
docImposterDestroy();
return;
}
if (this.textSourceLast && this.textSourceLast.equals(textSource)) {
return;
}
this.pendingLookup = true;
if (!await this.searchTerms(textSource)) {
await this.searchKanji(textSource);
}
} catch (e) {
if (window.yomichan_orphaned) {
if (textSource && this.options.scanning.modifier !== 'none') {
this.popup.showOrphaned(textSource.getRect(), this.options);
}
} else {
this.onError(e);
}
} finally {
docImposterDestroy(); docImposterDestroy();
this.pendingLookup = false; this.pendingLookup = false;
}); }
} }
searchTerms(textSource) { async searchTerms(textSource) {
textSource.setEndOffset(this.options.scanning.length); textSource.setEndOffset(this.options.scanning.length);
return bgTermsFind(textSource.text()).then(({definitions, length}) => { const {definitions, length} = await apiTermsFind(textSource.text());
if (definitions.length === 0) { if (definitions.length === 0) {
return false; return false;
} else { }
textSource.setEndOffset(length);
const sentence = docSentenceExtract(textSource, this.options.anki.sentenceExt); textSource.setEndOffset(length);
const url = window.location.href;
this.popup.showTermDefs(
textSource.getRect(),
definitions,
this.options,
{sentence, url}
);
this.lastTextSource = textSource; const sentence = docSentenceExtract(textSource, this.options.anki.sentenceExt);
if (this.options.scanning.selectText) { const url = window.location.href;
textSource.select(); this.popup.termsShow(
} textSource.getRect(),
definitions,
this.options,
{sentence, url}
);
return true; this.textSourceLast = textSource;
} if (this.options.scanning.selectText) {
}); textSource.select();
}
return true;
} }
searchKanji(textSource) { async searchKanji(textSource) {
textSource.setEndOffset(1); textSource.setEndOffset(1);
return bgKanjiFind(textSource.text()).then(definitions => { const definitions = await apiKanjiFind(textSource.text());
if (definitions.length === 0) { if (definitions.length === 0) {
return false; return false;
} else { }
const sentence = docSentenceExtract(textSource, this.options.anki.sentenceExt);
const url = window.location.href;
this.popup.showKanjiDefs(
textSource.getRect(),
definitions,
this.options,
{sentence, url}
);
this.lastTextSource = textSource; const sentence = docSentenceExtract(textSource, this.options.anki.sentenceExt);
if (this.options.scanning.selectText) { const url = window.location.href;
textSource.select(); this.popup.kanjiShow(
} textSource.getRect(),
definitions,
this.options,
{sentence, url}
);
return true; this.textSourceLast = textSource;
} if (this.options.scanning.selectText) {
}); textSource.select();
}
return true;
} }
searchClear() { searchClear() {
docImposterDestroy(); docImposterDestroy();
this.popup.hide(); this.popup.hide();
if (this.options.scanning.selectText && this.lastTextSource) { if (this.options.scanning.selectText && this.textSourceLast) {
this.lastTextSource.deselect(); this.textSourceLast.deselect();
} }
this.lastTextSource = null; this.textSourceLast = null;
} }
}
handleError(error, textSource) { window.yomichan_frontend = new Frontend();
if (window.orphaned) { window.yomichan_frontend.prepare();
if (textSource && this.options.scanning.modifier !== 'none') {
this.popup.showOrphaned(textSource.getRect(), this.options);
}
} else {
window.alert(`Error: ${error}`);
}
}
};

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2016 Alex Yatskov <alex@foosoft.net> * Copyright (C) 2016-2017 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net> * Author: Alex Yatskov <alex@foosoft.net>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@ -20,10 +20,10 @@
class Popup { class Popup {
constructor() { constructor() {
this.container = document.createElement('iframe'); this.container = document.createElement('iframe');
this.container.id = 'yomichan-popup'; this.container.id = 'yomichan-float';
this.container.addEventListener('mousedown', e => e.stopPropagation()); this.container.addEventListener('mousedown', e => e.stopPropagation());
this.container.addEventListener('scroll', e => e.stopPropagation()); this.container.addEventListener('scroll', e => e.stopPropagation());
this.container.setAttribute('src', chrome.extension.getURL('/fg/frame.html')); this.container.setAttribute('src', chrome.extension.getURL('/fg/float.html'));
this.container.style.width = '0px'; this.container.style.width = '0px';
this.container.style.height = '0px'; this.container.style.height = '0px';
this.injected = null; this.injected = null;
@ -40,51 +40,56 @@ class Popup {
return this.injected; return this.injected;
} }
show(elementRect, options) { async show(elementRect, options) {
return this.inject().then(() => { await this.inject();
const containerStyle = window.getComputedStyle(this.container);
const containerHeight = parseInt(containerStyle.height);
const containerWidth = parseInt(containerStyle.width);
const limitX = document.body.clientWidth; const containerStyle = window.getComputedStyle(this.container);
const limitY = window.innerHeight; const containerHeight = parseInt(containerStyle.height);
const containerWidth = parseInt(containerStyle.width);
let x = elementRect.left; const limitX = document.body.clientWidth;
let width = Math.max(containerWidth, options.general.popupWidth); const limitY = window.innerHeight;
const overflowX = Math.max(x + width - limitX, 0);
if (overflowX > 0) {
if (x >= overflowX) {
x -= overflowX;
} else {
width = limitX;
x = 0;
}
}
let y = 0; let x = elementRect.left;
let height = Math.max(containerHeight, options.general.popupHeight); let width = Math.max(containerWidth, options.general.popupWidth);
const yBelow = elementRect.bottom + options.general.popupOffset; const overflowX = Math.max(x + width - limitX, 0);
const yAbove = elementRect.top - options.general.popupOffset; if (overflowX > 0) {
const overflowBelow = Math.max(yBelow + height - limitY, 0); if (x >= overflowX) {
const overflowAbove = Math.max(height - yAbove, 0); x -= overflowX;
if (overflowBelow > 0 || overflowAbove > 0) {
if (overflowBelow < overflowAbove) {
height = Math.max(height - overflowBelow, 0);
y = yBelow;
} else {
height = Math.max(height - overflowAbove, 0);
y = Math.max(yAbove - height, 0);
}
} else { } else {
y = yBelow; width = limitX;
x = 0;
} }
}
this.container.style.left = `${x}px`; let y = 0;
this.container.style.top = `${y}px`; let height = Math.max(containerHeight, options.general.popupHeight);
this.container.style.width = `${width}px`; const yBelow = elementRect.bottom + options.general.popupOffset;
this.container.style.height = `${height}px`; const yAbove = elementRect.top - options.general.popupOffset;
this.container.style.visibility = 'visible'; const overflowBelow = Math.max(yBelow + height - limitY, 0);
}); const overflowAbove = Math.max(height - yAbove, 0);
if (overflowBelow > 0 || overflowAbove > 0) {
if (overflowBelow < overflowAbove) {
height = Math.max(height - overflowBelow, 0);
y = yBelow;
} else {
height = Math.max(height - overflowAbove, 0);
y = Math.max(yAbove - height, 0);
}
} else {
y = yBelow;
}
this.container.style.left = `${x}px`;
this.container.style.top = `${y}px`;
this.container.style.width = `${width}px`;
this.container.style.height = `${height}px`;
this.container.style.visibility = 'visible';
}
async showOrphaned(elementRect, options) {
await this.show(elementRect, options);
this.invokeApi('orphaned');
} }
hide() { hide() {
@ -95,22 +100,14 @@ class Popup {
return this.injected && this.container.style.visibility !== 'hidden'; return this.injected && this.container.style.visibility !== 'hidden';
} }
showTermDefs(elementRect, definitions, options, context) { async termsShow(elementRect, definitions, options, context) {
this.show(elementRect, options).then(() => { await this.show(elementRect, options);
this.invokeApi('showTermDefs', {definitions, options, context}); this.invokeApi('termsShow', {definitions, options, context});
});
} }
showKanjiDefs(elementRect, definitions, options, context) { async kanjiShow(elementRect, definitions, options, context) {
this.show(elementRect, options).then(() => { await this.show(elementRect, options);
this.invokeApi('showKanjiDefs', {definitions, options, context}); this.invokeApi('kanjiShow', {definitions, options, context});
});
}
showOrphaned(elementRect, options) {
this.show(elementRect, options).then(() => {
this.invokeApi('showOrphaned');
});
} }
invokeApi(action, params={}) { invokeApi(action, params={}) {

View File

@ -1,77 +0,0 @@
/*
* Copyright (C) 2016 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net>
*
* 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 <http://www.gnu.org/licenses/>.
*/
class TextSourceElement {
constructor(element, content='') {
this.element = element;
this.content = content;
}
clone() {
return new TextSourceElement(this.element, this.content);
}
text() {
return this.content;
}
setEndOffset(length) {
switch (this.element.nodeName) {
case 'BUTTON':
this.content = this.element.innerHTML;
break;
case 'IMG':
this.content = this.element.getAttribute('alt');
break;
default:
this.content = this.element.value;
break;
}
this.content = this.content || '';
this.content = this.content.substring(0, length);
return this.content.length;
}
setStartOffset(length) {
return 0;
}
containsPoint(point) {
const rect = this.getRect();
return point.x >= rect.left && point.x <= rect.right;
}
getRect() {
return this.element.getBoundingClientRect();
}
select() {
// NOP
}
deselect() {
// NOP
}
equals(other) {
return other.element === this.element && other.content === this.content;
}
}

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2016 Alex Yatskov <alex@foosoft.net> * Copyright (C) 2016-2017 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net> * Author: Alex Yatskov <alex@foosoft.net>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@ -17,6 +17,10 @@
*/ */
/*
* TextSourceRange
*/
class TextSourceRange { class TextSourceRange {
constructor(range, content='') { constructor(range, content='') {
this.range = range; this.range = range;
@ -174,3 +178,67 @@ class TextSourceRange {
return state.remainder > 0; return state.remainder > 0;
} }
} }
/*
* TextSourceElement
*/
class TextSourceElement {
constructor(element, content='') {
this.element = element;
this.content = content;
}
clone() {
return new TextSourceElement(this.element, this.content);
}
text() {
return this.content;
}
setEndOffset(length) {
switch (this.element.nodeName) {
case 'BUTTON':
this.content = this.element.innerHTML;
break;
case 'IMG':
this.content = this.element.getAttribute('alt');
break;
default:
this.content = this.element.value;
break;
}
this.content = this.content || '';
this.content = this.content.substring(0, length);
return this.content.length;
}
setStartOffset(length) {
return 0;
}
containsPoint(point) {
const rect = this.getRect();
return point.x >= rect.left && point.x <= rect.right;
}
getRect() {
return this.element.getBoundingClientRect();
}
select() {
// NOP
}
deselect() {
// NOP
}
equals(other) {
return other.element === this.element && other.content === this.content;
}
}

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2016 Alex Yatskov <alex@foosoft.net> * Copyright (C) 2016-2017 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net> * Author: Alex Yatskov <alex@foosoft.net>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@ -17,11 +17,13 @@
*/ */
/* function utilAsync(func) {
* Background return function(...args) {
*/ func.apply(this, args);
};
}
function bgInvoke(action, params) { function utilInvoke(action, params={}) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
try { try {
chrome.runtime.sendMessage({action, params}, ({result, error}) => { chrome.runtime.sendMessage({action, params}, ({result, error}) => {
@ -32,185 +34,8 @@ function bgInvoke(action, params) {
} }
}); });
} catch (e) { } catch (e) {
window.orphaned = true; window.yomichan_orphaned = true;
reject(e.message); reject(e.message);
} }
}); });
} }
function bgOptionsGet() {
return bgInvoke('optionsGet', {});
}
function bgTermsFind(text) {
return bgInvoke('termsFind', {text});
}
function bgKanjiFind(text) {
return bgInvoke('kanjiFind', {text});
}
function bgTemplateRender(template, data) {
return bgInvoke('templateRender', {data, template});
}
function bgDefinitionsAddable(definitions, modes) {
return bgInvoke('definitionsAddable', {definitions, modes}).catch(() => null);
}
function bgDefinitionAdd(definition, mode) {
return bgInvoke('definitionAdd', {definition, mode});
}
/*
* Document
*/
function docOffsetCalc(element) {
const scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
const scrollLeft = window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft;
const clientTop = document.documentElement.clientTop || document.body.clientTop || 0;
const clientLeft = document.documentElement.clientLeft || document.body.clientLeft || 0;
const rect = element.getBoundingClientRect();
const top = Math.round(rect.top + scrollTop - clientTop);
const left = Math.round(rect.left + scrollLeft - clientLeft);
return {top, left};
}
function docImposterCreate(element) {
const styleProps = window.getComputedStyle(element);
const stylePairs = [];
for (const key of styleProps) {
stylePairs.push(`${key}: ${styleProps[key]};`);
}
const offset = docOffsetCalc(element);
const imposter = document.createElement('div');
imposter.className = 'yomichan-imposter';
imposter.innerText = element.value;
imposter.style.cssText = stylePairs.join('\n');
imposter.style.position = 'absolute';
imposter.style.top = `${offset.top}px`;
imposter.style.left = `${offset.left}px`;
imposter.style.zIndex = 2147483646;
if (element.nodeName === 'TEXTAREA' && styleProps.overflow === 'visible') {
imposter.style.overflow = 'auto';
}
document.body.appendChild(imposter);
imposter.scrollTop = element.scrollTop;
imposter.scrollLeft = element.scrollLeft;
}
function docImposterDestroy() {
for (const element of document.getElementsByClassName('yomichan-imposter')) {
element.parentNode.removeChild(element);
}
}
function docRangeFromPoint(point) {
const element = document.elementFromPoint(point.x, point.y);
if (element !== null) {
if (element.nodeName === 'IMG' || element.nodeName === 'BUTTON') {
return new TextSourceElement(element);
} else if (element.nodeName === 'INPUT' || element.nodeName === 'TEXTAREA') {
docImposterCreate(element);
}
}
if (!document.caretRangeFromPoint) {
document.caretRangeFromPoint = (x, y) => {
const position = document.caretPositionFromPoint(x,y);
if (position === null) {
return null;
}
const range = document.createRange();
range.setStart(position.offsetNode, position.offset);
range.setEnd(position.offsetNode, position.offset);
return range;
};
}
const range = document.caretRangeFromPoint(point.x, point.y);
if (range !== null) {
return new TextSourceRange(range);
}
return null;
}
function docSentenceExtract(source, extent) {
const quotesFwd = {'「': '」', '『': '』', "'": "'", '"': '"'};
const quotesBwd = {'」': '「', '』': '『', "'": "'", '"': '"'};
const terminators = '…。..?!';
const sourceLocal = source.clone();
const position = sourceLocal.setStartOffset(extent);
sourceLocal.setEndOffset(position + extent);
const content = sourceLocal.text();
let quoteStack = [];
let startPos = 0;
for (let i = position; i >= startPos; --i) {
const c = content[i];
if (c === '\n') {
startPos = i + 1;
break;
}
if (quoteStack.length === 0 && (terminators.includes(c) || c in quotesFwd)) {
startPos = i + 1;
break;
}
if (quoteStack.length > 0 && c === quoteStack[0]) {
quoteStack.pop();
} else if (c in quotesBwd) {
quoteStack = [quotesBwd[c]].concat(quoteStack);
}
}
quoteStack = [];
let endPos = content.length;
for (let i = position; i <= endPos; ++i) {
const c = content[i];
if (c === '\n') {
endPos = i + 1;
break;
}
if (quoteStack.length === 0) {
if (terminators.includes(c)) {
endPos = i + 1;
break;
}
else if (c in quotesBwd) {
endPos = i;
break;
}
}
if (quoteStack.length > 0 && c === quoteStack[0]) {
quoteStack.pop();
} else if (c in quotesFwd) {
quoteStack = [quotesFwd[c]].concat(quoteStack);
}
}
const text = content.substring(startPos, endPos);
const padding = text.length - text.replace(/^\s+/, '').length;
return {
text: text.trim(),
offset: position - startPos - padding
};
}

View File

@ -1,13 +1,13 @@
{ {
"manifest_version": 2, "manifest_version": 2,
"name": "Yomichan", "name": "Yomichan",
"version": "1.2.0", "version": "1.3.0",
"description": "Japanese dictionary with Anki integration", "description": "Japanese dictionary with Anki integration",
"icons": {"16": "mixed/img/icon16.png", "48": "mixed/img/icon48.png", "128": "mixed/img/icon128.png"}, "icons": {"16": "mixed/img/icon16.png", "48": "mixed/img/icon48.png", "128": "mixed/img/icon128.png"},
"browser_action": { "browser_action": {
"default_icon": {"19": "mixed/img/icon19.png", "38": "mixed/img/icon38.png"}, "default_icon": {"19": "mixed/img/icon19.png", "38": "mixed/img/icon38.png"},
"default_popup": "bg/popup.html" "default_popup": "bg/context.html"
}, },
"author": "Alex Yatskov", "author": "Alex Yatskov",
@ -15,17 +15,18 @@
"content_scripts": [{ "content_scripts": [{
"matches": ["http://*/*", "https://*/*", "file://*/*"], "matches": ["http://*/*", "https://*/*", "file://*/*"],
"js": [ "js": [
"fg/js/util.js", "fg/js/api.js",
"fg/js/source-range.js", "fg/js/document.js",
"fg/js/source-element.js",
"fg/js/popup.js", "fg/js/popup.js",
"fg/js/driver.js" "fg/js/source.js",
"fg/js/util.js",
"fg/js/frontend.js"
], ],
"css": ["fg/css/client.css"] "css": ["fg/css/client.css"]
}], }],
"minimum_chrome_version": "45.0.0.0", "minimum_chrome_version": "57.0.0.0",
"options_ui": { "options_ui": {
"page": "bg/options.html" "page": "bg/settings.html"
}, },
"permissions": [ "permissions": [
"<all_urls>", "<all_urls>",
@ -46,11 +47,11 @@
"description": "Open search window" "description": "Open search window"
} }
}, },
"web_accessible_resources": ["fg/frame.html"], "web_accessible_resources": ["fg/float.html"],
"applications": { "applications": {
"gecko": { "gecko": {
"id": "alex@foosoft.net", "id": "alex@foosoft.net",
"strict_min_version": "51.0" "strict_min_version": "52.0"
} }
} }
} }

View File

@ -42,7 +42,7 @@ hr {
right: 5px; right: 5px;
} }
#orphan { #error-orphaned {
display: none; display: none;
} }

BIN
ext/mixed/img/view-note.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 622 B

View File

@ -27,190 +27,67 @@ class Display {
this.sequence = 0; this.sequence = 0;
this.index = 0; this.index = 0;
this.audioCache = {}; this.audioCache = {};
this.responseCache = {};
$(document).keydown(this.onKeyDown.bind(this)); $(document).keydown(this.onKeyDown.bind(this));
} }
definitionAdd(definition, mode) { onError(error) {
throw 'override me'; throw 'override me';
} }
definitionsAddable(definitions, modes) { onSearchClear() {
throw 'override me'; throw 'override me';
} }
templateRender(template, data) { onSourceTermView(e) {
throw 'override me';
}
kanjiFind(character) {
throw 'override me';
}
handleError(error) {
throw 'override me';
}
clearSearch() {
throw 'override me';
}
showTermDefs(definitions, options, context) {
window.focus();
this.spinner.hide();
this.definitions = definitions;
this.options = options;
this.context = context;
const sequence = ++this.sequence;
const params = {
definitions,
addable: options.anki.enable,
grouped: options.general.groupResults,
playback: options.general.audioSource !== 'disabled',
debug: options.general.debugInfo
};
if (context) {
for (const definition of definitions) {
if (context.sentence) {
definition.cloze = clozeBuild(context.sentence, definition.source);
}
definition.url = context.url;
}
}
this.templateRender('terms.html', params).then(content => {
this.container.html(content);
this.entryScroll(context && context.index || 0);
$('.action-add-note').click(this.onAddNote.bind(this));
$('.action-play-audio').click(this.onPlayAudio.bind(this));
$('.kanji-link').click(this.onKanjiLookup.bind(this));
return this.adderButtonsUpdate(['term-kanji', 'term-kana'], sequence);
}).catch(this.handleError.bind(this));
}
showKanjiDefs(definitions, options, context) {
window.focus();
this.spinner.hide();
this.definitions = definitions;
this.options = options;
this.context = context;
const sequence = ++this.sequence;
const params = {
definitions,
source: context && context.source,
addable: options.anki.enable,
debug: options.general.debugInfo
};
if (context) {
for (const definition of definitions) {
if (context.sentence) {
definition.cloze = clozeBuild(context.sentence);
}
definition.url = context.url;
}
}
this.templateRender('kanji.html', params).then(content => {
this.container.html(content);
this.entryScroll(context && context.index || 0);
$('.action-add-note').click(this.onAddNote.bind(this));
$('.source-term').click(this.onSourceTerm.bind(this));
return this.adderButtonsUpdate(['kanji'], sequence);
}).catch(this.handleError.bind(this));
}
adderButtonsUpdate(modes, sequence) {
return this.definitionsAddable(this.definitions, modes).then(states => {
if (states === null || sequence !== this.sequence) {
return;
}
states.forEach((state, index) => {
for (const mode in state) {
const button = Display.adderButtonFind(index, mode);
if (state[mode]) {
button.removeClass('disabled');
} else {
button.addClass('disabled');
}
button.removeClass('pending');
}
});
});
}
entryScroll(index, smooth) {
index = Math.min(index, this.definitions.length - 1);
index = Math.max(index, 0);
$('.current').hide().eq(index).show();
const container = $('html,body').stop();
const entry = $('.entry').eq(index);
const target = index === 0 ? 0 : entry.offset().top;
if (smooth) {
container.animate({scrollTop: target}, 200);
} else {
container.scrollTop(target);
}
this.index = index;
}
onSourceTerm(e) {
e.preventDefault(); e.preventDefault();
this.sourceBack(); this.sourceTermView();
} }
onKanjiLookup(e) { async onKanjiLookup(e) {
e.preventDefault(); try {
e.preventDefault();
const link = $(e.target); const link = $(e.target);
const context = { const context = {
source: { source: {
definitions: this.definitions, definitions: this.definitions,
index: Display.entryIndexFind(link) index: Display.entryIndexFind(link)
}
};
if (this.context) {
context.sentence = this.context.sentence;
context.url = this.context.url;
} }
};
if (this.context) { const kanjiDefs = await apiKanjiFind(link.text());
context.sentence = this.context.sentence; this.kanjiShow(kanjiDefs, this.options, context);
context.url = this.context.url; } catch (e) {
this.onError(e);
} }
this.kanjiFind(link.text()).then(kanjiDefs => {
this.showKanjiDefs(kanjiDefs, this.options, context);
}).catch(this.handleError.bind(this));
} }
onPlayAudio(e) { onAudioPlay(e) {
e.preventDefault(); e.preventDefault();
const index = Display.entryIndexFind($(e.currentTarget)); const index = Display.entryIndexFind($(e.currentTarget));
this.audioPlay(this.definitions[index]); this.audioPlay(this.definitions[index]);
} }
onAddNote(e) { onNoteAdd(e) {
e.preventDefault(); e.preventDefault();
const link = $(e.currentTarget); const link = $(e.currentTarget);
const index = Display.entryIndexFind(link); const index = Display.entryIndexFind(link);
this.noteAdd(this.definitions[index], link.data('mode')); this.noteAdd(this.definitions[index], link.data('mode'));
} }
onNoteView(e) {
e.preventDefault();
const link = $(e.currentTarget);
const index = Display.entryIndexFind(link);
apiNoteView(link.data('noteId'));
}
onKeyDown(e) { onKeyDown(e) {
const noteTryAdd = mode => { const noteTryAdd = mode => {
const button = Display.adderButtonFind(this.index, mode); const button = Display.adderButtonFind(this.index, mode);
@ -219,57 +96,64 @@ class Display {
} }
}; };
const noteTryView = mode => {
const button = Display.viewerButtonFind(this.index);
if (button.length !== 0 && !button.hasClass('disabled')) {
apiNoteView(button.data('noteId'));
}
};
const handlers = { const handlers = {
27: /* escape */ () => { 27: /* escape */ () => {
this.clearSearch(); this.onSearchClear();
return true; return true;
}, },
33: /* page up */ () => { 33: /* page up */ () => {
if (e.altKey) { if (e.altKey) {
this.entryScroll(this.index - 3, true); this.entryScrollIntoView(this.index - 3, true);
return true; return true;
} }
}, },
34: /* page down */ () => { 34: /* page down */ () => {
if (e.altKey) { if (e.altKey) {
this.entryScroll(this.index + 3, true); this.entryScrollIntoView(this.index + 3, true);
return true; return true;
} }
}, },
35: /* end */ () => { 35: /* end */ () => {
if (e.altKey) { if (e.altKey) {
this.entryScroll(this.definitions.length - 1, true); this.entryScrollIntoView(this.definitions.length - 1, true);
return true; return true;
} }
}, },
36: /* home */ () => { 36: /* home */ () => {
if (e.altKey) { if (e.altKey) {
this.entryScroll(0, true); this.entryScrollIntoView(0, true);
return true; return true;
} }
}, },
38: /* up */ () => { 38: /* up */ () => {
if (e.altKey) { if (e.altKey) {
this.entryScroll(this.index - 1, true); this.entryScrollIntoView(this.index - 1, true);
return true; return true;
} }
}, },
40: /* down */ () => { 40: /* down */ () => {
if (e.altKey) { if (e.altKey) {
this.entryScroll(this.index + 1, true); this.entryScrollIntoView(this.index + 1, true);
return true; return true;
} }
}, },
66: /* b */ () => { 66: /* b */ () => {
if (e.altKey) { if (e.altKey) {
this.sourceBack(); this.sourceTermView();
return true; return true;
} }
}, },
@ -303,6 +187,12 @@ class Display {
return true; return true;
} }
},
86: /* v */ () => {
if (e.altKey) {
noteTryView();
}
} }
}; };
@ -312,7 +202,133 @@ class Display {
} }
} }
sourceBack() { async termsShow(definitions, options, context) {
try {
window.focus();
this.definitions = definitions;
this.options = options;
this.context = context;
const sequence = ++this.sequence;
const params = {
definitions,
addable: options.anki.enable,
grouped: options.general.groupResults,
playback: options.general.audioSource !== 'disabled',
debug: options.general.debugInfo
};
if (context) {
for (const definition of definitions) {
if (context.sentence) {
definition.cloze = Display.clozeBuild(context.sentence, definition.source);
}
definition.url = context.url;
}
}
const content = await apiTemplateRender('terms.html', params);
this.container.html(content);
this.entryScrollIntoView(context && context.index || 0);
$('.action-add-note').click(this.onNoteAdd.bind(this));
$('.action-view-note').click(this.onNoteView.bind(this));
$('.action-play-audio').click(this.onAudioPlay.bind(this));
$('.kanji-link').click(this.onKanjiLookup.bind(this));
await this.adderButtonUpdate(['term-kanji', 'term-kana'], sequence);
} catch (e) {
this.onError(e);
}
}
async kanjiShow(definitions, options, context) {
try {
window.focus();
this.definitions = definitions;
this.options = options;
this.context = context;
const sequence = ++this.sequence;
const params = {
definitions,
source: context && context.source,
addable: options.anki.enable,
debug: options.general.debugInfo
};
if (context) {
for (const definition of definitions) {
if (context.sentence) {
definition.cloze = Display.clozeBuild(context.sentence);
}
definition.url = context.url;
}
}
const content = await apiTemplateRender('kanji.html', params);
this.container.html(content);
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);
} catch (e) {
this.onError(e);
}
}
async adderButtonUpdate(modes, sequence) {
try {
const states = await apiDefinitionsAddable(this.definitions, modes);
if (!states || sequence !== this.sequence) {
return;
}
for (let i = 0; i < states.length; ++i) {
const state = states[i];
for (const mode in state) {
const button = Display.adderButtonFind(i, mode);
if (state[mode]) {
button.removeClass('disabled');
} else {
button.addClass('disabled');
}
button.removeClass('pending');
}
}
} catch (e) {
this.onError(e);
}
}
entryScrollIntoView(index, smooth) {
index = Math.min(index, this.definitions.length - 1);
index = Math.max(index, 0);
$('.current').hide().eq(index).show();
const container = $('html,body').stop();
const entry = $('.entry').eq(index);
const target = index === 0 ? 0 : entry.offset().top;
if (smooth) {
container.animate({scrollTop: target}, 200);
} else {
container.scrollTop(target);
}
this.index = index;
}
sourceTermView() {
if (this.context && this.context.source) { if (this.context && this.context.source) {
const context = { const context = {
url: this.context.source.url, url: this.context.source.url,
@ -320,34 +336,42 @@ class Display {
index: this.context.source.index index: this.context.source.index
}; };
this.showTermDefs(this.context.source.definitions, this.options, context); this.termsShow(this.context.source.definitions, this.options, context);
} }
} }
noteAdd(definition, mode) { async noteAdd(definition, mode) {
this.spinner.show(); try {
return this.definitionAdd(definition, mode).then(success => { this.spinner.show();
if (success) {
const noteId = await apiDefinitionAdd(definition, mode);
if (noteId) {
const index = this.definitions.indexOf(definition); const index = this.definitions.indexOf(definition);
Display.adderButtonFind(index, mode).addClass('disabled'); Display.adderButtonFind(index, mode).addClass('disabled');
Display.viewerButtonFind(index).removeClass('pending disabled').data('noteId', noteId);
} else { } else {
this.handleError('note could not be added'); throw 'note could note be added';
} }
}).catch(this.handleError.bind(this)).then(() => this.spinner.hide()); } catch (e) {
this.onError(e);
} finally {
this.spinner.hide();
}
} }
audioPlay(definition) { async audioPlay(definition) {
this.spinner.show(); try {
this.spinner.show();
for (const key in this.audioCache) { let url = await apiAudioGetUrl(definition, this.options.general.audioSource);
this.audioCache[key].pause();
}
audioBuildUrl(definition, this.options.general.audioSource, this.responseCache).then(url => {
if (!url) { if (!url) {
url = '/mixed/mp3/button.mp3'; url = '/mixed/mp3/button.mp3';
} }
for (const key in this.audioCache) {
this.audioCache[key].pause();
}
let audio = this.audioCache[url]; let audio = this.audioCache[url];
if (audio) { if (audio) {
audio.currentTime = 0; audio.currentTime = 0;
@ -365,7 +389,25 @@ class Display {
audio.play(); audio.play();
}; };
} }
}).catch(this.handleError.bind(this)).then(() => this.spinner.hide()); } catch (e) {
this.onError(e);
} finally {
this.spinner.hide();
}
}
static clozeBuild(sentence, source) {
const result = {
sentence: sentence.text.trim()
};
if (source) {
result.prefix = sentence.text.substring(0, sentence.offset).trim();
result.body = source.trim();
result.suffix = sentence.text.substring(sentence.offset + source.length).trim();
}
return result;
} }
static entryIndexFind(element) { static entryIndexFind(element) {
@ -375,4 +417,8 @@ class Display {
static adderButtonFind(index, mode) { static adderButtonFind(index, mode) {
return $('.entry').eq(index).find(`.action-add-note[data-mode="${mode}"]`); return $('.entry').eq(index).find(`.action-add-note[data-mode="${mode}"]`);
} }
static viewerButtonFind(index) {
return $('.entry').eq(index).find('.action-view-note');
}
} }

View File

@ -17,24 +17,24 @@
*/ */
class AnkiNull { function jpIsKanji(c) {
addNote(note) { const code = c.charCodeAt(0);
return Promise.reject('unsupported action'); return code >= 0x4e00 && code < 0x9fb0 || code >= 0x3400 && code < 0x4dc0;
} }
canAddNotes(notes) { function jpIsKana(c) {
return Promise.resolve([]); return wanakana.isKana(c);
} }
getDeckNames() { function jpKatakanaToHiragana(text) {
return Promise.resolve([]); let result = '';
} for (const c of text) {
if (wanakana.isKatakana(c)) {
getModelNames() { result += wanakana.toHiragana(c);
return Promise.resolve([]); } else {
} result += c;
}
getModelFieldNames(modelName) { }
return Promise.resolve([]);
} return result;
} }

File diff suppressed because one or more lines are too long

View File

@ -1,13 +1,17 @@
{{#*inline "glossary-single"}} {{#*inline "glossary-single"}}
{{~#if html~}} {{~#if html~}}
{{~#if tags~}}<i>({{#each tags}}{{name}}{{#unless @last}}, {{/unless}}{{/each}})</i> {{/if~}} {{~#unless brief~}}
{{~#if tags~}}<i>({{#each tags}}{{name}}{{#unless @last}}, {{/unless}}{{/each}})</i> {{/if~}}
{{~/unless~}}
{{~#if glossary.[1]~}} {{~#if glossary.[1]~}}
<ul>{{#each glossary}}<li>{{#multiLine}}{{.}}{{/multiLine}}</li>{{/each}}</ul> <ul>{{#each glossary}}<li>{{#multiLine}}{{.}}{{/multiLine}}</li>{{/each}}</ul>
{{~else~}} {{~else~}}
{{~#multiLine}}{{glossary.[0]}}{{/multiLine~}} {{~#multiLine}}{{glossary.[0]}}{{/multiLine~}}
{{~/if~}} {{~/if~}}
{{~else~}} {{~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]~}} {{~#if glossary.[1]~}}
{{#each glossary}}{{.}}{{#unless @last}}, {{/unless}}{{/each}} {{#each glossary}}{{.}}{{#unless @last}}, {{/unless}}{{/each}}
{{~else~}} {{~else~}}
@ -58,18 +62,22 @@
{{~else~}} {{~else~}}
{{~#if group~}} {{~#if group~}}
{{~#if definition.definitions.[1]~}} {{~#if definition.definitions.[1]~}}
{{~#if html}}<ol>{{#each definition.definitions}}<li>{{> glossary-single html=../html}}</li>{{/each}}</ol> {{~#if html}}<ol>{{#each definition.definitions}}<li>{{> glossary-single html=../html brief=../brief}}</li>{{/each}}</ol>
{{~else}}{{#each definition.definitions}} * {{> glossary-single html=../html}}{{/each}}{{/if~}} {{~else}}{{#each definition.definitions}} * {{> glossary-single html=../html brief=../brief}}{{/each}}{{/if~}}
{{~else~}} {{~else~}}
{{~> glossary-single definition.definitions.[0] html=html~}} {{~> glossary-single definition.definitions.[0] html=html brief=brief~}}
{{~/if~}} {{~/if~}}
{{~else~}} {{~else~}}
{{~> glossary-single definition html=html~}} {{~> glossary-single definition html=html brief=brief~}}
{{~/if~}} {{~/if~}}
{{~/if~}} {{~/if~}}
{{~#if html}}</div>{{/if~}} {{~#if html}}</div>{{/if~}}
{{/inline}} {{/inline}}
{{#*inline "glossary-brief"}}
{{~> glossary brief=true ~}}
{{/inline}}
{{#*inline "kunyomi"}} {{#*inline "kunyomi"}}
{{~#each definition.kunyomi}}{{.}}{{#unless @last}}, {{/unless}}{{/each~}} {{~#each definition.kunyomi}}{{.}}{{#unless @last}}, {{/unless}}{{/each~}}
{{/inline}} {{/inline}}

View File

@ -1,13 +1,14 @@
{{#*inline "kanji"}} {{#*inline "kanji"}}
<div class="entry" data-type="kanji"> <div class="entry" data-type="kanji">
<div class="actions"> <div class="actions">
<img src="/mixed/img/entry-current.png" class="current" title="Current entry (Alt + Up/Down/Home/End/PgUp/PgDn)" alt>
{{#if addable}} {{#if addable}}
<a href="#" class="action-view-note pending disabled"><img src="/mixed/img/view-note.png" title="View added note (Alt + V)" alt></a>
<a href="#" class="action-add-note pending disabled" data-mode="kanji"><img src="/mixed/img/add-kanji.png" title="Add Kanji (Alt + K)" alt></a> <a href="#" class="action-add-note pending disabled" data-mode="kanji"><img src="/mixed/img/add-kanji.png" title="Add Kanji (Alt + K)" alt></a>
{{/if}} {{/if}}
{{#if source}} {{#if source}}
<a href="#" class="source-term"><img src="/mixed/img/source-term.png" title="Source term (Alt + B)" alt></a> <a href="#" class="source-term"><img src="/mixed/img/source-term.png" title="Source term (Alt + B)" alt></a>
{{/if}} {{/if}}
<img src="/mixed/img/entry-current.png" class="current" title="Current entry (Alt + Up/Down/Home/End/PgUp/PgDn)" alt>
</div> </div>
<div class="glyph">{{character}}</div> <div class="glyph">{{character}}</div>

View File

@ -20,14 +20,15 @@
{{#*inline "term"}} {{#*inline "term"}}
<div class="entry" data-type="term"> <div class="entry" data-type="term">
<div class="actions"> <div class="actions">
<img src="/mixed/img/entry-current.png" class="current" title="Current entry (Alt + Up/Down/Home/End/PgUp/PgDn)" alt>
{{#if addable}} {{#if addable}}
<a href="#" class="action-view-note pending disabled"><img src="/mixed/img/view-note.png" title="View added note (Alt + V)" alt></a>
<a href="#" class="action-add-note pending disabled" data-mode="term-kanji"><img src="/mixed/img/add-term-kanji.png" title="Add expression (Alt + E)" alt></a> <a href="#" class="action-add-note pending disabled" data-mode="term-kanji"><img src="/mixed/img/add-term-kanji.png" title="Add expression (Alt + E)" alt></a>
<a href="#" class="action-add-note pending disabled" data-mode="term-kana"><img src="/mixed/img/add-term-kana.png" title="Add reading (Alt + R)" alt></a> <a href="#" class="action-add-note pending disabled" data-mode="term-kana"><img src="/mixed/img/add-term-kana.png" title="Add reading (Alt + R)" alt></a>
{{/if}} {{/if}}
{{#if playback}} {{#if playback}}
<a href="#" class="action-play-audio"><img src="/mixed/img/play-audio.png" title="Play audio (Alt + P)" alt></a> <a href="#" class="action-play-audio"><img src="/mixed/img/play-audio.png" title="Play audio (Alt + P)" alt></a>
{{/if}} {{/if}}
<img src="/mixed/img/entry-current.png" class="current" title="Current entry (Alt + Up/Down/Home/End/PgUp/PgDn)" alt>
</div> </div>
{{#if reading}} {{#if reading}}