From a2b66dc6cc3bd0d037c050eb49e270189a6617fb Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Tue, 7 Apr 2020 19:51:39 -0400 Subject: Rename apiForward to apiBroadcast --- ext/mixed/js/api.js | 4 ++-- ext/mixed/js/display.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'ext/mixed/js') diff --git a/ext/mixed/js/api.js b/ext/mixed/js/api.js index feec94df..d28e3ab6 100644 --- a/ext/mixed/js/api.js +++ b/ext/mixed/js/api.js @@ -81,8 +81,8 @@ function apiScreenshotGet(options) { return _apiInvoke('screenshotGet', {options}); } -function apiForward(action, params) { - return _apiInvoke('forward', {action, params}); +function apiBroadcast(action, params) { + return _apiInvoke('broadcast', {action, params}); } function apiFrameInformationGet() { diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 2f456c3e..710674b2 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -23,9 +23,9 @@ * DisplayGenerator * WindowScroll * apiAudioGetUri + * apiBroadcast * apiDefinitionAdd * apiDefinitionsAddable - * apiForward * apiKanjiFind * apiNoteView * apiOptionsGet @@ -855,7 +855,7 @@ class Display { } setPopupVisibleOverride(visible) { - return apiForward('popupSetVisibleOverride', {visible}); + return apiBroadcast('popupSetVisibleOverride', {visible}); } setSpinnerVisible(visible) { -- cgit v1.2.3 From 75c5c7aabc88379b9ba03ea7f0ccdb96bc000af0 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Thu, 9 Apr 2020 21:57:07 -0400 Subject: Remove data-multi assignments --- ext/mixed/js/display-generator.js | 2 -- 1 file changed, 2 deletions(-) (limited to 'ext/mixed/js') diff --git a/ext/mixed/js/display-generator.js b/ext/mixed/js/display-generator.js index f1122e3d..cd76000a 100644 --- a/ext/mixed/js/display-generator.js +++ b/ext/mixed/js/display-generator.js @@ -361,7 +361,6 @@ class DisplayGenerator { container.appendChild(node); } - container.dataset.multi = 'true'; container.dataset.count = `${exclusiveExpressions.length + exclusiveReadings.length}`; container.dataset.expressionCount = `${exclusiveExpressions.length}`; container.dataset.readingCount = `${exclusiveReadings.length}`; @@ -464,7 +463,6 @@ class DisplayGenerator { ++count; } - container.dataset.multi = `${multi}`; container.dataset.count = `${count}`; return count; -- cgit v1.2.3 From d7e4ff067e8a2c39963b93829cdfea867bde6bf9 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Thu, 9 Apr 2020 21:59:02 -0400 Subject: Remove statics --- ext/mixed/js/display-generator.js | 62 +++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 31 deletions(-) (limited to 'ext/mixed/js') diff --git a/ext/mixed/js/display-generator.js b/ext/mixed/js/display-generator.js index cd76000a..2f1154eb 100644 --- a/ext/mixed/js/display-generator.js +++ b/ext/mixed/js/display-generator.js @@ -44,7 +44,7 @@ class DisplayGenerator { const debugInfoContainer = node.querySelector('.debug-info'); const bodyContainer = node.querySelector('.term-entry-body'); - const pitches = DisplayGenerator._getPitchInfos(details); + const pitches = this._getPitchInfos(details); const pitchCount = pitches.reduce((i, v) => i + v[1].length, 0); const expressionMulti = Array.isArray(details.expressions); @@ -70,11 +70,11 @@ class DisplayGenerator { let expressions = details.expressions; expressions = Array.isArray(expressions) ? expressions.map((e) => [e, termTags]) : null; - DisplayGenerator._appendMultiple(expressionsContainer, this.createTermExpression.bind(this), expressions, [[details, termTags]]); - DisplayGenerator._appendMultiple(reasonsContainer, this.createTermReason.bind(this), details.reasons); - DisplayGenerator._appendMultiple(frequenciesContainer, this.createFrequencyTag.bind(this), details.frequencies); - DisplayGenerator._appendMultiple(pitchesContainer, this.createPitches.bind(this), pitches); - DisplayGenerator._appendMultiple(definitionsContainer, this.createTermDefinitionItem.bind(this), details.definitions, [details]); + this._appendMultiple(expressionsContainer, this.createTermExpression.bind(this), expressions, [[details, termTags]]); + this._appendMultiple(reasonsContainer, this.createTermReason.bind(this), details.reasons); + this._appendMultiple(frequenciesContainer, this.createFrequencyTag.bind(this), details.frequencies); + this._appendMultiple(pitchesContainer, this.createPitches.bind(this), pitches); + this._appendMultiple(definitionsContainer, this.createTermDefinitionItem.bind(this), details.definitions, [details]); if (debugInfoContainer !== null) { debugInfoContainer.textContent = JSON.stringify(details, null, 4); @@ -100,7 +100,7 @@ class DisplayGenerator { // This case should not occur furiganaSegments = [{text: details.expression, furigana: details.reading}]; } - DisplayGenerator._appendFurigana(expressionContainer, furiganaSegments, this._appendKanjiLinks.bind(this)); + this._appendFurigana(expressionContainer, furiganaSegments, this._appendKanjiLinks.bind(this)); } if (!Array.isArray(termTags)) { @@ -110,9 +110,9 @@ class DisplayGenerator { const searchQueries = [details.expression, details.reading] .filter((x) => !!x) .map((x) => ({query: x})); - DisplayGenerator._appendMultiple(tagContainer, this.createTag.bind(this), termTags); - DisplayGenerator._appendMultiple(tagContainer, this.createSearchTag.bind(this), searchQueries); - DisplayGenerator._appendMultiple(frequencyContainer, this.createFrequencyTag.bind(this), details.frequencies); + this._appendMultiple(tagContainer, this.createTag.bind(this), termTags); + this._appendMultiple(tagContainer, this.createSearchTag.bind(this), searchQueries); + this._appendMultiple(frequencyContainer, this.createFrequencyTag.bind(this), details.frequencies); return node; } @@ -134,9 +134,9 @@ class DisplayGenerator { node.dataset.dictionary = details.dictionary; - DisplayGenerator._appendMultiple(tagListContainer, this.createTag.bind(this), details.definitionTags); - DisplayGenerator._appendMultiple(onlyListContainer, this.createTermOnly.bind(this), details.only); - DisplayGenerator._appendMultiple(glossaryContainer, this.createTermGlossaryItem.bind(this), details.glossary); + this._appendMultiple(tagListContainer, this.createTag.bind(this), details.definitionTags); + this._appendMultiple(onlyListContainer, this.createTermOnly.bind(this), details.only); + this._appendMultiple(glossaryContainer, this.createTermGlossaryItem.bind(this), details.glossary); return node; } @@ -145,7 +145,7 @@ class DisplayGenerator { const node = this._templateHandler.instantiate('term-glossary-item'); const container = node.querySelector('.term-glossary'); if (container !== null) { - DisplayGenerator._appendMultilineText(container, glossary); + this._appendMultilineText(container, glossary); } return node; } @@ -184,11 +184,11 @@ class DisplayGenerator { glyphContainer.textContent = details.character; } - DisplayGenerator._appendMultiple(frequenciesContainer, this.createFrequencyTag.bind(this), details.frequencies); - DisplayGenerator._appendMultiple(tagContainer, this.createTag.bind(this), details.tags); - DisplayGenerator._appendMultiple(glossaryContainer, this.createKanjiGlossaryItem.bind(this), details.glossary); - DisplayGenerator._appendMultiple(chineseReadingsContainer, this.createKanjiReading.bind(this), details.onyomi); - DisplayGenerator._appendMultiple(japaneseReadingsContainer, this.createKanjiReading.bind(this), details.kunyomi); + this._appendMultiple(frequenciesContainer, this.createFrequencyTag.bind(this), details.frequencies); + this._appendMultiple(tagContainer, this.createTag.bind(this), details.tags); + this._appendMultiple(glossaryContainer, this.createKanjiGlossaryItem.bind(this), details.glossary); + this._appendMultiple(chineseReadingsContainer, this.createKanjiReading.bind(this), details.onyomi); + this._appendMultiple(japaneseReadingsContainer, this.createKanjiReading.bind(this), details.kunyomi); if (statisticsContainer !== null) { statisticsContainer.appendChild(this.createKanjiInfoTable(details.stats.misc)); @@ -214,7 +214,7 @@ class DisplayGenerator { const node = this._templateHandler.instantiate('kanji-glossary-item'); const container = node.querySelector('.kanji-glossary'); if (container !== null) { - DisplayGenerator._appendMultilineText(container, glossary); + this._appendMultilineText(container, glossary); } return node; } @@ -231,7 +231,7 @@ class DisplayGenerator { const container = node.querySelector('.kanji-info-table-body'); if (container !== null) { - const count = DisplayGenerator._appendMultiple(container, this.createKanjiInfoTableItem.bind(this), details); + const count = this._appendMultiple(container, this.createKanjiInfoTableItem.bind(this), details); if (count === 0) { const n = this.createKanjiInfoTableItemEmpty(); container.appendChild(n); @@ -298,7 +298,7 @@ class DisplayGenerator { node.querySelector('.term-pitch-accent-group-tag-list').appendChild(tag); const n = node.querySelector('.term-pitch-accent-list'); - DisplayGenerator._appendMultiple(n, this.createPitch.bind(this), dictionaryPitches); + this._appendMultiple(n, this.createPitch.bind(this), dictionaryPitches); return node; } @@ -316,7 +316,7 @@ class DisplayGenerator { n.textContent = `${position}`; n = node.querySelector('.term-pitch-accent-tag-list'); - DisplayGenerator._appendMultiple(n, this.createTag.bind(this), tags); + this._appendMultiple(n, this.createTag.bind(this), tags); n = node.querySelector('.term-pitch-accent-disambiguation-list'); this.createPitchAccentDisambiguations(n, exclusiveExpressions, exclusiveReadings); @@ -445,7 +445,7 @@ class DisplayGenerator { } } - static _appendMultiple(container, createItem, detailsIterable, fallback=[]) { + _appendMultiple(container, createItem, detailsIterable, fallback=[]) { if (container === null) { return 0; } const multi = ( @@ -468,7 +468,7 @@ class DisplayGenerator { return count; } - static _appendFurigana(container, segments, addText) { + _appendFurigana(container, segments, addText) { for (const {text, furigana} of segments) { if (furigana) { const ruby = document.createElement('ruby'); @@ -483,7 +483,7 @@ class DisplayGenerator { } } - static _appendMultilineText(container, text) { + _appendMultilineText(container, text) { const parts = text.split('\n'); container.appendChild(document.createTextNode(parts[0])); for (let i = 1, ii = parts.length; i < ii; ++i) { @@ -492,7 +492,7 @@ class DisplayGenerator { } } - static _getPitchInfos(definition) { + _getPitchInfos(definition) { const results = new Map(); const allExpressions = new Set(); @@ -510,7 +510,7 @@ class DisplayGenerator { } for (const {position, tags} of pitches) { - let pitchInfo = DisplayGenerator._findExistingPitchInfo(reading, position, tags, dictionaryResults); + let pitchInfo = this._findExistingPitchInfo(reading, position, tags, dictionaryResults); if (pitchInfo === null) { pitchInfo = {expressions: new Set(), reading, position, tags}; dictionaryResults.push(pitchInfo); @@ -539,12 +539,12 @@ class DisplayGenerator { return [...results.entries()]; } - static _findExistingPitchInfo(reading, position, tags, pitchInfoList) { + _findExistingPitchInfo(reading, position, tags, pitchInfoList) { for (const pitchInfo of pitchInfoList) { if ( pitchInfo.reading === reading && pitchInfo.position === position && - DisplayGenerator._areTagListsEqual(pitchInfo.tags, tags) + this._areTagListsEqual(pitchInfo.tags, tags) ) { return pitchInfo; } @@ -552,7 +552,7 @@ class DisplayGenerator { return null; } - static _areTagListsEqual(tagList1, tagList2) { + _areTagListsEqual(tagList1, tagList2) { const ii = tagList1.length; if (tagList2.length !== ii) { return false; } -- cgit v1.2.3 From 9bbe35da68b9cdbc49c8f223544bdefad16d66d4 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Thu, 9 Apr 2020 22:02:17 -0400 Subject: Mark functions as private --- ext/mixed/js/display-generator.js | 92 +++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 46 deletions(-) (limited to 'ext/mixed/js') diff --git a/ext/mixed/js/display-generator.js b/ext/mixed/js/display-generator.js index 2f1154eb..c3817ab2 100644 --- a/ext/mixed/js/display-generator.js +++ b/ext/mixed/js/display-generator.js @@ -70,11 +70,11 @@ class DisplayGenerator { let expressions = details.expressions; expressions = Array.isArray(expressions) ? expressions.map((e) => [e, termTags]) : null; - this._appendMultiple(expressionsContainer, this.createTermExpression.bind(this), expressions, [[details, termTags]]); - this._appendMultiple(reasonsContainer, this.createTermReason.bind(this), details.reasons); - this._appendMultiple(frequenciesContainer, this.createFrequencyTag.bind(this), details.frequencies); - this._appendMultiple(pitchesContainer, this.createPitches.bind(this), pitches); - this._appendMultiple(definitionsContainer, this.createTermDefinitionItem.bind(this), details.definitions, [details]); + this._appendMultiple(expressionsContainer, this._createTermExpression.bind(this), expressions, [[details, termTags]]); + this._appendMultiple(reasonsContainer, this._createTermReason.bind(this), details.reasons); + this._appendMultiple(frequenciesContainer, this._createFrequencyTag.bind(this), details.frequencies); + this._appendMultiple(pitchesContainer, this._createPitches.bind(this), pitches); + this._appendMultiple(definitionsContainer, this._createTermDefinitionItem.bind(this), details.definitions, [details]); if (debugInfoContainer !== null) { debugInfoContainer.textContent = JSON.stringify(details, null, 4); @@ -83,7 +83,7 @@ class DisplayGenerator { return node; } - createTermExpression([details, termTags]) { + _createTermExpression([details, termTags]) { const node = this._templateHandler.instantiate('term-expression'); const expressionContainer = node.querySelector('.term-expression-text'); @@ -110,14 +110,14 @@ class DisplayGenerator { const searchQueries = [details.expression, details.reading] .filter((x) => !!x) .map((x) => ({query: x})); - this._appendMultiple(tagContainer, this.createTag.bind(this), termTags); - this._appendMultiple(tagContainer, this.createSearchTag.bind(this), searchQueries); - this._appendMultiple(frequencyContainer, this.createFrequencyTag.bind(this), details.frequencies); + this._appendMultiple(tagContainer, this._createTag.bind(this), termTags); + this._appendMultiple(tagContainer, this._createSearchTag.bind(this), searchQueries); + this._appendMultiple(frequencyContainer, this._createFrequencyTag.bind(this), details.frequencies); return node; } - createTermReason(reason) { + _createTermReason(reason) { const fragment = this._templateHandler.instantiateFragment('term-reason'); const node = fragment.querySelector('.term-reason'); node.textContent = reason; @@ -125,7 +125,7 @@ class DisplayGenerator { return fragment; } - createTermDefinitionItem(details) { + _createTermDefinitionItem(details) { const node = this._templateHandler.instantiate('term-definition-item'); const tagListContainer = node.querySelector('.term-definition-tag-list'); @@ -134,14 +134,14 @@ class DisplayGenerator { node.dataset.dictionary = details.dictionary; - this._appendMultiple(tagListContainer, this.createTag.bind(this), details.definitionTags); - this._appendMultiple(onlyListContainer, this.createTermOnly.bind(this), details.only); - this._appendMultiple(glossaryContainer, this.createTermGlossaryItem.bind(this), details.glossary); + this._appendMultiple(tagListContainer, this._createTag.bind(this), details.definitionTags); + this._appendMultiple(onlyListContainer, this._createTermOnly.bind(this), details.only); + this._appendMultiple(glossaryContainer, this._createTermGlossaryItem.bind(this), details.glossary); return node; } - createTermGlossaryItem(glossary) { + _createTermGlossaryItem(glossary) { const node = this._templateHandler.instantiate('term-glossary-item'); const container = node.querySelector('.term-glossary'); if (container !== null) { @@ -150,14 +150,14 @@ class DisplayGenerator { return node; } - createTermOnly(only) { + _createTermOnly(only) { const node = this._templateHandler.instantiate('term-definition-only'); node.dataset.only = only; node.textContent = only; return node; } - createKanjiLink(character) { + _createKanjiLink(character) { const node = document.createElement('a'); node.href = '#'; node.className = 'kanji-link'; @@ -184,23 +184,23 @@ class DisplayGenerator { glyphContainer.textContent = details.character; } - this._appendMultiple(frequenciesContainer, this.createFrequencyTag.bind(this), details.frequencies); - this._appendMultiple(tagContainer, this.createTag.bind(this), details.tags); - this._appendMultiple(glossaryContainer, this.createKanjiGlossaryItem.bind(this), details.glossary); - this._appendMultiple(chineseReadingsContainer, this.createKanjiReading.bind(this), details.onyomi); - this._appendMultiple(japaneseReadingsContainer, this.createKanjiReading.bind(this), details.kunyomi); + this._appendMultiple(frequenciesContainer, this._createFrequencyTag.bind(this), details.frequencies); + this._appendMultiple(tagContainer, this._createTag.bind(this), details.tags); + this._appendMultiple(glossaryContainer, this._createKanjiGlossaryItem.bind(this), details.glossary); + this._appendMultiple(chineseReadingsContainer, this._createKanjiReading.bind(this), details.onyomi); + this._appendMultiple(japaneseReadingsContainer, this._createKanjiReading.bind(this), details.kunyomi); if (statisticsContainer !== null) { - statisticsContainer.appendChild(this.createKanjiInfoTable(details.stats.misc)); + statisticsContainer.appendChild(this._createKanjiInfoTable(details.stats.misc)); } if (classificationsContainer !== null) { - classificationsContainer.appendChild(this.createKanjiInfoTable(details.stats.class)); + classificationsContainer.appendChild(this._createKanjiInfoTable(details.stats.class)); } if (codepointsContainer !== null) { - codepointsContainer.appendChild(this.createKanjiInfoTable(details.stats.code)); + codepointsContainer.appendChild(this._createKanjiInfoTable(details.stats.code)); } if (dictionaryIndicesContainer !== null) { - dictionaryIndicesContainer.appendChild(this.createKanjiInfoTable(details.stats.index)); + dictionaryIndicesContainer.appendChild(this._createKanjiInfoTable(details.stats.index)); } if (debugInfoContainer !== null) { @@ -210,7 +210,7 @@ class DisplayGenerator { return node; } - createKanjiGlossaryItem(glossary) { + _createKanjiGlossaryItem(glossary) { const node = this._templateHandler.instantiate('kanji-glossary-item'); const container = node.querySelector('.kanji-glossary'); if (container !== null) { @@ -219,21 +219,21 @@ class DisplayGenerator { return node; } - createKanjiReading(reading) { + _createKanjiReading(reading) { const node = this._templateHandler.instantiate('kanji-reading'); node.textContent = reading; return node; } - createKanjiInfoTable(details) { + _createKanjiInfoTable(details) { const node = this._templateHandler.instantiate('kanji-info-table'); const container = node.querySelector('.kanji-info-table-body'); if (container !== null) { - const count = this._appendMultiple(container, this.createKanjiInfoTableItem.bind(this), details); + const count = this._appendMultiple(container, this._createKanjiInfoTableItem.bind(this), details); if (count === 0) { - const n = this.createKanjiInfoTableItemEmpty(); + const n = this._createKanjiInfoTableItemEmpty(); container.appendChild(n); } } @@ -241,7 +241,7 @@ class DisplayGenerator { return node; } - createKanjiInfoTableItem(details) { + _createKanjiInfoTableItem(details) { const node = this._templateHandler.instantiate('kanji-info-table-item'); const nameNode = node.querySelector('.kanji-info-table-item-header'); const valueNode = node.querySelector('.kanji-info-table-item-value'); @@ -254,11 +254,11 @@ class DisplayGenerator { return node; } - createKanjiInfoTableItemEmpty() { + _createKanjiInfoTableItemEmpty() { return this._templateHandler.instantiate('kanji-info-table-empty'); } - createTag(details) { + _createTag(details) { const node = this._templateHandler.instantiate('tag'); const inner = node.querySelector('.tag-inner'); @@ -270,7 +270,7 @@ class DisplayGenerator { return node; } - createSearchTag(details) { + _createSearchTag(details) { const node = this._templateHandler.instantiate('tag-search'); node.textContent = details.query; @@ -280,7 +280,7 @@ class DisplayGenerator { return node; } - createPitches(details) { + _createPitches(details) { if (!this._termPitchAccentStaticTemplateIsSetup) { this._termPitchAccentStaticTemplateIsSetup = true; const t = this._templateHandler.instantiate('term-pitch-accent-static'); @@ -294,16 +294,16 @@ class DisplayGenerator { node.dataset.pitchesMulti = 'true'; node.dataset.pitchesCount = `${dictionaryPitches.length}`; - const tag = this.createTag({notes: '', name: dictionary, category: 'pitch-accent-dictionary'}); + const tag = this._createTag({notes: '', name: dictionary, category: 'pitch-accent-dictionary'}); node.querySelector('.term-pitch-accent-group-tag-list').appendChild(tag); const n = node.querySelector('.term-pitch-accent-list'); - this._appendMultiple(n, this.createPitch.bind(this), dictionaryPitches); + this._appendMultiple(n, this._createPitch.bind(this), dictionaryPitches); return node; } - createPitch(details) { + _createPitch(details) { const {reading, position, tags, exclusiveExpressions, exclusiveReadings} = details; const morae = jp.getKanaMorae(reading); @@ -316,10 +316,10 @@ class DisplayGenerator { n.textContent = `${position}`; n = node.querySelector('.term-pitch-accent-tag-list'); - this._appendMultiple(n, this.createTag.bind(this), tags); + this._appendMultiple(n, this._createTag.bind(this), tags); n = node.querySelector('.term-pitch-accent-disambiguation-list'); - this.createPitchAccentDisambiguations(n, exclusiveExpressions, exclusiveReadings); + this._createPitchAccentDisambiguations(n, exclusiveExpressions, exclusiveReadings); n = node.querySelector('.term-pitch-accent-characters'); for (let i = 0, ii = morae.length; i < ii; ++i) { @@ -339,13 +339,13 @@ class DisplayGenerator { } if (morae.length > 0) { - this.populatePitchGraph(node.querySelector('.term-pitch-accent-graph'), position, morae); + this._populatePitchGraph(node.querySelector('.term-pitch-accent-graph'), position, morae); } return node; } - createPitchAccentDisambiguations(container, exclusiveExpressions, exclusiveReadings) { + _createPitchAccentDisambiguations(container, exclusiveExpressions, exclusiveReadings) { const templateName = 'term-pitch-accent-disambiguation'; for (const exclusiveExpression of exclusiveExpressions) { const node = this._templateHandler.instantiate(templateName); @@ -366,7 +366,7 @@ class DisplayGenerator { container.dataset.readingCount = `${exclusiveReadings.length}`; } - populatePitchGraph(svg, position, morae) { + _populatePitchGraph(svg, position, morae) { const svgns = svg.getAttribute('xmlns'); const ii = morae.length; svg.setAttribute('viewBox', `0 0 ${50 * (ii + 1)} 100`); @@ -406,7 +406,7 @@ class DisplayGenerator { path.setAttribute('d', `M${pathPoints.join(' L')}`); } - createFrequencyTag(details) { + _createFrequencyTag(details) { const node = this._templateHandler.instantiate('tag-frequency'); let n = node.querySelector('.term-frequency-dictionary-name'); @@ -434,7 +434,7 @@ class DisplayGenerator { part = ''; } - const link = this.createKanjiLink(c); + const link = this._createKanjiLink(c); container.appendChild(link); } else { part += c; -- cgit v1.2.3 From f9bdf2c66f5eca0ecb1c21f231492be47e40e690 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Thu, 9 Apr 2020 22:03:16 -0400 Subject: Organize --- ext/mixed/js/display-generator.js | 92 ++++++++++++++++++++------------------- 1 file changed, 47 insertions(+), 45 deletions(-) (limited to 'ext/mixed/js') diff --git a/ext/mixed/js/display-generator.js b/ext/mixed/js/display-generator.js index c3817ab2..951f16ec 100644 --- a/ext/mixed/js/display-generator.js +++ b/ext/mixed/js/display-generator.js @@ -83,6 +83,53 @@ class DisplayGenerator { return node; } + createKanjiEntry(details) { + const node = this._templateHandler.instantiate('kanji-entry'); + + const glyphContainer = node.querySelector('.kanji-glyph'); + const frequenciesContainer = node.querySelector('.frequencies'); + const tagContainer = node.querySelector('.tags'); + const glossaryContainer = node.querySelector('.kanji-glossary-list'); + const chineseReadingsContainer = node.querySelector('.kanji-readings-chinese'); + const japaneseReadingsContainer = node.querySelector('.kanji-readings-japanese'); + const statisticsContainer = node.querySelector('.kanji-statistics'); + const classificationsContainer = node.querySelector('.kanji-classifications'); + const codepointsContainer = node.querySelector('.kanji-codepoints'); + const dictionaryIndicesContainer = node.querySelector('.kanji-dictionary-indices'); + const debugInfoContainer = node.querySelector('.debug-info'); + + if (glyphContainer !== null) { + glyphContainer.textContent = details.character; + } + + this._appendMultiple(frequenciesContainer, this._createFrequencyTag.bind(this), details.frequencies); + this._appendMultiple(tagContainer, this._createTag.bind(this), details.tags); + this._appendMultiple(glossaryContainer, this._createKanjiGlossaryItem.bind(this), details.glossary); + this._appendMultiple(chineseReadingsContainer, this._createKanjiReading.bind(this), details.onyomi); + this._appendMultiple(japaneseReadingsContainer, this._createKanjiReading.bind(this), details.kunyomi); + + if (statisticsContainer !== null) { + statisticsContainer.appendChild(this._createKanjiInfoTable(details.stats.misc)); + } + if (classificationsContainer !== null) { + classificationsContainer.appendChild(this._createKanjiInfoTable(details.stats.class)); + } + if (codepointsContainer !== null) { + codepointsContainer.appendChild(this._createKanjiInfoTable(details.stats.code)); + } + if (dictionaryIndicesContainer !== null) { + dictionaryIndicesContainer.appendChild(this._createKanjiInfoTable(details.stats.index)); + } + + if (debugInfoContainer !== null) { + debugInfoContainer.textContent = JSON.stringify(details, null, 4); + } + + return node; + } + + // Private + _createTermExpression([details, termTags]) { const node = this._templateHandler.instantiate('term-expression'); @@ -165,51 +212,6 @@ class DisplayGenerator { return node; } - createKanjiEntry(details) { - const node = this._templateHandler.instantiate('kanji-entry'); - - const glyphContainer = node.querySelector('.kanji-glyph'); - const frequenciesContainer = node.querySelector('.frequencies'); - const tagContainer = node.querySelector('.tags'); - const glossaryContainer = node.querySelector('.kanji-glossary-list'); - const chineseReadingsContainer = node.querySelector('.kanji-readings-chinese'); - const japaneseReadingsContainer = node.querySelector('.kanji-readings-japanese'); - const statisticsContainer = node.querySelector('.kanji-statistics'); - const classificationsContainer = node.querySelector('.kanji-classifications'); - const codepointsContainer = node.querySelector('.kanji-codepoints'); - const dictionaryIndicesContainer = node.querySelector('.kanji-dictionary-indices'); - const debugInfoContainer = node.querySelector('.debug-info'); - - if (glyphContainer !== null) { - glyphContainer.textContent = details.character; - } - - this._appendMultiple(frequenciesContainer, this._createFrequencyTag.bind(this), details.frequencies); - this._appendMultiple(tagContainer, this._createTag.bind(this), details.tags); - this._appendMultiple(glossaryContainer, this._createKanjiGlossaryItem.bind(this), details.glossary); - this._appendMultiple(chineseReadingsContainer, this._createKanjiReading.bind(this), details.onyomi); - this._appendMultiple(japaneseReadingsContainer, this._createKanjiReading.bind(this), details.kunyomi); - - if (statisticsContainer !== null) { - statisticsContainer.appendChild(this._createKanjiInfoTable(details.stats.misc)); - } - if (classificationsContainer !== null) { - classificationsContainer.appendChild(this._createKanjiInfoTable(details.stats.class)); - } - if (codepointsContainer !== null) { - codepointsContainer.appendChild(this._createKanjiInfoTable(details.stats.code)); - } - if (dictionaryIndicesContainer !== null) { - dictionaryIndicesContainer.appendChild(this._createKanjiInfoTable(details.stats.index)); - } - - if (debugInfoContainer !== null) { - debugInfoContainer.textContent = JSON.stringify(details, null, 4); - } - - return node; - } - _createKanjiGlossaryItem(glossary) { const node = this._templateHandler.instantiate('kanji-glossary-item'); const container = node.querySelector('.kanji-glossary'); -- cgit v1.2.3 From 6788bb31d241e1b77a6630df3d617de4a9470f26 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Thu, 9 Apr 2020 22:16:55 -0400 Subject: Update _appendMultiple to not use a fallback --- ext/mixed/js/display-generator.js | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'ext/mixed/js') diff --git a/ext/mixed/js/display-generator.js b/ext/mixed/js/display-generator.js index 951f16ec..5c4b330d 100644 --- a/ext/mixed/js/display-generator.js +++ b/ext/mixed/js/display-generator.js @@ -68,13 +68,13 @@ class DisplayGenerator { const termTags = details.termTags; let expressions = details.expressions; - expressions = Array.isArray(expressions) ? expressions.map((e) => [e, termTags]) : null; + expressions = Array.isArray(expressions) ? expressions.map((e) => [e, termTags]) : [[details, termTags]]; - this._appendMultiple(expressionsContainer, this._createTermExpression.bind(this), expressions, [[details, termTags]]); + this._appendMultiple(expressionsContainer, this._createTermExpression.bind(this), expressions); this._appendMultiple(reasonsContainer, this._createTermReason.bind(this), details.reasons); this._appendMultiple(frequenciesContainer, this._createFrequencyTag.bind(this), details.frequencies); this._appendMultiple(pitchesContainer, this._createPitches.bind(this), pitches); - this._appendMultiple(definitionsContainer, this._createTermDefinitionItem.bind(this), details.definitions, [details]); + this._appendMultiple(definitionsContainer, this._createTermDefinitionItem.bind(this), definitionMulti ? details.definitions : [details]); if (debugInfoContainer !== null) { debugInfoContainer.textContent = JSON.stringify(details, null, 4); @@ -447,22 +447,23 @@ class DisplayGenerator { } } - _appendMultiple(container, createItem, detailsIterable, fallback=[]) { - if (container === null) { return 0; } - - const multi = ( - detailsIterable !== null && - typeof detailsIterable === 'object' && - typeof detailsIterable[Symbol.iterator] !== 'undefined' + _isIterable(value) { + return ( + value !== null && + typeof value === 'object' && + typeof value[Symbol.iterator] !== 'undefined' ); - if (!multi) { detailsIterable = fallback; } + } + _appendMultiple(container, createItem, detailsIterable) { let count = 0; - for (const details of detailsIterable) { - const item = createItem(details); - if (item === null) { continue; } - container.appendChild(item); - ++count; + if (container !== null && this._isIterable(detailsIterable)) { + for (const details of detailsIterable) { + const item = createItem(details); + if (item === null) { continue; } + container.appendChild(item); + ++count; + } } container.dataset.count = `${count}`; -- cgit v1.2.3 From bb37b74288cf0653f42bbb149e3c563adcf2ead5 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Thu, 9 Apr 2020 22:19:58 -0400 Subject: Rename "only" to "disambiguation" to match naming convention used for pitch accents --- ext/mixed/css/display.css | 10 +++++----- ext/mixed/display-templates.html | 4 ++-- ext/mixed/js/display-generator.js | 12 ++++++------ 3 files changed, 13 insertions(+), 13 deletions(-) (limited to 'ext/mixed/js') diff --git a/ext/mixed/css/display.css b/ext/mixed/css/display.css index ac17e2ec..e10c9379 100644 --- a/ext/mixed/css/display.css +++ b/ext/mixed/css/display.css @@ -365,19 +365,19 @@ button.action-button { list-style-type: circle; } -.term-definition-only-list[data-count="0"] { +.term-definition-disambiguation-list[data-count="0"] { display: none; } -.term-definition-only-list:before { +.term-definition-disambiguation-list:before { content: "("; } -.term-definition-only-list:after { +.term-definition-disambiguation-list:after { content: " only)"; } -.term-definition-only+.term-definition-only:before { +.term-definition-disambiguation+.term-definition-disambiguation:before { content: ", "; } @@ -399,7 +399,7 @@ button.action-button { } :root[data-compact-glossaries=true] .term-definition-tag-list, -:root[data-compact-glossaries=true] .term-definition-only-list:not([data-count="0"]) { +:root[data-compact-glossaries=true] .term-definition-disambiguation-list:not([data-count="0"]) { display: inline; } diff --git a/ext/mixed/display-templates.html b/ext/mixed/display-templates.html index b8d52d15..3baa8293 100644 --- a/ext/mixed/display-templates.html +++ b/ext/mixed/display-templates.html @@ -30,10 +30,10 @@ - + diff --git a/ext/mixed/js/display-generator.js b/ext/mixed/js/display-generator.js index 5c4b330d..6ae727e0 100644 --- a/ext/mixed/js/display-generator.js +++ b/ext/mixed/js/display-generator.js @@ -176,13 +176,13 @@ class DisplayGenerator { const node = this._templateHandler.instantiate('term-definition-item'); const tagListContainer = node.querySelector('.term-definition-tag-list'); - const onlyListContainer = node.querySelector('.term-definition-only-list'); + const onlyListContainer = node.querySelector('.term-definition-disambiguation-list'); const glossaryContainer = node.querySelector('.term-glossary-list'); node.dataset.dictionary = details.dictionary; this._appendMultiple(tagListContainer, this._createTag.bind(this), details.definitionTags); - this._appendMultiple(onlyListContainer, this._createTermOnly.bind(this), details.only); + this._appendMultiple(onlyListContainer, this._createTermDisambiguation.bind(this), details.only); this._appendMultiple(glossaryContainer, this._createTermGlossaryItem.bind(this), details.glossary); return node; @@ -197,10 +197,10 @@ class DisplayGenerator { return node; } - _createTermOnly(only) { - const node = this._templateHandler.instantiate('term-definition-only'); - node.dataset.only = only; - node.textContent = only; + _createTermDisambiguation(disambiguation) { + const node = this._templateHandler.instantiate('term-definition-disambiguation'); + node.dataset.term = disambiguation; + node.textContent = disambiguation; return node; } -- cgit v1.2.3 From 06183ec12442fc127a7f723225bcf1782eb15ebc Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Thu, 9 Apr 2020 22:35:26 -0400 Subject: Update how termTags is passed to _createTermExpression --- ext/mixed/js/display-generator.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'ext/mixed/js') diff --git a/ext/mixed/js/display-generator.js b/ext/mixed/js/display-generator.js index 6ae727e0..b2d34cfc 100644 --- a/ext/mixed/js/display-generator.js +++ b/ext/mixed/js/display-generator.js @@ -68,9 +68,9 @@ class DisplayGenerator { const termTags = details.termTags; let expressions = details.expressions; - expressions = Array.isArray(expressions) ? expressions.map((e) => [e, termTags]) : [[details, termTags]]; + expressions = Array.isArray(expressions) ? expressions : [details]; - this._appendMultiple(expressionsContainer, this._createTermExpression.bind(this), expressions); + this._appendMultiple(expressionsContainer, this._createTermExpression.bind(this), expressions, termTags); this._appendMultiple(reasonsContainer, this._createTermReason.bind(this), details.reasons); this._appendMultiple(frequenciesContainer, this._createFrequencyTag.bind(this), details.frequencies); this._appendMultiple(pitchesContainer, this._createPitches.bind(this), pitches); @@ -130,7 +130,7 @@ class DisplayGenerator { // Private - _createTermExpression([details, termTags]) { + _createTermExpression(details, termTags) { const node = this._templateHandler.instantiate('term-expression'); const expressionContainer = node.querySelector('.term-expression-text'); @@ -455,11 +455,11 @@ class DisplayGenerator { ); } - _appendMultiple(container, createItem, detailsIterable) { + _appendMultiple(container, createItem, detailsIterable, ...args) { let count = 0; if (container !== null && this._isIterable(detailsIterable)) { for (const details of detailsIterable) { - const item = createItem(details); + const item = createItem(details, ...args); if (item === null) { continue; } container.appendChild(item); ++count; -- cgit v1.2.3 From 025b1f398b7e498a0a61ebee095498caccb46819 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Thu, 9 Apr 2020 22:38:08 -0400 Subject: Simplify access to details fields in createTermEntry --- ext/mixed/js/display-generator.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'ext/mixed/js') diff --git a/ext/mixed/js/display-generator.js b/ext/mixed/js/display-generator.js index b2d34cfc..19f6a56e 100644 --- a/ext/mixed/js/display-generator.js +++ b/ext/mixed/js/display-generator.js @@ -44,13 +44,15 @@ class DisplayGenerator { const debugInfoContainer = node.querySelector('.debug-info'); const bodyContainer = node.querySelector('.term-entry-body'); + const {termTags, expressions, definitions} = details; + const pitches = this._getPitchInfos(details); const pitchCount = pitches.reduce((i, v) => i + v[1].length, 0); - const expressionMulti = Array.isArray(details.expressions); - const definitionMulti = Array.isArray(details.definitions); - const expressionCount = expressionMulti ? details.expressions.length : 1; - const definitionCount = definitionMulti ? details.definitions.length : 1; + const expressionMulti = Array.isArray(expressions); + const definitionMulti = Array.isArray(definitions); + const expressionCount = expressionMulti ? expressions.length : 1; + const definitionCount = definitionMulti ? definitions.length : 1; const uniqueExpressionCount = Array.isArray(details.expression) ? new Set(details.expression).size : 1; node.dataset.expressionMulti = `${expressionMulti}`; @@ -66,15 +68,11 @@ class DisplayGenerator { (pitches.length > 0 ? 1 : 0) }`; - const termTags = details.termTags; - let expressions = details.expressions; - expressions = Array.isArray(expressions) ? expressions : [details]; - - this._appendMultiple(expressionsContainer, this._createTermExpression.bind(this), expressions, termTags); + this._appendMultiple(expressionsContainer, this._createTermExpression.bind(this), expressionMulti ? expressions : [details], termTags); this._appendMultiple(reasonsContainer, this._createTermReason.bind(this), details.reasons); this._appendMultiple(frequenciesContainer, this._createFrequencyTag.bind(this), details.frequencies); this._appendMultiple(pitchesContainer, this._createPitches.bind(this), pitches); - this._appendMultiple(definitionsContainer, this._createTermDefinitionItem.bind(this), definitionMulti ? details.definitions : [details]); + this._appendMultiple(definitionsContainer, this._createTermDefinitionItem.bind(this), definitionMulti ? definitions : [details]); if (debugInfoContainer !== null) { debugInfoContainer.textContent = JSON.stringify(details, null, 4); -- cgit v1.2.3 From 2c5bf0ed6b2345fb8aa302a38f73cd452df8c254 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Fri, 10 Apr 2020 17:11:41 -0400 Subject: Fix getSelection not working in QueryParser --- ext/mixed/js/text-scanner.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/mixed/js') diff --git a/ext/mixed/js/text-scanner.js b/ext/mixed/js/text-scanner.js index b8156c01..9d8a7f0c 100644 --- a/ext/mixed/js/text-scanner.js +++ b/ext/mixed/js/text-scanner.js @@ -134,7 +134,7 @@ class TextScanner { this.preventNextClick = false; const primaryTouch = e.changedTouches[0]; - if (DOM.isPointInSelection(primaryTouch.clientX, primaryTouch.clientY, this.node.getSelection())) { + if (DOM.isPointInSelection(primaryTouch.clientX, primaryTouch.clientY, window.getSelection())) { return; } -- cgit v1.2.3 From a296c758b95b428777548f5aada1be13429faf03 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Fri, 10 Apr 2020 20:00:18 -0400 Subject: apiBroadcast => apiBroadcastTab --- ext/bg/js/backend.js | 4 ++-- ext/fg/js/float.js | 6 +++--- ext/fg/js/frame-offset-forwarder.js | 4 ++-- ext/fg/js/frontend-initialize.js | 4 ++-- ext/fg/js/frontend.js | 6 +++--- ext/mixed/js/api.js | 4 ++-- ext/mixed/js/display.js | 4 ++-- 7 files changed, 16 insertions(+), 16 deletions(-) (limited to 'ext/mixed/js') diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js index 35e75bbe..20e17836 100644 --- a/ext/bg/js/backend.js +++ b/ext/bg/js/backend.js @@ -94,7 +94,7 @@ class Backend { ['commandExec', {handler: this._onApiCommandExec.bind(this), async: false}], ['audioGetUri', {handler: this._onApiAudioGetUri.bind(this), async: true}], ['screenshotGet', {handler: this._onApiScreenshotGet.bind(this), async: true}], - ['broadcast', {handler: this._onApiBroadcast.bind(this), async: false}], + ['broadcastTab', {handler: this._onApiBroadcastTab.bind(this), async: false}], ['frameInformationGet', {handler: this._onApiFrameInformationGet.bind(this), async: true}], ['injectStylesheet', {handler: this._onApiInjectStylesheet.bind(this), async: true}], ['getEnvironmentInfo', {handler: this._onApiGetEnvironmentInfo.bind(this), async: true}], @@ -566,7 +566,7 @@ class Backend { }); } - _onApiBroadcast({action, params}, sender) { + _onApiBroadcastTab({action, params}, sender) { if (!(sender && sender.tab)) { return false; } diff --git a/ext/fg/js/float.js b/ext/fg/js/float.js index 8c00d0a5..d0c0f419 100644 --- a/ext/fg/js/float.js +++ b/ext/fg/js/float.js @@ -18,7 +18,7 @@ /* global * Display - * apiBroadcast + * apiBroadcastTab * apiGetMessageToken * popupNestedInitialize */ @@ -80,7 +80,7 @@ class DisplayFloat extends Display { this.setContentScale(scale); - apiBroadcast('popupPrepareCompleted', {targetPopupId: this._popupId}); + apiBroadcastTab('popupPrepareCompleted', {targetPopupId: this._popupId}); } onError(error) { @@ -181,7 +181,7 @@ class DisplayFloat extends Display { }, 2000 ); - apiBroadcast('requestDocumentInformationBroadcast', {uniqueId}); + apiBroadcastTab('requestDocumentInformationBroadcast', {uniqueId}); const {title} = await promise; return title; diff --git a/ext/fg/js/frame-offset-forwarder.js b/ext/fg/js/frame-offset-forwarder.js index 88c1b72c..609d0d77 100644 --- a/ext/fg/js/frame-offset-forwarder.js +++ b/ext/fg/js/frame-offset-forwarder.js @@ -17,7 +17,7 @@ */ /* global - * apiBroadcast + * apiBroadcastTab */ class FrameOffsetForwarder { @@ -97,6 +97,6 @@ class FrameOffsetForwarder { } _forwardFrameOffsetOrigin(offset, uniqueId) { - apiBroadcast('frameOffset', {offset, uniqueId}); + apiBroadcastTab('frameOffset', {offset, uniqueId}); } } diff --git a/ext/fg/js/frontend-initialize.js b/ext/fg/js/frontend-initialize.js index d2572746..5c9ce7b1 100644 --- a/ext/fg/js/frontend-initialize.js +++ b/ext/fg/js/frontend-initialize.js @@ -21,7 +21,7 @@ * Frontend * PopupProxy * PopupProxyHost - * apiBroadcast + * apiBroadcastTab * apiOptionsGet */ @@ -44,7 +44,7 @@ async function main() { } } ); - apiBroadcast('rootPopupRequestInformationBroadcast'); + apiBroadcastTab('rootPopupRequestInformationBroadcast'); const {popupId, frameId} = await rootPopupInformationPromise; const frameOffsetForwarder = new FrameOffsetForwarder(); diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js index bcb0b84a..b380dbfd 100644 --- a/ext/fg/js/frontend.js +++ b/ext/fg/js/frontend.js @@ -18,7 +18,7 @@ /* global * TextScanner - * apiBroadcast + * apiBroadcastTab * apiGetZoom * apiKanjiFind * apiOptionsGet @@ -261,12 +261,12 @@ class Frontend extends TextScanner { _broadcastRootPopupInformation() { if (!this.popup.isProxy() && this.popup.depth === 0) { - apiBroadcast('rootPopupInformation', {popupId: this.popup.id, frameId: this.popup.frameId}); + apiBroadcastTab('rootPopupInformation', {popupId: this.popup.id, frameId: this.popup.frameId}); } } _broadcastDocumentInformation(uniqueId) { - apiBroadcast('documentInformationBroadcast', { + apiBroadcastTab('documentInformationBroadcast', { uniqueId, frameId: this.popup.frameId, title: document.title diff --git a/ext/mixed/js/api.js b/ext/mixed/js/api.js index d28e3ab6..83a4a403 100644 --- a/ext/mixed/js/api.js +++ b/ext/mixed/js/api.js @@ -81,8 +81,8 @@ function apiScreenshotGet(options) { return _apiInvoke('screenshotGet', {options}); } -function apiBroadcast(action, params) { - return _apiInvoke('broadcast', {action, params}); +function apiBroadcastTab(action, params) { + return _apiInvoke('broadcastTab', {action, params}); } function apiFrameInformationGet() { diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 710674b2..b691ae12 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -23,7 +23,7 @@ * DisplayGenerator * WindowScroll * apiAudioGetUri - * apiBroadcast + * apiBroadcastTab * apiDefinitionAdd * apiDefinitionsAddable * apiKanjiFind @@ -855,7 +855,7 @@ class Display { } setPopupVisibleOverride(visible) { - return apiBroadcast('popupSetVisibleOverride', {visible}); + return apiBroadcastTab('popupSetVisibleOverride', {visible}); } setSpinnerVisible(visible) { -- cgit v1.2.3 From 1df59d57b5dcbf9d3efedcb21a4d5e16524a67c1 Mon Sep 17 00:00:00 2001 From: siikamiika Date: Fri, 10 Apr 2020 02:48:41 +0300 Subject: limit popup depth live --- ext/fg/js/frontend.js | 3 ++- ext/mixed/js/text-scanner.js | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'ext/mixed/js') diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js index 55d699e5..a6b24c76 100644 --- a/ext/fg/js/frontend.js +++ b/ext/fg/js/frontend.js @@ -30,7 +30,8 @@ class Frontend extends TextScanner { super( window, popup.isProxy() ? [] : [popup.getContainer()], - [(x, y) => this.popup.containsPoint(x, y)] + [(x, y) => this.popup.containsPoint(x, y)], + () => this.popup.depth <= this.options.scanning.popupNestingMaxDepth ); this.popup = popup; diff --git a/ext/mixed/js/text-scanner.js b/ext/mixed/js/text-scanner.js index a1d96320..1d6e36e0 100644 --- a/ext/mixed/js/text-scanner.js +++ b/ext/mixed/js/text-scanner.js @@ -22,11 +22,13 @@ */ class TextScanner { - constructor(node, ignoreElements, ignorePoints) { + constructor(node, ignoreElements, ignorePoints, canEnable=null) { this.node = node; this.ignoreElements = ignoreElements; this.ignorePoints = ignorePoints; + this.canEnable = canEnable; + this.ignoreNodes = null; this.scanTimerPromise = null; @@ -225,6 +227,10 @@ class TextScanner { } setEnabled(enabled) { + if (this.canEnable !== null && !this.canEnable()) { + enabled = false; + } + if (enabled) { if (!this.enabled) { this.hookEvents(); -- cgit v1.2.3 From 565e3a8c6ad31afa0ddb171ac5a33b6b84e5c3dc Mon Sep 17 00:00:00 2001 From: siikamiika Date: Fri, 10 Apr 2020 15:49:56 +0300 Subject: change iframe popup live --- ext/fg/js/frontend-initialize.js | 13 +++++++++---- ext/fg/js/frontend.js | 11 +++++++++-- ext/mixed/js/text-scanner.js | 2 +- 3 files changed, 19 insertions(+), 7 deletions(-) (limited to 'ext/mixed/js') diff --git a/ext/fg/js/frontend-initialize.js b/ext/fg/js/frontend-initialize.js index 2cfb6176..ce1a6bf6 100644 --- a/ext/fg/js/frontend-initialize.js +++ b/ext/fg/js/frontend-initialize.js @@ -86,10 +86,6 @@ async function main() { const applyOptions = async () => { const optionsContext = {depth: isSearchPage ? 0 : depth, url}; const options = await apiOptionsGet(optionsContext); - if (isSearchPage) { - const disabled = !options.scanning.enableOnSearchPage; - initEventDispatcher.trigger('setDisabledOverride', {disabled}); - } let popup; if (isIframe && options.general.showIframePopupsInRootFrame) { @@ -103,6 +99,15 @@ async function main() { popups.normal = popup; } + if (isSearchPage) { + const disabled = !options.scanning.enableOnSearchPage; + initEventDispatcher.trigger('setDisabledOverride', {disabled}); + } + + if (isIframe) { + initEventDispatcher.trigger('popupChange', {popup}); + } + if (frontend === null) { frontend = new Frontend(popup, initEventDispatcher); await frontend.prepare(); diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js index a6df4b4c..f969df32 100644 --- a/ext/fg/js/frontend.js +++ b/ext/fg/js/frontend.js @@ -29,7 +29,7 @@ class Frontend extends TextScanner { constructor(popup, initEventDispatcher) { super( window, - popup.isProxy() ? [] : [popup.getContainer()], + () => this.popup.isProxy() ? [] : [this.popup.getContainer()], [(x, y) => this.popup.containsPoint(x, y)], () => this.popup.depth <= this.options.scanning.popupNestingMaxDepth && !this._disabledOverride ); @@ -78,6 +78,7 @@ class Frontend extends TextScanner { } this.initEventDispatcher.on('setDisabledOverride', this.onSetDisabledOverride.bind(this)); + this.initEventDispatcher.on('popupChange', this.onPopupChange.bind(this)); yomichan.on('orphaned', this.onOrphaned.bind(this)); yomichan.on('optionsUpdated', this.updateOptions.bind(this)); @@ -242,6 +243,12 @@ class Frontend extends TextScanner { } } + async onPopupChange({popup}) { + this.onSearchClear(true); + this.popup = popup; + await popup.setOptions(this.options); + } + getOptionsContext() { this.optionsContext.url = this.popup.url; return this.optionsContext; @@ -274,7 +281,7 @@ class Frontend extends TextScanner { } _broadcastRootPopupInformation() { - if (!this.popup.isProxy() && this.popup.depth === 0) { + if (!this.popup.isProxy() && this.popup.depth === 0 && this.popup.frameId === 0) { apiBroadcastTab('rootPopupInformation', {popupId: this.popup.id, frameId: this.popup.frameId}); } } diff --git a/ext/mixed/js/text-scanner.js b/ext/mixed/js/text-scanner.js index 1d6e36e0..85be7119 100644 --- a/ext/mixed/js/text-scanner.js +++ b/ext/mixed/js/text-scanner.js @@ -48,7 +48,7 @@ class TextScanner { } onMouseOver(e) { - if (this.ignoreElements.includes(e.target)) { + if (this.ignoreElements().includes(e.target)) { this.scanTimerClear(); } } -- cgit v1.2.3 From 5c3641eadb78144b7f6305ebbd574bbc6265a4c4 Mon Sep 17 00:00:00 2001 From: siikamiika Date: Sat, 11 Apr 2020 16:20:12 +0300 Subject: simplify frontend disable override --- ext/fg/js/frontend-initialize.js | 5 ++++- ext/fg/js/frontend.js | 15 ++++++++------- ext/mixed/js/text-scanner.js | 16 +++++----------- 3 files changed, 17 insertions(+), 19 deletions(-) (limited to 'ext/mixed/js') diff --git a/ext/fg/js/frontend-initialize.js b/ext/fg/js/frontend-initialize.js index 34be6bc6..e794c7c0 100644 --- a/ext/fg/js/frontend-initialize.js +++ b/ext/fg/js/frontend-initialize.js @@ -80,6 +80,7 @@ async function main() { }; let frontend = null; + let frontendPreparePromise = null; const applyOptions = async () => { const optionsContext = {depth: isSearchPage ? 0 : depth, url}; @@ -99,8 +100,10 @@ async function main() { if (frontend === null) { frontend = new Frontend(popup); - await frontend.prepare(); + frontendPreparePromise = frontend.prepare(); + await frontendPreparePromise; } else { + await frontendPreparePromise; if (isSearchPage) { const disabled = !options.scanning.enableOnSearchPage; frontend.setDisabledOverride(disabled); diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js index 288d3589..20bfc638 100644 --- a/ext/fg/js/frontend.js +++ b/ext/fg/js/frontend.js @@ -30,8 +30,7 @@ class Frontend extends TextScanner { super( window, () => this.popup.isProxy() ? [] : [this.popup.getContainer()], - [(x, y) => this.popup.containsPoint(x, y)], - () => this.popup.depth <= this.options.scanning.popupNestingMaxDepth && !this._disabledOverride + [(x, y) => this.popup.containsPoint(x, y)] ); this.popup = popup; @@ -138,10 +137,7 @@ class Frontend extends TextScanner { setDisabledOverride(disabled) { this._disabledOverride = disabled; - // other cases handed by regular options update - if (disabled && this.enabled) { - this.setEnabled(false); - } + this.setEnabled(this.options.general.enable, this._canEnable()); } async setPopup(popup) { @@ -151,7 +147,7 @@ class Frontend extends TextScanner { } async updateOptions() { - this.setOptions(await apiOptionsGet(this.getOptionsContext())); + this.setOptions(await apiOptionsGet(this.getOptionsContext()), this._canEnable()); const ignoreNodes = ['.scan-disable', '.scan-disable *']; if (!this.options.scanning.enableOnPopupExpressions) { @@ -290,6 +286,11 @@ class Frontend extends TextScanner { }); } + _canEnable() { + if (this.options === null) { return true; } // called by updateOptions for the first time + return this.popup.depth <= this.options.scanning.popupNestingMaxDepth && !this._disabledOverride; + } + async _updatePopupPosition() { const textSource = this.getCurrentTextSource(); if (textSource !== null && await this.popup.isVisible()) { diff --git a/ext/mixed/js/text-scanner.js b/ext/mixed/js/text-scanner.js index 85be7119..bff9544f 100644 --- a/ext/mixed/js/text-scanner.js +++ b/ext/mixed/js/text-scanner.js @@ -22,13 +22,11 @@ */ class TextScanner { - constructor(node, ignoreElements, ignorePoints, canEnable=null) { + constructor(node, ignoreElements, ignorePoints) { this.node = node; this.ignoreElements = ignoreElements; this.ignorePoints = ignorePoints; - this.canEnable = canEnable; - this.ignoreNodes = null; this.scanTimerPromise = null; @@ -226,12 +224,8 @@ class TextScanner { } } - setEnabled(enabled) { - if (this.canEnable !== null && !this.canEnable()) { - enabled = false; - } - - if (enabled) { + setEnabled(enabled, canEnable) { + if (enabled && canEnable) { if (!this.enabled) { this.hookEvents(); this.enabled = true; @@ -277,9 +271,9 @@ class TextScanner { ]; } - setOptions(options) { + setOptions(options, canEnable=true) { this.options = options; - this.setEnabled(this.options.general.enable); + this.setEnabled(this.options.general.enable, canEnable); } async searchAt(x, y, cause) { -- cgit v1.2.3 From c613321a735dbf333491ab199b808f30852a8daa Mon Sep 17 00:00:00 2001 From: siikamiika Date: Sun, 12 Apr 2020 03:53:24 +0300 Subject: move QueryParser.parseText to Backend --- ext/bg/js/backend.js | 128 +++++++++++++++++------------ ext/bg/js/search-query-parser-generator.js | 11 ++- ext/bg/js/search-query-parser.js | 27 +----- ext/mixed/js/api.js | 4 - 4 files changed, 88 insertions(+), 82 deletions(-) (limited to 'ext/mixed/js') diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js index be8ea322..65e00f28 100644 --- a/ext/bg/js/backend.js +++ b/ext/bg/js/backend.js @@ -85,7 +85,6 @@ class Backend { ['kanjiFind', {handler: this._onApiKanjiFind.bind(this), async: true}], ['termsFind', {handler: this._onApiTermsFind.bind(this), async: true}], ['textParse', {handler: this._onApiTextParse.bind(this), async: true}], - ['textParseMecab', {handler: this._onApiTextParseMecab.bind(this), async: true}], ['definitionAdd', {handler: this._onApiDefinitionAdd.bind(this), async: true}], ['definitionsAddable', {handler: this._onApiDefinitionsAddable.bind(this), async: true}], ['noteView', {handler: this._onApiNoteView.bind(this), async: true}], @@ -315,6 +314,65 @@ class Backend { return await this.dictionaryImporter.import(this.database, archiveSource, onProgress, details); } + async _textParseScanning(text, options) { + const results = []; + while (text.length > 0) { + const term = []; + const [definitions, sourceLength] = await this.translator.findTerms( + 'simple', + text.substring(0, options.scanning.length), + {}, + options + ); + if (definitions.length > 0) { + dictTermsSort(definitions); + const {expression, reading} = definitions[0]; + const source = text.substring(0, sourceLength); + for (const {text: text2, furigana} of jp.distributeFuriganaInflected(expression, reading, source)) { + const reading2 = jp.convertReading(text2, furigana, options.parsing.readingMode); + term.push({text: text2, reading: reading2}); + } + text = text.substring(source.length); + } else { + const reading = jp.convertReading(text[0], null, options.parsing.readingMode); + term.push({text: text[0], reading}); + text = text.substring(1); + } + results.push(term); + } + return results; + } + + async _textParseMecab(text, options) { + const results = []; + const rawResults = await this.mecab.parseText(text); + for (const [mecabName, parsedLines] of Object.entries(rawResults)) { + const result = []; + for (const parsedLine of parsedLines) { + for (const {expression, reading, source} of parsedLine) { + const term = []; + if (expression !== null && reading !== null) { + for (const {text: text2, furigana} of jp.distributeFuriganaInflected( + expression, + jp.convertKatakanaToHiragana(reading), + source + )) { + const reading2 = jp.convertReading(text2, furigana, options.parsing.readingMode); + term.push({text: text2, reading: reading2}); + } + } else { + const reading2 = jp.convertReading(source, null, options.parsing.readingMode); + term.push({text: source, reading: reading2}); + } + result.push(term); + } + result.push([{text: '\n'}]); + } + results.push([mecabName, result]); + } + return results; + } + // Message handlers _onApiYomichanCoreReady(_params, sender) { @@ -406,61 +464,27 @@ class Backend { async _onApiTextParse({text, optionsContext}) { const options = this.getOptions(optionsContext); const results = []; - while (text.length > 0) { - const term = []; - const [definitions, sourceLength] = await this.translator.findTerms( - 'simple', - text.substring(0, options.scanning.length), - {}, - options - ); - if (definitions.length > 0) { - dictTermsSort(definitions); - const {expression, reading} = definitions[0]; - const source = text.substring(0, sourceLength); - for (const {text: text2, furigana} of jp.distributeFuriganaInflected(expression, reading, source)) { - const reading2 = jp.convertReading(text2, furigana, options.parsing.readingMode); - term.push({text: text2, reading: reading2}); - } - text = text.substring(source.length); - } else { - const reading = jp.convertReading(text[0], null, options.parsing.readingMode); - term.push({text: text[0], reading}); - text = text.substring(1); - } - results.push(term); + + if (options.parsing.enableScanningParser) { + results.push({ + source: 'scanning-parser', + id: 'scan', + content: await this._textParseScanning(text, options) + }); } - return results; - } - async _onApiTextParseMecab({text, optionsContext}) { - const options = this.getOptions(optionsContext); - const results = []; - const rawResults = await this.mecab.parseText(text); - for (const [mecabName, parsedLines] of Object.entries(rawResults)) { - const result = []; - for (const parsedLine of parsedLines) { - for (const {expression, reading, source} of parsedLine) { - const term = []; - if (expression !== null && reading !== null) { - for (const {text: text2, furigana} of jp.distributeFuriganaInflected( - expression, - jp.convertKatakanaToHiragana(reading), - source - )) { - const reading2 = jp.convertReading(text2, furigana, options.parsing.readingMode); - term.push({text: text2, reading: reading2}); - } - } else { - const reading2 = jp.convertReading(source, null, options.parsing.readingMode); - term.push({text: source, reading: reading2}); - } - result.push(term); - } - result.push([{text: '\n'}]); + if (options.parsing.enableMecabParser) { + const mecabResults = await this._textParseMecab(text, options); + for (const [mecabDictName, mecabDictResults] of mecabResults) { + results.push({ + source: 'mecab', + dictionary: mecabDictName, + id: `mecab-${mecabDictName}`, + content: mecabDictResults + }); } - results.push([mecabName, result]); } + return results; } diff --git a/ext/bg/js/search-query-parser-generator.js b/ext/bg/js/search-query-parser-generator.js index 390841c1..d44829f7 100644 --- a/ext/bg/js/search-query-parser-generator.js +++ b/ext/bg/js/search-query-parser-generator.js @@ -71,7 +71,16 @@ class QueryParserGenerator { for (const parseResult of parseResults) { const optionContainer = this._templateHandler.instantiate('select-option'); optionContainer.value = parseResult.id; - optionContainer.textContent = parseResult.name; + switch (parseResult.source) { + case 'scanning-parser': + optionContainer.textContent = 'Scanning parser'; + break; + case 'mecab': + optionContainer.textContent = `MeCab: ${parseResult.dictionary}`; + break; + default: + optionContainer.textContent = 'Unrecognized dictionary'; + } optionContainer.defaultSelected = selectedParser === parseResult.id; selectContainer.appendChild(optionContainer); } diff --git a/ext/bg/js/search-query-parser.js b/ext/bg/js/search-query-parser.js index 01a0ace5..da61b045 100644 --- a/ext/bg/js/search-query-parser.js +++ b/ext/bg/js/search-query-parser.js @@ -21,7 +21,6 @@ * apiOptionsSet * apiTermsFind * apiTextParse - * apiTextParseMecab * docSentenceExtract */ @@ -128,7 +127,7 @@ class QueryParser extends TextScanner { this.setPreview(text); - this.parseResults = await this.parseText(text); + this.parseResults = await apiTextParse(text, this.getOptionsContext()); this.refreshSelectedParser(); this.renderParserSelect(); @@ -137,28 +136,6 @@ class QueryParser extends TextScanner { this.setSpinnerVisible(false); } - async parseText(text) { - const results = []; - if (this.options.parsing.enableScanningParser) { - results.push({ - name: 'Scanning parser', - id: 'scan', - parsedText: await apiTextParse(text, this.getOptionsContext()) - }); - } - if (this.options.parsing.enableMecabParser) { - const mecabResults = await apiTextParseMecab(text, this.getOptionsContext()); - for (const [mecabDictName, mecabDictResults] of mecabResults) { - results.push({ - name: `MeCab: ${mecabDictName}`, - id: `mecab-${mecabDictName}`, - parsedText: mecabDictResults - }); - } - } - return results; - } - setPreview(text) { const previewTerms = []; for (let i = 0, ii = text.length; i < ii; i += 2) { @@ -183,6 +160,6 @@ class QueryParser extends TextScanner { const parseResult = this.getParseResult(); this.queryParser.textContent = ''; if (!parseResult) { return; } - this.queryParser.appendChild(this.queryParserGenerator.createParseResult(parseResult.parsedText)); + this.queryParser.appendChild(this.queryParserGenerator.createParseResult(parseResult.content)); } } diff --git a/ext/mixed/js/api.js b/ext/mixed/js/api.js index 50b285a5..30c08347 100644 --- a/ext/mixed/js/api.js +++ b/ext/mixed/js/api.js @@ -44,10 +44,6 @@ function apiTextParse(text, optionsContext) { return _apiInvoke('textParse', {text, optionsContext}); } -function apiTextParseMecab(text, optionsContext) { - return _apiInvoke('textParseMecab', {text, optionsContext}); -} - function apiKanjiFind(text, optionsContext) { return _apiInvoke('kanjiFind', {text, optionsContext}); } -- cgit v1.2.3