From ac2e079c98f87acfbafd2105461885a1cb199c76 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Wed, 19 Jul 2017 21:41:30 -0700 Subject: cleanup --- ext/bg/background.html | 2 +- ext/bg/js/instance.js | 30 +++++++++++++++++++++++++ ext/bg/js/options.js | 1 - ext/bg/js/popup.js | 2 ++ ext/bg/js/util.js | 60 -------------------------------------------------- ext/bg/js/yomichan.js | 6 +++++ ext/bg/popup.html | 2 +- ext/bg/search.html | 2 +- ext/bg/settings.html | 2 +- 9 files changed, 42 insertions(+), 65 deletions(-) create mode 100644 ext/bg/js/instance.js delete mode 100644 ext/bg/js/util.js diff --git a/ext/bg/background.html b/ext/bg/background.html index 7d352561..de3cbf20 100644 --- a/ext/bg/background.html +++ b/ext/bg/background.html @@ -10,7 +10,7 @@ - + diff --git a/ext/bg/js/instance.js b/ext/bg/js/instance.js new file mode 100644 index 00000000..0df267cc --- /dev/null +++ b/ext/bg/js/instance.js @@ -0,0 +1,30 @@ +/* + * 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 instYomi() { + return chrome.extension.getBackgroundPage().yomichan; +} + +function instDb() { + return instYomi().translator.database; +} + +function instAnki() { + return instYomi().anki; +} diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js index a9345fdd..d611ae59 100644 --- a/ext/bg/js/options.js +++ b/ext/bg/js/options.js @@ -127,6 +127,5 @@ function optionsSave(options) { chrome.storage.local.set({options: JSON.stringify(options)}, resolve); }).then(() => { instYomi().optionsSet(options); - fgOptionsSet(options); }); } diff --git a/ext/bg/js/popup.js b/ext/bg/js/popup.js index 8577dd96..01994827 100644 --- a/ext/bg/js/popup.js +++ b/ext/bg/js/popup.js @@ -18,6 +18,8 @@ $(document).ready(() => { + const commandExec = command => instYomi().onCommand(command); + $('#open-search').click(() => commandExec('search')); $('#open-options').click(() => commandExec('options')); $('#open-help').click(() => commandExec('help')); diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js deleted file mode 100644 index c7ebbb0e..00000000 --- a/ext/bg/js/util.js +++ /dev/null @@ -1,60 +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 . - */ - - -/* - * Commands - */ - -function commandExec(command) { - instYomi().onCommand(command); -} - - -/* - * Instance - */ - -function instYomi() { - return chrome.extension.getBackgroundPage().yomichan; -} - -function instDb() { - return instYomi().translator.database; -} - -function instAnki() { - return instYomi().anki; -} - - -/* - * Foreground - */ - -function fgBroadcast(action, params) { - chrome.tabs.query({}, tabs => { - for (const tab of tabs) { - chrome.tabs.sendMessage(tab.id, {action, params}, () => null); - } - }); -} - -function fgOptionsSet(options) { - fgBroadcast('optionsSet', options); -} diff --git a/ext/bg/js/yomichan.js b/ext/bg/js/yomichan.js index eb083396..214bdef3 100644 --- a/ext/bg/js/yomichan.js +++ b/ext/bg/js/yomichan.js @@ -59,6 +59,12 @@ window.yomichan = new class { } else { this.anki = new AnkiNull(); } + + chrome.tabs.query({}, tabs => { + for (const tab of tabs) { + chrome.tabs.sendMessage(tab.id, {action: 'optionsSet', params: options}, () => null); + } + }); } noteFormat(definition, mode) { diff --git a/ext/bg/popup.html b/ext/bg/popup.html index b3d38533..baeb2ffb 100644 --- a/ext/bg/popup.html +++ b/ext/bg/popup.html @@ -30,7 +30,7 @@ - + diff --git a/ext/bg/search.html b/ext/bg/search.html index 45603f17..472907c2 100644 --- a/ext/bg/search.html +++ b/ext/bg/search.html @@ -33,7 +33,7 @@ - + diff --git a/ext/bg/settings.html b/ext/bg/settings.html index 4c7198c3..9c3995eb 100644 --- a/ext/bg/settings.html +++ b/ext/bg/settings.html @@ -276,7 +276,7 @@ - + -- cgit v1.2.3