diff --git a/ext/bg/css/settings2.css b/ext/bg/css/settings2.css
index b41ea7ea..fe9f0e6b 100644
--- a/ext/bg/css/settings2.css
+++ b/ext/bg/css/settings2.css
@@ -230,7 +230,7 @@ h3 {
font-size: calc(1em / 1.125);
color: var(--text-color-light);
}
-.heading-link-light {
+a.heading-link-light {
color: var(--text-color-light);
}
.heading-description,
diff --git a/ext/bg/data/options-schema.json b/ext/bg/data/options-schema.json
index 405d62a9..def279cc 100644
--- a/ext/bg/data/options-schema.json
+++ b/ext/bg/data/options-schema.json
@@ -63,6 +63,7 @@
"type": "object",
"required": [
"general",
+ "popupWindow",
"audio",
"scanning",
"translation",
@@ -288,6 +289,57 @@
}
}
},
+ "popupWindow": {
+ "type": "object",
+ "required": [
+ "width",
+ "height",
+ "left",
+ "top",
+ "useLeft",
+ "useTop",
+ "windowType",
+ "windowState"
+ ],
+ "properties": {
+ "width": {
+ "type": "integer",
+ "minimum": 0,
+ "default": 400
+ },
+ "height": {
+ "type": "integer",
+ "minimum": 0,
+ "default": 250
+ },
+ "left": {
+ "type": "integer",
+ "default": 0
+ },
+ "top": {
+ "type": "integer",
+ "default": 0
+ },
+ "useLeft": {
+ "type": "boolean",
+ "default": false
+ },
+ "useTop": {
+ "type": "boolean",
+ "default": false
+ },
+ "windowType": {
+ "type": "string",
+ "enum": ["normal", "popup"],
+ "default": "popup"
+ },
+ "windowState": {
+ "type": "string",
+ "enum": ["normal", "maximized", "fullscreen"],
+ "default": "normal"
+ }
+ }
+ },
"audio": {
"type": "object",
"required": [
diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js
index 11a17381..d5e5b086 100644
--- a/ext/bg/js/backend.js
+++ b/ext/bg/js/backend.js
@@ -818,25 +818,12 @@ class Backend {
// Create a new window
const options = this.getOptions({current: true});
- const {popupWidth, popupHeight} = options.general;
- const popupWindow = await new Promise((resolve, reject) => {
- chrome.windows.create(
- {
- url: baseUrl,
- width: popupWidth,
- height: popupHeight,
- type: 'popup'
- },
- (result) => {
- const error = chrome.runtime.lastError;
- if (error) {
- reject(new Error(error.message));
- } else {
- resolve(result);
- }
- }
- );
- });
+ const createData = this._getSearchPopupWindowCreateData(baseUrl, options);
+ const {popupWindow: {windowState}} = options;
+ const popupWindow = await this._createWindow(createData);
+ if (windowState !== 'normal') {
+ await this._updateWindow(popupWindow.id, {state: windowState});
+ }
const {tabs} = popupWindow;
if (tabs.length === 0) {
@@ -856,6 +843,52 @@ class Backend {
return {tab, created: true};
}
+ _getSearchPopupWindowCreateData(url, options) {
+ const {popupWindow: {width, height, left, top, useLeft, useTop, windowType}} = options;
+ return {
+ url,
+ width,
+ height,
+ left: useLeft ? left : void 0,
+ top: useTop ? top : void 0,
+ type: windowType,
+ state: 'normal'
+ };
+ }
+
+ _createWindow(createData) {
+ return new Promise((resolve, reject) => {
+ chrome.windows.create(
+ createData,
+ (result) => {
+ const error = chrome.runtime.lastError;
+ if (error) {
+ reject(new Error(error.message));
+ } else {
+ resolve(result);
+ }
+ }
+ );
+ });
+ }
+
+ _updateWindow(windowId, updateInfo) {
+ return new Promise((resolve, reject) => {
+ chrome.windows.update(
+ windowId,
+ updateInfo,
+ (result) => {
+ const error = chrome.runtime.lastError;
+ if (error) {
+ reject(new Error(error.message));
+ } else {
+ resolve(result);
+ }
+ }
+ );
+ });
+ }
+
_updateSearchQuery(tabId, text, animate) {
return this._sendMessageTabPromise(
tabId,
diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js
index 964c346c..026d75c5 100644
--- a/ext/bg/js/options.js
+++ b/ext/bg/js/options.js
@@ -689,6 +689,7 @@ class OptionsUtil {
// Changed general.popupActionBarLocation.
// Added inputs.hotkeys.
// Added anki.suspendNewCards.
+ // Added popupWindow.
for (const profile of options.profiles) {
profile.options.translation.textReplacements = {
searchOriginal: true,
@@ -735,6 +736,16 @@ class OptionsUtil {
]
};
profile.options.anki.suspendNewCards = false;
+ profile.options.popupWindow = {
+ width: profile.options.general.popupWidth,
+ height: profile.options.general.popupHeight,
+ left: 0,
+ top: 0,
+ useLeft: false,
+ useTop: false,
+ windowType: 'popup',
+ windowState: 'normal'
+ };
}
return options;
}
diff --git a/ext/bg/js/settings/generic-setting-controller.js b/ext/bg/js/settings/generic-setting-controller.js
index 0d24c429..7d6fc2e6 100644
--- a/ext/bg/js/settings/generic-setting-controller.js
+++ b/ext/bg/js/settings/generic-setting-controller.js
@@ -36,6 +36,7 @@ class GenericSettingController {
['splitTags', this._splitTags.bind(this)],
['joinTags', this._joinTags.bind(this)],
['toNumber', this._toNumber.bind(this)],
+ ['toBoolean', this._toBoolean.bind(this)],
['toString', this._toString.bind(this)],
['conditionalConvert', this._conditionalConvert.bind(this)]
]);
@@ -206,6 +207,10 @@ class GenericSettingController {
return DOMDataBinder.convertToNumber(value, constraints);
}
+ _toBoolean(value) {
+ return (value === 'true');
+ }
+
_toString(value) {
return `${value}`;
}
diff --git a/ext/bg/js/settings2/popup-window-controller.js b/ext/bg/js/settings2/popup-window-controller.js
new file mode 100644
index 00000000..cc83db68
--- /dev/null
+++ b/ext/bg/js/settings2/popup-window-controller.js
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2021 Yomichan Authors
+ *
+ * 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