From edf1c0ff6d9eadd17c98f00ef027c27d1b89a8ee Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 22 Jul 2017 23:19:38 -0700 Subject: cleanup --- ext/fg/frame.html | 2 +- ext/fg/js/api.js | 63 ++++++++++++++++++++++++++++++++++++++++++++++ ext/fg/js/background.js | 63 ---------------------------------------------- ext/fg/js/display-frame.js | 10 ++++---- ext/fg/js/frontend.js | 6 ++--- ext/manifest.json | 2 +- 6 files changed, 73 insertions(+), 73 deletions(-) create mode 100644 ext/fg/js/api.js delete mode 100644 ext/fg/js/background.js diff --git a/ext/fg/frame.html b/ext/fg/frame.html index 80e69967..9ff2c585 100644 --- a/ext/fg/frame.html +++ b/ext/fg/frame.html @@ -35,7 +35,7 @@ - + diff --git a/ext/fg/js/api.js b/ext/fg/js/api.js new file mode 100644 index 00000000..e252637e --- /dev/null +++ b/ext/fg/js/api.js @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2016 Alex Yatskov + * Author: Alex Yatskov + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +function apiInvoke(action, params={}) { + return new Promise((resolve, reject) => { + try { + chrome.runtime.sendMessage({action, params}, ({result, error}) => { + if (error) { + reject(error); + } else { + resolve(result); + } + }); + } catch (e) { + window.yomichanOrphaned = true; + reject(e.message); + } + }); +} + +function apiOptionsGet() { + return apiInvoke('optionsGet'); +} + +function apiTermsFind(text) { + return apiInvoke('termsFind', {text}); +} + +function apiKanjiFind(text) { + return apiInvoke('kanjiFind', {text}); +} + +function apiTemplateRender(template, data) { + return apiInvoke('templateRender', {data, template}); +} + +function apiDefinitionsAddable(definitions, modes) { + return apiInvoke('definitionsAddable', {definitions, modes}).catch(() => null); +} + +function apiDefinitionAdd(definition, mode) { + return apiInvoke('definitionAdd', {definition, mode}); +} + +function apiNoteView(noteId) { + return apiInvoke('noteView', {noteId}); +} diff --git a/ext/fg/js/background.js b/ext/fg/js/background.js deleted file mode 100644 index c072468b..00000000 --- a/ext/fg/js/background.js +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2016 Alex Yatskov - * Author: Alex Yatskov - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - - -function bgInvoke(action, params={}) { - return new Promise((resolve, reject) => { - try { - chrome.runtime.sendMessage({action, params}, ({result, error}) => { - if (error) { - reject(error); - } else { - resolve(result); - } - }); - } catch (e) { - window.yomichanOrphaned = true; - reject(e.message); - } - }); -} - -function bgOptionsGet() { - return bgInvoke('optionsGet'); -} - -function bgTermsFind(text) { - return bgInvoke('termsFind', {text}); -} - -function bgKanjiFind(text) { - return bgInvoke('kanjiFind', {text}); -} - -function bgTemplateRender(template, data) { - return bgInvoke('templateRender', {data, template}); -} - -function bgDefinitionsAddable(definitions, modes) { - return bgInvoke('definitionsAddable', {definitions, modes}).catch(() => null); -} - -function bgDefinitionAdd(definition, mode) { - return bgInvoke('definitionAdd', {definition, mode}); -} - -function bgNoteView(noteId) { - return bgInvoke('noteView', {noteId}); -} diff --git a/ext/fg/js/display-frame.js b/ext/fg/js/display-frame.js index c7da43e8..09bd9255 100644 --- a/ext/fg/js/display-frame.js +++ b/ext/fg/js/display-frame.js @@ -24,23 +24,23 @@ window.displayFrame = new class extends Display { } definitionAdd(definition, mode) { - return bgDefinitionAdd(definition, mode); + return apiDefinitionAdd(definition, mode); } definitionsAddable(definitions, modes) { - return bgDefinitionsAddable(definitions, modes); + return apiDefinitionsAddable(definitions, modes); } noteView(noteId) { - return bgNoteView(noteId); + return apiNoteView(noteId); } templateRender(template, data) { - return bgTemplateRender(template, data); + return apiTemplateRender(template, data); } kanjiFind(character) { - return bgKanjiFind(character); + return apiKanjiFind(character); } handleError(error) { diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js index 8b4c182c..9974d878 100644 --- a/ext/fg/js/frontend.js +++ b/ext/fg/js/frontend.js @@ -28,7 +28,7 @@ window.yomichanFrontend = new class { this.pendingLookup = false; this.options = null; - bgOptionsGet().then(options => { + apiOptionsGet().then(options => { this.options = options; window.addEventListener('mouseover', this.onMouseOver.bind(this)); window.addEventListener('mousedown', this.onMouseDown.bind(this)); @@ -175,7 +175,7 @@ window.yomichanFrontend = new class { searchTerms(textSource) { textSource.setEndOffset(this.options.scanning.length); - return bgTermsFind(textSource.text()).then(({definitions, length}) => { + return apiTermsFind(textSource.text()).then(({definitions, length}) => { if (definitions.length === 0) { return false; } else { @@ -203,7 +203,7 @@ window.yomichanFrontend = new class { searchKanji(textSource) { textSource.setEndOffset(1); - return bgKanjiFind(textSource.text()).then(definitions => { + return apiKanjiFind(textSource.text()).then(definitions => { if (definitions.length === 0) { return false; } else { diff --git a/ext/manifest.json b/ext/manifest.json index a318e539..288976f3 100644 --- a/ext/manifest.json +++ b/ext/manifest.json @@ -18,7 +18,7 @@ "fg/js/document.js", "fg/js/source-range.js", "fg/js/source-element.js", - "fg/js/background.js", + "fg/js/api.js", "fg/js/popup.js", "fg/js/frontend.js" ], -- cgit v1.2.3