diff --git a/JS/privateTabs.uc.js b/JS/privateTabs.uc.js index 0c9f329..f81ca4b 100644 --- a/JS/privateTabs.uc.js +++ b/JS/privateTabs.uc.js @@ -1,6 +1,6 @@ // ==UserScript== // @name Private Tabs -// @version 1.4.1 +// @version 1.4.2 // @author aminomancer // @homepage https://github.com/aminomancer // @description An fx-autoconfig port of [Private Tab](https://github.com/xiaoxiaoflood/firefox-scripts/blob/master/chrome/privateTab.uc.js) by xiaoxiaoflood. Adds buttons and menu items allowing you to open a "private tab" in nearly any circumstance in which you'd be able to open a normal tab. Instead of opening a link in a private window, you can open it in a private tab instead. This will use a special container and prevent history storage, depending on user configuration. You can also toggle tabs back and forth between private and normal mode. This script adds two hotkeys: Ctrl+Alt+P to open a new private tab, and Ctrl+Alt+T to toggle private mode for the active tab. These hotkeys can be configured along with several other options at the top of the script file. @@ -61,9 +61,8 @@ class PrivateTabManager { // to addTrustedTab. so we need to make our own function, which requires us // to access some private objects. // eslint-disable-next-line mozilla/use-chromeutils-import - let { SessionStoreInternal, TAB_CUSTOM_VALUES } = Cu.import( - "resource:///modules/sessionstore/SessionStore.jsm" - ); + let { SessionStoreInternal, TAB_CUSTOM_VALUES } = + ChromeUtils.importESModule("resource:///modules/sessionstore/SessionStore.sys.mjs"); this.SSI = SessionStoreInternal; this.TAB_CUSTOM_VALUES = TAB_CUSTOM_VALUES; ChromeUtils.defineESModuleGetters(this, { @@ -411,15 +410,12 @@ class PrivateTabManager { ? aWindow : lazy.BrowserWindowTracker.getTopWindow(); } - let openTabsetString = PlacesUIUtils.openTabset.toString(); - eval( - `PlacesUIUtils.openTabset = ${ - openTabsetString.startsWith("function") ? "" : "function " - }${openTabsetString.replace( - /(\s+)(inBackground: loadInBackground,)/, - "$1$2$1userContextId: aEvent.userContextId || 0," - )}` - ); + let originalOpenTabset = PlacesUtils.openTabset; + lazy.PlacesUtils.openTabset = function(aURIs, aOptions) { + aOptions = aOptions || {}; + aOptions.userContextId = aOptions.userContextId || 0; + originalOpenTabset.call(this, aURIs, aOptions); + }; } const { WebExtensionPolicy } = Cu.getGlobalForObject(Services); @@ -527,16 +523,25 @@ class PrivateTabManager { return newTab; } - togglePrivate(tab = gBrowser.selectedTab) { - tab.isToggling = true; - let shouldSelect = tab == gBrowser.selectedTab; - this.duplicateTab(tab, { - index: shouldSelect ? tab._tPos + 1 : tab._tPos, - inBackground: !shouldSelect, +togglePrivate(tab = gBrowser.selectedTab) { + let isCurrentlyPrivate = this.isPrivate(tab); + let targetUserContextId = isCurrentlyPrivate ? 0 : this.container.userContextId; + + let urlToOpen = tab.linkedBrowser.currentURI.spec; + + let newTab = openTrustedLinkIn(urlToOpen, "tab", { + userContextId: targetUserContextId, + index: tab._tPos + 1, + inBackground: tab != gBrowser.selectedTab, }); - if (shouldSelect && gURLBar.focused) gURLBar.focus(); + + if (tab == gBrowser.selectedTab) { + gBrowser.selectedTab = newTab; + if (gURLBar.focused) gURLBar.focus(); + } + gBrowser.removeTab(tab, { animate: false, closeWindowWithLastTab: false }); - } +} toggleMask() { let privateMask = document.querySelector(