Use let
instead of const
in for loops.
This commit is contained in:
parent
caf0678832
commit
ad61722130
@ -26,12 +26,12 @@ class Deinflection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
validate(validator) {
|
validate(validator) {
|
||||||
for (const tags of validator(this.term)) {
|
for (let tags of validator(this.term)) {
|
||||||
if (this.tags.length === 0) {
|
if (this.tags.length === 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const tag of this.tags) {
|
for (let tag of this.tags) {
|
||||||
if (tags.indexOf(tag) !== -1) {
|
if (tags.indexOf(tag) !== -1) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -47,11 +47,11 @@ class Deinflection {
|
|||||||
this.children.push(child);
|
this.children.push(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const rule in rules) {
|
for (let rule in rules) {
|
||||||
const variants = rules[rule];
|
const variants = rules[rule];
|
||||||
for (const v of variants) {
|
for (let v of variants) {
|
||||||
let allowed = this.tags.length === 0;
|
let allowed = this.tags.length === 0;
|
||||||
for (const tag of this.tags) {
|
for (let tag of this.tags) {
|
||||||
//
|
//
|
||||||
// TODO: Handle addons through tags.json or rules.json
|
// TODO: Handle addons through tags.json or rules.json
|
||||||
//
|
//
|
||||||
@ -83,8 +83,8 @@ class Deinflection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const paths = [];
|
const paths = [];
|
||||||
for (const child of this.children) {
|
for (let child of this.children) {
|
||||||
for (const path of child.gather()) {
|
for (let path of child.gather()) {
|
||||||
if (this.rule.length > 0) {
|
if (this.rule.length > 0) {
|
||||||
path.rules.push(this.rule);
|
path.rules.push(this.rule);
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ class Dictionary {
|
|||||||
findTerm(term) {
|
findTerm(term) {
|
||||||
let results = [];
|
let results = [];
|
||||||
|
|
||||||
for (const name in this.termDicts) {
|
for (let name in this.termDicts) {
|
||||||
const dict = this.termDicts[name];
|
const dict = this.termDicts[name];
|
||||||
const indices = dict.indices[term] || [];
|
const indices = dict.indices[term] || [];
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ class Dictionary {
|
|||||||
// TODO: Handle addons through data.
|
// TODO: Handle addons through data.
|
||||||
//
|
//
|
||||||
|
|
||||||
for (const tag of tags) {
|
for (let tag of tags) {
|
||||||
if (tag.startsWith('v5') && tag !== 'v5') {
|
if (tag.startsWith('v5') && tag !== 'v5') {
|
||||||
addons.push('v5');
|
addons.push('v5');
|
||||||
} else if (tag.startsWith('vs-')) {
|
} else if (tag.startsWith('vs-')) {
|
||||||
@ -74,7 +74,7 @@ class Dictionary {
|
|||||||
findKanji(kanji) {
|
findKanji(kanji) {
|
||||||
const results = [];
|
const results = [];
|
||||||
|
|
||||||
for (const name in this.kanjiDicts) {
|
for (let name in this.kanjiDicts) {
|
||||||
const def = this.kanjiDicts[name][kanji];
|
const def = this.kanjiDicts[name][kanji];
|
||||||
if (def) {
|
if (def) {
|
||||||
const [k, o, g] = def;
|
const [k, o, g] = def;
|
||||||
|
@ -33,7 +33,7 @@ function sanitizeOptions(options) {
|
|||||||
ankiKanjiFields: {}
|
ankiKanjiFields: {}
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const key in defaults) {
|
for (let key in defaults) {
|
||||||
if (!options.hasOwnProperty(key)) {
|
if (!options.hasOwnProperty(key)) {
|
||||||
options[key] = defaults[key];
|
options[key] = defaults[key];
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ class Translator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const pendingLoads = [];
|
const pendingLoads = [];
|
||||||
for (const key of files) {
|
for (let key of files) {
|
||||||
pendingLoads.push(key);
|
pendingLoads.push(key);
|
||||||
Translator.loadData(this.paths[key], (response) => {
|
Translator.loadData(this.paths[key], (response) => {
|
||||||
switch (key) {
|
switch (key) {
|
||||||
@ -80,7 +80,7 @@ class Translator {
|
|||||||
|
|
||||||
const dfs = this.deinflector.deinflect(term, t => {
|
const dfs = this.deinflector.deinflect(term, t => {
|
||||||
const tags = [];
|
const tags = [];
|
||||||
for (const d of this.dictionary.findTerm(t)) {
|
for (let d of this.dictionary.findTerm(t)) {
|
||||||
tags.push(d.tags);
|
tags.push(d.tags);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,13 +91,13 @@ class Translator {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const df of dfs) {
|
for (let df of dfs) {
|
||||||
this.processTerm(groups, df.source, df.tags, df.rules, df.root);
|
this.processTerm(groups, df.source, df.tags, df.rules, df.root);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let definitions = [];
|
let definitions = [];
|
||||||
for (const key in groups) {
|
for (let key in groups) {
|
||||||
definitions.push(groups[key]);
|
definitions.push(groups[key]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,7 +130,7 @@ class Translator {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let length = 0;
|
let length = 0;
|
||||||
for (const result of definitions) {
|
for (let result of definitions) {
|
||||||
length = Math.max(length, result.source.length);
|
length = Math.max(length, result.source.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,7 +141,7 @@ class Translator {
|
|||||||
let definitions = [];
|
let definitions = [];
|
||||||
const processed = {};
|
const processed = {};
|
||||||
|
|
||||||
for (const c of text) {
|
for (let c of text) {
|
||||||
if (!processed[c]) {
|
if (!processed[c]) {
|
||||||
definitions = definitions.concat(this.dictionary.findKanji(c));
|
definitions = definitions.concat(this.dictionary.findKanji(c));
|
||||||
processed[c] = true;
|
processed[c] = true;
|
||||||
@ -152,13 +152,13 @@ class Translator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
processTerm(groups, source, tags, rules=[], root='') {
|
processTerm(groups, source, tags, rules=[], root='') {
|
||||||
for (const entry of this.dictionary.findTerm(root)) {
|
for (let entry of this.dictionary.findTerm(root)) {
|
||||||
if (entry.id in groups) {
|
if (entry.id in groups) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let matched = tags.length == 0;
|
let matched = tags.length == 0;
|
||||||
for (const tag of tags) {
|
for (let tag of tags) {
|
||||||
if (entry.tags.indexOf(tag) !== -1) {
|
if (entry.tags.indexOf(tag) !== -1) {
|
||||||
matched = true;
|
matched = true;
|
||||||
break;
|
break;
|
||||||
@ -167,7 +167,7 @@ class Translator {
|
|||||||
|
|
||||||
let popular = false;
|
let popular = false;
|
||||||
let tagItems = [];
|
let tagItems = [];
|
||||||
for (const tag of entry.tags) {
|
for (let tag of entry.tags) {
|
||||||
const tagItem = this.tags[tag];
|
const tagItem = this.tags[tag];
|
||||||
if (tagItem && entry.addons.indexOf(tag) === -1) {
|
if (tagItem && entry.addons.indexOf(tag) === -1) {
|
||||||
tagItems.push({
|
tagItems.push({
|
||||||
|
@ -22,7 +22,7 @@ class Yomichan {
|
|||||||
Handlebars.partials = Handlebars.templates;
|
Handlebars.partials = Handlebars.templates;
|
||||||
Handlebars.registerHelper('kanjiLinks', function(options) {
|
Handlebars.registerHelper('kanjiLinks', function(options) {
|
||||||
let result = '';
|
let result = '';
|
||||||
for (const c of options.fn(this)) {
|
for (let c of options.fn(this)) {
|
||||||
if (Translator.isKanji(c)) {
|
if (Translator.isKanji(c)) {
|
||||||
result += Handlebars.templates['kanji-link.html']({kanji: c}).trim();
|
result += Handlebars.templates['kanji-link.html']({kanji: c}).trim();
|
||||||
} else {
|
} else {
|
||||||
@ -111,7 +111,7 @@ class Yomichan {
|
|||||||
|
|
||||||
notifyTabs(name, value) {
|
notifyTabs(name, value) {
|
||||||
chrome.tabs.query({}, (tabs) => {
|
chrome.tabs.query({}, (tabs) => {
|
||||||
for (const tab of tabs) {
|
for (let tab of tabs) {
|
||||||
chrome.tabs.sendMessage(tab.id, {name, value}, () => null);
|
chrome.tabs.sendMessage(tab.id, {name, value}, () => null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -155,7 +155,7 @@ class Yomichan {
|
|||||||
formatField(field, definition, mode) {
|
formatField(field, definition, mode) {
|
||||||
const supported = ['character', 'expression', 'glossary', 'kunyomi', 'onyomi', 'reading'];
|
const supported = ['character', 'expression', 'glossary', 'kunyomi', 'onyomi', 'reading'];
|
||||||
|
|
||||||
for (const key in definition) {
|
for (let key in definition) {
|
||||||
if (supported.indexOf(key) === -1) {
|
if (supported.indexOf(key) === -1) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -175,7 +175,7 @@ class Yomichan {
|
|||||||
|
|
||||||
if (mode !== 'kanji' && key === 'glossary') {
|
if (mode !== 'kanji' && key === 'glossary') {
|
||||||
value = '<ol>';
|
value = '<ol>';
|
||||||
for (const gloss of definition.glossary) {
|
for (let gloss of definition.glossary) {
|
||||||
value += `<li>${gloss}</li>`;
|
value += `<li>${gloss}</li>`;
|
||||||
}
|
}
|
||||||
value += '</ol>';
|
value += '</ol>';
|
||||||
@ -201,7 +201,7 @@ class Yomichan {
|
|||||||
note.modelName = this.options.ankiVocabModel;
|
note.modelName = this.options.ankiVocabModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const name in fields) {
|
for (let name in fields) {
|
||||||
note.fields[name] = this.formatField(fields[name], definition, mode);
|
note.fields[name] = this.formatField(fields[name], definition, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,8 +215,8 @@ class Yomichan {
|
|||||||
|
|
||||||
api_canAddDefinitions({definitions, modes, callback}) {
|
api_canAddDefinitions({definitions, modes, callback}) {
|
||||||
let notes = [];
|
let notes = [];
|
||||||
for (const definition of definitions) {
|
for (let definition of definitions) {
|
||||||
for (const mode of modes) {
|
for (let mode of modes) {
|
||||||
notes.push(this.formatNote(definition, mode));
|
notes.push(this.formatNote(definition, mode));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
|
|
||||||
function registerKanjiLinks() {
|
function registerKanjiLinks() {
|
||||||
for (const link of [].slice.call(document.getElementsByClassName('kanji-link'))) {
|
for (let link of [].slice.call(document.getElementsByClassName('kanji-link'))) {
|
||||||
link.addEventListener('click', (e) => {
|
link.addEventListener('click', (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
window.parent.postMessage({action: 'displayKanji', params: e.target.innerHTML}, '*');
|
window.parent.postMessage({action: 'displayKanji', params: e.target.innerHTML}, '*');
|
||||||
@ -27,7 +27,7 @@ function registerKanjiLinks() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function registerAddNoteLinks() {
|
function registerAddNoteLinks() {
|
||||||
for (const link of [].slice.call(document.getElementsByClassName('action-add-note'))) {
|
for (let link of [].slice.call(document.getElementsByClassName('action-add-note'))) {
|
||||||
link.addEventListener('click', (e) => {
|
link.addEventListener('click', (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const ds = e.currentTarget.dataset;
|
const ds = e.currentTarget.dataset;
|
||||||
@ -37,7 +37,7 @@ function registerAddNoteLinks() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function registerPronounceLinks() {
|
function registerPronounceLinks() {
|
||||||
for (const link of [].slice.call(document.getElementsByClassName('action-pronounce'))) {
|
for (let link of [].slice.call(document.getElementsByClassName('action-pronounce'))) {
|
||||||
link.addEventListener('click', (e) => {
|
link.addEventListener('click', (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const ds = e.currentTarget.dataset;
|
const ds = e.currentTarget.dataset;
|
||||||
@ -60,7 +60,7 @@ function onMessage(e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function api_setActionState({index, state, sequence}) {
|
function api_setActionState({index, state, sequence}) {
|
||||||
for (const mode in state) {
|
for (let mode in state) {
|
||||||
const matches = document.querySelectorAll(`.action-bar[data-sequence="${sequence}"] .action-add-note[data-index="${index}"][data-mode="${mode}"]`);
|
const matches = document.querySelectorAll(`.action-bar[data-sequence="${sequence}"] .action-add-note[data-index="${index}"][data-mode="${mode}"]`);
|
||||||
if (matches.length === 0) {
|
if (matches.length === 0) {
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user