Cleanup
This commit is contained in:
parent
4995135657
commit
d479107eb5
@ -89,7 +89,7 @@ templates['kanji-list.html'] = template({"1":function(container,depth0,helpers,p
|
|||||||
var stack1;
|
var stack1;
|
||||||
|
|
||||||
return ((stack1 = container.invokePartial(partials["header.html"],depth0,{"name":"header.html","data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "")
|
return ((stack1 = container.invokePartial(partials["header.html"],depth0,{"name":"header.html","data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "")
|
||||||
+ ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.defs : depth0),{"name":"each","hash":{},"fn":container.program(1, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "")
|
+ ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.definitions : depth0),{"name":"each","hash":{},"fn":container.program(1, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "")
|
||||||
+ ((stack1 = container.invokePartial(partials["footer.html"],depth0,{"name":"footer.html","data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "");
|
+ ((stack1 = container.invokePartial(partials["footer.html"],depth0,{"name":"footer.html","data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "");
|
||||||
},"usePartial":true,"useData":true,"useDepths":true});
|
},"usePartial":true,"useData":true,"useDepths":true});
|
||||||
templates['term.html'] = template({"1":function(container,depth0,helpers,partials,data,blockParams,depths) {
|
templates['term.html'] = template({"1":function(container,depth0,helpers,partials,data,blockParams,depths) {
|
||||||
@ -101,17 +101,17 @@ templates['term.html'] = template({"1":function(container,depth0,helpers,partial
|
|||||||
|
|
||||||
return " <div class=\"action-bar\">\n <a href=\"#\" title=\"Add term as expression\" class=\"action-link disabled\" data-sequence=\""
|
return " <div class=\"action-bar\">\n <a href=\"#\" title=\"Add term as expression\" class=\"action-link disabled\" data-sequence=\""
|
||||||
+ alias2(alias1((depths[1] != null ? depths[1].sequence : depths[1]), depth0))
|
+ alias2(alias1((depths[1] != null ? depths[1].sequence : depths[1]), depth0))
|
||||||
+ "\" data-mode=\"vocabExp\" data-index=\""
|
+ "\" data-mode=\"vocab_kanji\" data-index=\""
|
||||||
+ alias2(((helper = (helper = helpers.index || (data && data.index)) != null ? helper : alias4),(typeof helper === alias5 ? helper.call(alias3,{"name":"index","hash":{},"data":data}) : helper)))
|
+ alias2(((helper = (helper = helpers.index || (data && data.index)) != null ? helper : alias4),(typeof helper === alias5 ? helper.call(alias3,{"name":"index","hash":{},"data":data}) : helper)))
|
||||||
+ "\"><img src=\""
|
+ "\"><img src=\""
|
||||||
+ alias2(alias1((depths[1] != null ? depths[1].root : depths[1]), depth0))
|
+ alias2(alias1((depths[1] != null ? depths[1].root : depths[1]), depth0))
|
||||||
+ "/img/add_expression.png\"></a>\n <a href=\"#\" title=\"Add term as reading\" class=\"action-link disabled\" data-sequence=\""
|
+ "/img/add_vocab_kanji.png\"></a>\n <a href=\"#\" title=\"Add term as reading\" class=\"action-link disabled\" data-sequence=\""
|
||||||
+ alias2(alias1((depths[1] != null ? depths[1].sequence : depths[1]), depth0))
|
+ alias2(alias1((depths[1] != null ? depths[1].sequence : depths[1]), depth0))
|
||||||
+ "\" data-mode=\"vocabReading\" data-index=\""
|
+ "\" data-mode=\"vocab_kana\" data-index=\""
|
||||||
+ alias2(((helper = (helper = helpers.index || (data && data.index)) != null ? helper : alias4),(typeof helper === alias5 ? helper.call(alias3,{"name":"index","hash":{},"data":data}) : helper)))
|
+ alias2(((helper = (helper = helpers.index || (data && data.index)) != null ? helper : alias4),(typeof helper === alias5 ? helper.call(alias3,{"name":"index","hash":{},"data":data}) : helper)))
|
||||||
+ "\"><img src=\""
|
+ "\"><img src=\""
|
||||||
+ alias2(alias1((depths[1] != null ? depths[1].root : depths[1]), depth0))
|
+ alias2(alias1((depths[1] != null ? depths[1].root : depths[1]), depth0))
|
||||||
+ "/img/add_reading.png\"></a>\n </div>\n";
|
+ "/img/add_vocab_kana.png\"></a>\n </div>\n";
|
||||||
},"4":function(container,depth0,helpers,partials,data) {
|
},"4":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 : {}, alias2=helpers.helperMissing, alias3="function", buffer =
|
||||||
" <div class=\"term-expression\"><ruby>";
|
" <div class=\"term-expression\"><ruby>";
|
||||||
@ -191,7 +191,7 @@ templates['term-list.html'] = template({"1":function(container,depth0,helpers,pa
|
|||||||
var stack1;
|
var stack1;
|
||||||
|
|
||||||
return ((stack1 = container.invokePartial(partials["header.html"],depth0,{"name":"header.html","data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "")
|
return ((stack1 = container.invokePartial(partials["header.html"],depth0,{"name":"header.html","data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "")
|
||||||
+ ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.defs : depth0),{"name":"each","hash":{},"fn":container.program(1, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "")
|
+ ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.definitions : depth0),{"name":"each","hash":{},"fn":container.program(1, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "")
|
||||||
+ ((stack1 = container.invokePartial(partials["footer.html"],depth0,{"name":"footer.html","data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "");
|
+ ((stack1 = container.invokePartial(partials["footer.html"],depth0,{"name":"footer.html","data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "");
|
||||||
},"usePartial":true,"useData":true,"useDepths":true});
|
},"usePartial":true,"useData":true,"useDepths":true});
|
||||||
})();
|
})();
|
@ -99,6 +99,14 @@ class Yomichan {
|
|||||||
this.notifyTabs('options', this.options);
|
this.notifyTabs('options', this.options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
notifyTabs(name, value) {
|
||||||
|
chrome.tabs.query({}, (tabs) => {
|
||||||
|
for (const tab of tabs) {
|
||||||
|
chrome.tabs.sendMessage(tab.id, {name, value}, () => null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
ankiInvoke(action, params, pool, callback) {
|
ankiInvoke(action, params, pool, callback) {
|
||||||
if (this.options.enableAnkiConnect) {
|
if (this.options.enableAnkiConnect) {
|
||||||
if (pool !== null && this.asyncPools.hasOwnProperty(pool)) {
|
if (pool !== null && this.asyncPools.hasOwnProperty(pool)) {
|
||||||
@ -165,26 +173,18 @@ class Yomichan {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const name in fields) {
|
for (const name in fields) {
|
||||||
note.fields[name] = this.formatField(fields[name], definition, mode === 'vocabReading');
|
note.fields[name] = this.formatField(fields[name], definition, mode === 'vocab_kana');
|
||||||
}
|
}
|
||||||
|
|
||||||
return note;
|
return note;
|
||||||
}
|
}
|
||||||
|
|
||||||
notifyTabs(name, value) {
|
api_addDefinition({definition, mode, callback}) {
|
||||||
chrome.tabs.query({}, (tabs) => {
|
|
||||||
for (const tab of tabs) {
|
|
||||||
chrome.tabs.sendMessage(tab.id, {name, value}, () => null);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
api_addNote({definition, mode, callback}) {
|
|
||||||
const note = this.formatNote(definition, mode);
|
const note = this.formatNote(definition, mode);
|
||||||
this.ankiInvoke('addNote', {note}, null, callback);
|
this.ankiInvoke('addNote', {note}, null, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
api_canAddNotes({definitions, modes, callback}) {
|
api_canAddDefinitions({definitions, modes, callback}) {
|
||||||
let notes = [];
|
let notes = [];
|
||||||
for (const definition of definitions) {
|
for (const definition of definitions) {
|
||||||
for (const mode of modes) {
|
for (const mode of modes) {
|
||||||
@ -194,6 +194,8 @@ class Yomichan {
|
|||||||
|
|
||||||
this.ankiInvoke('canAddNotes', {notes}, 'notes', (results) => {
|
this.ankiInvoke('canAddNotes', {notes}, 'notes', (results) => {
|
||||||
const states = [];
|
const states = [];
|
||||||
|
|
||||||
|
if (results !== null) {
|
||||||
for (let resultBase = 0; resultBase < results.length; resultBase += modes.length) {
|
for (let resultBase = 0; resultBase < results.length; resultBase += modes.length) {
|
||||||
const state = {};
|
const state = {};
|
||||||
for (let modeOffset = 0; modeOffset < modes.length; ++modeOffset) {
|
for (let modeOffset = 0; modeOffset < modes.length; ++modeOffset) {
|
||||||
@ -202,6 +204,7 @@ class Yomichan {
|
|||||||
|
|
||||||
states.push(state);
|
states.push(state);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
callback(states);
|
callback(states);
|
||||||
});
|
});
|
||||||
|
Before Width: | Height: | Size: 286 B After Width: | Height: | Size: 286 B |
Before Width: | Height: | Size: 733 B After Width: | Height: | Size: 733 B |
@ -41,10 +41,10 @@ function bgGetState(callback) {
|
|||||||
bgSendMessage('getState', {}, callback);
|
bgSendMessage('getState', {}, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
function bgCanAddNotes(definitions, modes, callback) {
|
function bgCanAddDefinitions(definitions, modes, callback) {
|
||||||
bgSendMessage('canAddNotes', {definitions, modes}, callback);
|
bgSendMessage('canAddDefinitions', {definitions, modes}, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
function bgAddNote(definition, mode, callback) {
|
function bgAddDefinition(definition, mode, callback) {
|
||||||
bgSendMessage('addNote', {definition, mode}, callback);
|
bgSendMessage('addDefinition', {definition, mode}, callback);
|
||||||
}
|
}
|
||||||
|
@ -106,13 +106,13 @@ class Client {
|
|||||||
range.setLength(length);
|
range.setLength(length);
|
||||||
|
|
||||||
bgRenderText(
|
bgRenderText(
|
||||||
{defs: definitions, root: this.fgRoot, options: this.options, sequence},
|
{definitions, root: this.fgRoot, options: this.options, sequence},
|
||||||
'term-list.html',
|
'term-list.html',
|
||||||
(content) => {
|
(content) => {
|
||||||
this.definitions = definitions;
|
this.definitions = definitions;
|
||||||
this.showPopup(range, content);
|
this.showPopup(range, content);
|
||||||
|
|
||||||
bgCanAddNotes(definitions, ['vocabExp', 'vocabReading'], (states) => {
|
bgCanAddDefinitions(definitions, ['vocab_kanji', 'vocab_kana'], (states) => {
|
||||||
if (states !== null) {
|
if (states !== null) {
|
||||||
states.forEach((state, index) => this.popup.sendMessage('setActionState', {index, state, sequence}));
|
states.forEach((state, index) => this.popup.sendMessage('setActionState', {index, state, sequence}));
|
||||||
}
|
}
|
||||||
@ -158,7 +158,7 @@ class Client {
|
|||||||
const state = {};
|
const state = {};
|
||||||
state[mode] = false;
|
state[mode] = false;
|
||||||
|
|
||||||
bgAddNote(this.definitions[index], mode, (success) => {
|
bgAddDefinition(this.definitions[index], mode, (success) => {
|
||||||
if (success) {
|
if (success) {
|
||||||
this.popup.sendMessage('setActionState', {index, state, sequence: this.sequence});
|
this.popup.sendMessage('setActionState', {index, state, sequence: this.sequence});
|
||||||
} else {
|
} else {
|
||||||
@ -171,13 +171,13 @@ class Client {
|
|||||||
bgFindKanji(kanji, (definitions) => {
|
bgFindKanji(kanji, (definitions) => {
|
||||||
const sequence = ++this.sequence;
|
const sequence = ++this.sequence;
|
||||||
bgRenderText(
|
bgRenderText(
|
||||||
{defs: definitions, root: this.fgRoot, options: this.options, sequence},
|
{definitions, root: this.fgRoot, options: this.options, sequence},
|
||||||
'kanji-list.html',
|
'kanji-list.html',
|
||||||
(content) => {
|
(content) => {
|
||||||
this.definitions = definitions;
|
this.definitions = definitions;
|
||||||
this.popup.setContent(content, definitions);
|
this.popup.setContent(content, definitions);
|
||||||
|
|
||||||
bgCanAddNotes(definitions, ['kanji'], (states) => {
|
bgCanAddDefinitions(definitions, ['kanji'], (states) => {
|
||||||
if (states !== null) {
|
if (states !== null) {
|
||||||
states.forEach((state, index) => this.popup.sendMessage('setActionState', {index, state, sequence}));
|
states.forEach((state, index) => this.popup.sendMessage('setActionState', {index, state, sequence}));
|
||||||
}
|
}
|
||||||
|
@ -19,9 +19,9 @@
|
|||||||
"permissions": ["storage"],
|
"permissions": ["storage"],
|
||||||
"web_accessible_resources": [
|
"web_accessible_resources": [
|
||||||
"fg/css/frame.css",
|
"fg/css/frame.css",
|
||||||
"fg/img/add_expression.png",
|
|
||||||
"fg/img/add_kanji.png",
|
"fg/img/add_kanji.png",
|
||||||
"fg/img/add_reading.png",
|
"fg/img/add_vocab_kana.png",
|
||||||
|
"fg/img/add_vocab_kanji.png",
|
||||||
"fg/js/frame.js",
|
"fg/js/frame.js",
|
||||||
"fg/ttf/kanji-stroke-orders.ttf",
|
"fg/ttf/kanji-stroke-orders.ttf",
|
||||||
"fg/ttf/vl-gothic-regular.ttf"
|
"fg/ttf/vl-gothic-regular.ttf"
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{{> header.html}}
|
{{> header.html}}
|
||||||
{{#each defs}}
|
{{#each definitions}}
|
||||||
{{> kanji.html root=../root options=../options sequence=../sequence}}
|
{{> kanji.html root=../root options=../options sequence=../sequence}}
|
||||||
{{/each}}
|
{{/each}}
|
||||||
{{> footer.html}}
|
{{> footer.html}}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{{> header.html}}
|
{{> header.html}}
|
||||||
{{#each defs}}
|
{{#each definitions}}
|
||||||
{{> term.html root=../root options=../options sequence=../sequence}}
|
{{> term.html root=../root options=../options sequence=../sequence}}
|
||||||
{{/each}}
|
{{/each}}
|
||||||
{{> footer.html}}
|
{{> footer.html}}
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
{{#with options}}
|
{{#with options}}
|
||||||
{{#if enableAnkiConnect}}
|
{{#if enableAnkiConnect}}
|
||||||
<div class="action-bar">
|
<div class="action-bar">
|
||||||
<a href="#" title="Add term as expression" class="action-link disabled" data-sequence="{{../sequence}}" data-mode="vocabExp" data-index="{{@index}}"><img src="{{../root}}/img/add_expression.png"></a>
|
<a href="#" title="Add term as expression" class="action-link disabled" data-sequence="{{../sequence}}" data-mode="vocab_kanji" data-index="{{@index}}"><img src="{{../root}}/img/add_vocab_kanji.png"></a>
|
||||||
<a href="#" title="Add term as reading" class="action-link disabled" data-sequence="{{../sequence}}" data-mode="vocabReading" data-index="{{@index}}"><img src="{{../root}}/img/add_reading.png"></a>
|
<a href="#" title="Add term as reading" class="action-link disabled" data-sequence="{{../sequence}}" data-mode="vocab_kana" data-index="{{@index}}"><img src="{{../root}}/img/add_vocab_kana.png"></a>
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{/with}}
|
{{/with}}
|
||||||
|
Loading…
Reference in New Issue
Block a user