-
Notifications
You must be signed in to change notification settings - Fork 25
Update privateTabs.uc.js fix for Firefox Nightly 141 #115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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); | ||
| }; | ||
|
Comment on lines
+414
to
+418
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's PlacesUIUtils, not PlacesUtils. there is no also, as far as I can tell, there's no reason the original version on the left wouldn't work. unless you have |
||
| } | ||
|
|
||
| const { WebExtensionPolicy } = Cu.getGlobalForObject(Services); | ||
|
|
@@ -527,16 +523,25 @@ class PrivateTabManager { | |
| return newTab; | ||
| } | ||
|
|
||
| togglePrivate(tab = gBrowser.selectedTab) { | ||
| tab.isToggling = true; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why remove this?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was the only way I found to get the script working again😅 |
||
| 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, | ||
|
Comment on lines
+532
to
+535
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't restore the tab state. You'll lose tab history. You should be using |
||
| }); | ||
| if (shouldSelect && gURLBar.focused) gURLBar.focus(); | ||
|
|
||
| if (tab == gBrowser.selectedTab) { | ||
| gBrowser.selectedTab = newTab; | ||
| if (gURLBar.focused) gURLBar.focus(); | ||
| } | ||
|
Comment on lines
+538
to
+541
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should save this before you open/duplicate the tab. Like at line 531. |
||
|
|
||
| gBrowser.removeTab(tab, { animate: false, closeWindowWithLastTab: false }); | ||
| } | ||
| } | ||
|
|
||
| toggleMask() { | ||
| let privateMask = document.querySelector( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't work. Neither of these properties are exported, they're hidden in the code and not available to outside callers, so they can't be imported by
importESModule. Like I said in the other thread, you'd need to change theduplicateTabcode so it usesSessionStore.duplicateTab, like xiaoxiaoflood's version. Then your code doesn't rely onSessionStoreInternalorTAB_CUSTOM_VALUES. But that has trade-offs.