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