MCPcopy Create free account
hub / github.com/Useful-Scripts-Extension/useful-script / initOpenInNewTab

Function initOpenInNewTab

popup/index.js:683–730  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

681}, 500);
682
683async 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
732function initSettings() {
733 settingsBtn.onclick = () => {

Callers 1

index.jsFile · 0.85

Calls 3

trackEventFunction · 0.90
updateMethod · 0.80
removeMethod · 0.45

Tested by

no test coverage detected