Skip to content

Commit 8631c1e

Browse files
authored
Merge pull request #41 from qurikuduo/master
Increase initial width of the popup window to 1200px if the screen width is large then 1200px.
2 parents 5c02b4c + e3f4b11 commit 8631c1e

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/background.js

+17-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// const deeplURL = "https://www.deepl.com/translator/q/auto/"
22
const deeplURL = "https://www.deepl.com/translator#en/"
3-
const w = 940;
3+
let w = 940;
44
const h = 650;
55
let defaultLang = "en"
66
let windowType = "popup"
@@ -32,7 +32,14 @@ browser.contextMenus.onClicked.addListener((info, tab) => {
3232
const querying = browser.tabs.query({ currentWindow: true, active: true });
3333
querying.then((current) => {
3434
if (windowType === 'popup') {
35-
const left = screen.width / 2 - w / 2;
35+
// give popup window more space if screen is wide,
36+
// so the translated text is along side with the original text
37+
if (screen.width >= 1200) {
38+
w = 1200;
39+
} else {
40+
w = screen.width;
41+
}
42+
const left = (screen.width - w) / 2;
3643
const top = screen.height / 2 - h / 2;
3744

3845
browser.windows.create({
@@ -67,7 +74,14 @@ browser.commands.onCommand.addListener(async command => {
6774
const translateURL = `${deeplURL + defaultLang}/${encodeURIComponent(text).replaceAll("%2F", "\\%2F").replaceAll("%7C", "\\%7C").replaceAll("%5C", "%5C%5C")}`;
6875

6976
if (windowType === 'popup') {
70-
const left = screen.width / 2 - w / 2;
77+
// give popup window more space if screen is wide,
78+
// so the translated text is along side with the original text
79+
if (screen.width >= 1200) {
80+
w = 1200;
81+
} else {
82+
w = screen.width;
83+
}
84+
const left = (screen.width - w) / 2;
7185
const top = screen.height / 2 - h / 2;
7286

7387
browser.windows.create({

0 commit comments

Comments
 (0)