()
| 681 | }, 500); |
| 682 | |
| 683 | async function initOpenInNewTab() { |
| 684 | if (!chrome?.tabs) return; |
| 685 | |
| 686 | let currentTab = await chrome.tabs.getCurrent(); |
| 687 | isInNewTab = currentTab != null; |
| 688 | |
| 689 | if (isInNewTab) { |
| 690 | [ |
| 691 | ["tabs", "onHighlighted"], |
| 692 | ["windows", "onFocusChanged"], |
| 693 | ].forEach(([context, event]) => { |
| 694 | chrome[context][event].addListener(updateTargetTab); |
| 695 | }); |
| 696 | |
| 697 | openInNewTabBtn.remove(); |
| 698 | return; |
| 699 | } |
| 700 | |
| 701 | openInNewTabBtn.onclick = async () => { |
| 702 | const exist = await chrome.tabs.query({ |
| 703 | url: location.href, |
| 704 | }); |
| 705 | if (exist.length > 0) { |
| 706 | chrome.windows.update(exist[0].windowId, { focused: true }); |
| 707 | window.close(); |
| 708 | return; |
| 709 | } |
| 710 | |
| 711 | trackEvent("CLICK_OPEN_IN_NEW_TAB"); |
| 712 | |
| 713 | let width = window.outerWidth, |
| 714 | height = window.outerHeight, |
| 715 | left = window.screenLeft, |
| 716 | top = window.screenTop; |
| 717 | |
| 718 | await chrome.windows.create({ |
| 719 | url: location.href, |
| 720 | type: "popup", |
| 721 | height, |
| 722 | width, |
| 723 | left, |
| 724 | top, |
| 725 | setSelfAsOpener: true, |
| 726 | }); |
| 727 | |
| 728 | window.close(); |
| 729 | }; |
| 730 | } |
| 731 | |
| 732 | function initSettings() { |
| 733 | settingsBtn.onclick = () => { |
no test coverage detected