summaryrefslogtreecommitdiff
path: root/ext/js/pages
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-02-14 15:53:35 -0500
committerGitHub <noreply@github.com>2021-02-14 15:53:35 -0500
commit286534e648af350d24fbf3c7892a7ec81aaeb4bd (patch)
tree89d88e961c5a0a6f508c66789e30b9ba4a968e73 /ext/js/pages
parentefe8140f103179f50b610f182148b9427af99010 (diff)
Move api to yomichan object (#1392)
* Move cross frame API from API to Yomichan * Add API instance to Yomichan * Move api global to yomichan.api * Pass yomichan to API * Remove IIFE
Diffstat (limited to 'ext/js/pages')
-rw-r--r--ext/js/pages/action-popup-main.js16
-rw-r--r--ext/js/pages/info-main.js8
-rw-r--r--ext/js/pages/permissions-main.js4
-rw-r--r--ext/js/pages/welcome-main.js6
4 files changed, 13 insertions, 21 deletions
diff --git a/ext/js/pages/action-popup-main.js b/ext/js/pages/action-popup-main.js
index 99a76bdf..75dfb641 100644
--- a/ext/js/pages/action-popup-main.js
+++ b/ext/js/pages/action-popup-main.js
@@ -18,7 +18,6 @@
/* global
* HotkeyHelpController
* PermissionsUtil
- * api
*/
class DisplayController {
@@ -35,7 +34,7 @@ class DisplayController {
this._setupButtonEvents('.action-open-search', 'openSearchPage', chrome.runtime.getURL('/search.html'));
this._setupButtonEvents('.action-open-info', 'openInfoPage', chrome.runtime.getURL('/info.html'));
- const optionsFull = await api.optionsGetFull();
+ const optionsFull = await yomichan.api.optionsGetFull();
this._optionsFull = optionsFull;
this._setupHotkeys();
@@ -74,12 +73,12 @@ class DisplayController {
if (typeof command === 'string') {
node.addEventListener('click', (e) => {
if (e.button !== 0) { return; }
- api.commandExec(command, {mode: e.ctrlKey ? 'newTab' : 'existingOrNewTab'});
+ yomichan.api.commandExec(command, {mode: e.ctrlKey ? 'newTab' : 'existingOrNewTab'});
e.preventDefault();
}, false);
node.addEventListener('auxclick', (e) => {
if (e.button !== 1) { return; }
- api.commandExec(command, {mode: 'newTab'});
+ yomichan.api.commandExec(command, {mode: 'newTab'});
e.preventDefault();
}, false);
}
@@ -130,7 +129,7 @@ class DisplayController {
_setupOptions({options}) {
const extensionEnabled = options.general.enable;
- const onToggleChanged = () => api.commandExec('toggleTextScanning');
+ const onToggleChanged = () => yomichan.api.commandExec('toggleTextScanning');
for (const toggle of document.querySelectorAll('#enable-search,#enable-search2')) {
toggle.checked = extensionEnabled;
toggle.addEventListener('change', onToggleChanged, false);
@@ -178,7 +177,7 @@ class DisplayController {
}
async _setPrimaryProfileIndex(value) {
- return await api.modifySettings(
+ return await yomichan.api.modifySettings(
[{
action: 'set',
path: 'profileCurrent',
@@ -190,7 +189,7 @@ class DisplayController {
async _updateDictionariesEnabledWarnings(options) {
const noDictionariesEnabledWarnings = document.querySelectorAll('.no-dictionaries-enabled-warning');
- const dictionaries = await api.getDictionaryInfo();
+ const dictionaries = await yomichan.api.getDictionaryInfo();
let enabledCount = 0;
for (const {title} of dictionaries) {
@@ -221,10 +220,9 @@ class DisplayController {
}
(async () => {
- api.prepare();
await yomichan.prepare();
- api.logIndicatorClear();
+ yomichan.api.logIndicatorClear();
const displayController = new DisplayController();
displayController.prepare();
diff --git a/ext/js/pages/info-main.js b/ext/js/pages/info-main.js
index 7d34d47a..45c28d25 100644
--- a/ext/js/pages/info-main.js
+++ b/ext/js/pages/info-main.js
@@ -19,7 +19,6 @@
* BackupController
* DocumentFocusController
* SettingsController
- * api
*/
function getBrowserDisplayName(browser) {
@@ -54,12 +53,11 @@ function getOperatingSystemDisplayName(os) {
const manifest = chrome.runtime.getManifest();
const language = chrome.i18n.getUILanguage();
- api.prepare();
await yomichan.prepare();
const {userAgent} = navigator;
const {name, version} = manifest;
- const {browser, platform: {os}} = await api.getEnvironmentInfo();
+ const {browser, platform: {os}} = await yomichan.api.getEnvironmentInfo();
const thisVersionLink = document.querySelector('#release-notes-this-version-link');
thisVersionLink.href = thisVersionLink.dataset.hrefFormat.replace(/\{version\}/g, version);
@@ -73,7 +71,7 @@ function getOperatingSystemDisplayName(os) {
(async () => {
let ankiConnectVersion = null;
try {
- ankiConnectVersion = await api.getAnkiConnectVersion();
+ ankiConnectVersion = await yomichan.api.getAnkiConnectVersion();
} catch (e) {
// NOP
}
@@ -86,7 +84,7 @@ function getOperatingSystemDisplayName(os) {
(async () => {
let dictionaryInfos;
try {
- dictionaryInfos = await api.getDictionaryInfo();
+ dictionaryInfos = await yomichan.api.getDictionaryInfo();
} catch (e) {
return;
}
diff --git a/ext/js/pages/permissions-main.js b/ext/js/pages/permissions-main.js
index 7c0427b9..0cb37e93 100644
--- a/ext/js/pages/permissions-main.js
+++ b/ext/js/pages/permissions-main.js
@@ -19,12 +19,11 @@
* DocumentFocusController
* PermissionsToggleController
* SettingsController
- * api
*/
async function setupEnvironmentInfo() {
const {manifest_version: manifestVersion} = chrome.runtime.getManifest();
- const {browser, platform} = await api.getEnvironmentInfo();
+ const {browser, platform} = await yomichan.api.getEnvironmentInfo();
document.documentElement.dataset.browser = browser;
document.documentElement.dataset.os = platform.os;
document.documentElement.dataset.manifestVersion = `${manifestVersion}`;
@@ -69,7 +68,6 @@ function setupPermissionsToggles() {
node.textContent = chrome.runtime.getURL('/');
}
- api.prepare();
await yomichan.prepare();
setupEnvironmentInfo();
diff --git a/ext/js/pages/welcome-main.js b/ext/js/pages/welcome-main.js
index 626cbd3a..5a6bb2a5 100644
--- a/ext/js/pages/welcome-main.js
+++ b/ext/js/pages/welcome-main.js
@@ -25,12 +25,11 @@
* SettingsController
* SettingsDisplayController
* StatusFooter
- * api
*/
async function setupEnvironmentInfo() {
const {manifest_version: manifestVersion} = chrome.runtime.getManifest();
- const {browser, platform} = await api.getEnvironmentInfo();
+ const {browser, platform} = await yomichan.api.getEnvironmentInfo();
document.documentElement.dataset.browser = browser;
document.documentElement.dataset.os = platform.os;
document.documentElement.dataset.manifestVersion = `${manifestVersion}`;
@@ -49,12 +48,11 @@ async function setupGenericSettingsController(genericSettingController) {
const statusFooter = new StatusFooter(document.querySelector('.status-footer-container'));
statusFooter.prepare();
- api.prepare();
await yomichan.prepare();
setupEnvironmentInfo();
- const optionsFull = await api.optionsGetFull();
+ const optionsFull = await yomichan.api.optionsGetFull();
const preparePromises = [];