|
1 | 1 | // const deeplURL = "https://www.deepl.com/translator/q/auto/"
|
2 | 2 | const deeplURL = "https://www.deepl.com/translator#en/"
|
3 |
| -const w = 940; |
| 3 | +let w = 940; |
4 | 4 | const h = 650;
|
5 | 5 | let defaultLang = "en"
|
6 | 6 | let windowType = "popup"
|
@@ -32,7 +32,14 @@ browser.contextMenus.onClicked.addListener((info, tab) => {
|
32 | 32 | const querying = browser.tabs.query({ currentWindow: true, active: true });
|
33 | 33 | querying.then((current) => {
|
34 | 34 | 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; |
36 | 43 | const top = screen.height / 2 - h / 2;
|
37 | 44 |
|
38 | 45 | browser.windows.create({
|
@@ -67,7 +74,14 @@ browser.commands.onCommand.addListener(async command => {
|
67 | 74 | const translateURL = `${deeplURL + defaultLang}/${encodeURIComponent(text).replaceAll("%2F", "\\%2F").replaceAll("%7C", "\\%7C").replaceAll("%5C", "%5C%5C")}`;
|
68 | 75 |
|
69 | 76 | 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; |
71 | 85 | const top = screen.height / 2 - h / 2;
|
72 | 86 |
|
73 | 87 | browser.windows.create({
|
|
0 commit comments