diff options
-rw-r--r-- | ext/bg/background.html | 1 | ||||
-rw-r--r-- | ext/bg/js/database.js | 12 | ||||
-rw-r--r-- | ext/bg/js/deinflector.js | 14 | ||||
-rw-r--r-- | ext/bg/js/gecko.js | 16 | ||||
-rw-r--r-- | ext/bg/js/translator.js | 14 | ||||
-rw-r--r-- | ext/bg/js/util.js | 19 | ||||
m--------- | ext/bg/lang/data | 0 | ||||
-rw-r--r-- | ext/bg/options.html | 1 | ||||
-rw-r--r-- | ext/fg/js/driver.js | 6 | ||||
-rw-r--r-- | ext/fg/js/gecko.js | 12 | ||||
-rw-r--r-- | ext/manifest.json | 8 |
11 files changed, 70 insertions, 33 deletions
diff --git a/ext/bg/background.html b/ext/bg/background.html index 3ecfa3dc..625917ef 100644 --- a/ext/bg/background.html +++ b/ext/bg/background.html @@ -4,6 +4,7 @@ <script src="../lib/handlebars.min.js"></script> <script src="../lib/dexie.min.js"></script> <script src="../lib/wanakana.min.js"></script> + <script src="js/gecko.js"></script> <script src="js/ankiconnect.js"></script> <script src="js/ankinull.js"></script> <script src="js/templates.js"></script> diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js index 31573065..3b2bcfcb 100644 --- a/ext/bg/js/database.js +++ b/ext/bg/js/database.js @@ -87,7 +87,7 @@ class Database { }).then(() => { return this.cacheTagMeta(dictionaries); }).then(() => { - for (const result of results) { + for (let result of results) { result.tagMeta = this.tagMetaCache[result.dictionary] || {}; } @@ -115,7 +115,7 @@ class Database { }).then(() => { return this.cacheTagMeta(dictionaries); }).then(() => { - for (const result of results) { + for (let result of results) { result.tagMeta = this.tagMetaCache[result.dictionary] || {}; } @@ -129,7 +129,7 @@ class Database { } const promises = []; - for (const dictionary of dictionaries) { + for (let dictionary of dictionaries) { if (this.tagMetaCache[dictionary]) { continue; } @@ -170,7 +170,7 @@ class Database { return this.db.dictionaries.add({title, version, revision, hasTerms, hasKanji}).then(() => { const rows = []; - for (const tag in tagMeta || {}) { + for (let tag in tagMeta || {}) { const meta = tagMeta[tag]; const row = sanitizeTag({ name: tag, @@ -190,7 +190,7 @@ class Database { const termsLoaded = (title, entries, total, current) => { const rows = []; - for (const [expression, reading, tags, rules, score, ...glossary] of entries) { + for (let [expression, reading, tags, rules, score, ...glossary] of entries) { rows.push({ expression, reading, @@ -211,7 +211,7 @@ class Database { const kanjiLoaded = (title, entries, total, current) => { const rows = []; - for (const [character, onyomi, kunyomi, tags, ...meanings] of entries) { + for (let [character, onyomi, kunyomi, tags, ...meanings] of entries) { rows.push({ character, onyomi, diff --git a/ext/bg/js/deinflector.js b/ext/bg/js/deinflector.js index 6e480068..256ae1a1 100644 --- a/ext/bg/js/deinflector.js +++ b/ext/bg/js/deinflector.js @@ -32,8 +32,8 @@ class Deinflection { if (this.rules.length === 0) { this.definitions = definitions; } else { - for (const rule of this.rules) { - for (const definition of definitions) { + for (let rule of this.rules) { + for (let definition of definitions) { if (definition.rules.includes(rule)) { this.definitions.push(definition); } @@ -46,11 +46,11 @@ class Deinflection { }; const promises = []; - for (const reason in reasons) { - for (const variant of reasons[reason]) { + for (let reason in reasons) { + for (let variant of reasons[reason]) { let accept = this.rules.length === 0; if (!accept) { - for (const rule of this.rules) { + for (let rule of this.rules) { if (variant.rulesIn.includes(rule)) { accept = true; break; @@ -95,8 +95,8 @@ class Deinflection { } const results = []; - for (const child of this.children) { - for (const result of child.gather()) { + for (let child of this.children) { + for (let result of child.gather()) { if (this.reason.length > 0) { result.reasons.push(this.reason); } diff --git a/ext/bg/js/gecko.js b/ext/bg/js/gecko.js new file mode 100644 index 00000000..f055e163 --- /dev/null +++ b/ext/bg/js/gecko.js @@ -0,0 +1,16 @@ +// +// Gecko does not currently support chrome.storage.sync, use storage.local instead +// https://bugzilla.mozilla.org/show_bug.cgi?id=1220494 +if (!chrome.storage.sync) { + chrome.storage.sync = chrome.storage.local; +} + +// Gecko does not currently support chrome.runtime.onInstalled, just ignore calls to it +// (https://bugzilla.mozilla.org/show_bug.cgi?id=1252871) +if (!chrome.runtime.onInstalled) { + chrome.runtime.onInstalled = { + 'addListener' : function(){}, + 'hasListener' : function(){}, + 'removeListener' : function(){} + }; +} diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index e7c2aac2..82dffd91 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -54,8 +54,8 @@ class Translator { } }).then(deinflections => { let definitions = []; - for (const deinflection of deinflections) { - for (const definition of deinflection.definitions) { + for (let deinflection of deinflections) { + for (let definition of deinflection.definitions) { const tags = definition.tags.map(tag => buildTag(tag, definition.tagMeta)); tags.push(buildDictTag(definition.dictionary)); definitions.push({ @@ -76,7 +76,7 @@ class Translator { definitions = sortTermDefs(definitions, dictionaries); let length = 0; - for (const definition of definitions) { + for (let definition of definitions) { length = Math.max(length, definition.source.length); } @@ -95,7 +95,7 @@ class Translator { const processed = {}; const promises = []; - for (const c of text) { + for (let c of text) { if (!processed[c]) { promises.push(this.database.findKanji(c, titles)); processed[c] = true; @@ -104,7 +104,7 @@ class Translator { return Promise.all(promises).then(defSets => { const definitions = defSets.reduce((a, b) => a.concat(b), []); - for (const definition of definitions) { + for (let definition of definitions) { const tags = definition.tags.map(tag => buildTag(tag, definition.tagMeta)); tags.push(buildDictTag(definition.dictionary)); definition.tags = sortTags(tags); @@ -130,7 +130,7 @@ class Translator { return Promise.all(promises).then(results => { let deinflections = []; - for (const result of results) { + for (let result of results) { deinflections = deinflections.concat(result); } @@ -139,7 +139,7 @@ class Translator { } processKanji(definitions) { - for (const definition of definitions) { + for (let definition of definitions) { const tags = definition.tags.map(tag => buildTag(tag, definition.tagMeta)); definition.tags = sortTags(tags); } diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js index 108c88e7..24050cf3 100644 --- a/ext/bg/js/util.js +++ b/ext/bg/js/util.js @@ -19,7 +19,7 @@ function kanjiLinks(options) { let result = ''; - for (const c of options.fn(this)) { + for (let c of options.fn(this)) { if (isKanji(c)) { result += `<a href="#" class="kanji-link">${c}</a>`; } else { @@ -41,7 +41,7 @@ function isKanji(c) { function enabledDicts(options) { const dictionaries = {}; - for (const title in options.dictionaries) { + for (let title in options.dictionaries) { const dictionary = options.dictionaries[title]; if (dictionary.enabled) { dictionaries[title] = dictionary; @@ -104,7 +104,7 @@ function sortTermDefs(definitions, dictionaries=null) { function undupeTermDefs(definitions) { const definitionGroups = {}; - for (const definition of definitions) { + for (let definition of definitions) { const definitionExisting = definitionGroups[definition.id]; if (!definitionGroups.hasOwnProperty(definition.id) || definition.expression.length > definitionExisting.expression.length) { definitionGroups[definition.id] = definition; @@ -112,7 +112,7 @@ function undupeTermDefs(definitions) { } const definitionsUnique = []; - for (const key in definitionGroups) { + for (let key in definitionGroups) { definitionsUnique.push(definitionGroups[key]); } @@ -121,7 +121,7 @@ function undupeTermDefs(definitions) { function groupTermDefs(definitions, dictionaries) { const groups = {}; - for (const definition of definitions) { + for (let definition of definitions) { const key = [definition.source, definition.expression].concat(definition.reasons); if (definition.reading) { key.push(definition.reading); @@ -136,7 +136,7 @@ function groupTermDefs(definitions, dictionaries) { } const results = []; - for (const key in groups) { + for (let key in groups) { const groupDefs = groups[key]; const firstDef = groupDefs[0]; sortTermDefs(groupDefs, dictionaries); @@ -160,7 +160,7 @@ function buildDictTag(name) { function buildTag(name, meta) { const tag = {name}; const symbol = name.split(':')[0]; - for (const prop in meta[symbol] || {}) { + for (let prop in meta[symbol] || {}) { tag[prop] = meta[symbol][prop]; } @@ -217,7 +217,7 @@ function formatField(field, definition, mode, options) { 'url' ]; - for (const marker of markers) { + for (let marker of markers) { const data = { marker, definition, @@ -240,6 +240,7 @@ function formatField(field, definition, mode, options) { function loadJson(url) { return new Promise((resolve, reject) => { const xhr = new XMLHttpRequest(); + xhr.overrideMimeType('application/json'); xhr.addEventListener('load', () => resolve(xhr.responseText)); xhr.addEventListener('error', () => reject('failed to execute network request')); xhr.open('GET', url); @@ -303,7 +304,7 @@ function importJsonDb(indexUrl, indexLoaded, termsLoaded, kanjiLoaded) { } let chain = Promise.resolve(); - for (const loader of loaders) { + for (let loader of loaders) { chain = chain.then(loader); } diff --git a/ext/bg/lang/data b/ext/bg/lang/data -Subproject f149a6d54df57e7dfd1e6ebbabab1ef4c2a86a6 +Subproject a9f34826ab9be977338efa6efab8064978fa464 diff --git a/ext/bg/options.html b/ext/bg/options.html index e22e9698..d6eeb121 100644 --- a/ext/bg/options.html +++ b/ext/bg/options.html @@ -241,6 +241,7 @@ <script src="../lib/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script> <script src="../lib/handlebars.min.js"></script> <script src="js/templates.js"></script> + <script src="js/gecko.js"></script> <script src="js/options.js"></script> <script src="js/options-form.js"></script> </body> diff --git a/ext/fg/js/driver.js b/ext/fg/js/driver.js index 3b4c0c76..9d972abf 100644 --- a/ext/fg/js/driver.js +++ b/ext/fg/js/driver.js @@ -62,9 +62,9 @@ class Driver { return; } - if (e.which === 1 /* lmb */) { - return; - } + // if (e.which === 1 /* lmb */) { + // return; + // } if (this.options.scanning.requireShift && !e.shiftKey) { return; diff --git a/ext/fg/js/gecko.js b/ext/fg/js/gecko.js new file mode 100644 index 00000000..21671749 --- /dev/null +++ b/ext/fg/js/gecko.js @@ -0,0 +1,12 @@ +if (!document.caretRangeFromPoint){ + document.caretRangeFromPoint = function polyfillcaretRangeFromPoint(x,y){ + let range = document.createRange(); + let position = document.caretPositionFromPoint(x,y); + if (!position) { + return null; + } + range.setStart(position.offsetNode, position.offset); + range.setEnd(position.offsetNode, position.offset); + return range; + }; +} diff --git a/ext/manifest.json b/ext/manifest.json index 73b7cc8d..1de5a5c1 100644 --- a/ext/manifest.json +++ b/ext/manifest.json @@ -12,6 +12,7 @@ "content_scripts": [{ "matches": ["*://*/*", "file://*/*"], "js": [ + "fg/js/gecko.js", "fg/js/source-range.js", "fg/js/source-element.js", "fg/js/popup.js", @@ -41,5 +42,10 @@ "fg/mp3/button.mp3", "fg/ttf/kanji-stroke-orders.ttf", "fg/ttf/vl-gothic-regular.ttf" - ] + ], + "applications": { + "gecko": { + "id": "alex@foosoft.net" + } + } } |