xiaoxiaoflood / firefox-scripts

userChromeJS / autoconfig.js and extensions
Mozilla Public License 2.0
1.02k stars 86 forks source link

Private tab script not working since Firefox 119 #290

Closed kaos-55 closed 6 months ago

kaos-55 commented 11 months ago

I recently noticed that the private tabs script does not work specifically since Firefox version 119. The button appears and the private container is created, however the sites are still saved in the history. I know that this repository is apparently "abandoned" by the developer, but if anyone knows a way to fix it I would appreciate if you could post the solution.

Sneakpeakcss commented 11 months ago

at line 142 change this:

-let privateMask = document.getElementsByClassName('private-browsing-indicator')[0];
+let privateMask = document.getElementsByClassName('private-browsing-indicator-icon')[0];
kaos-55 commented 11 months ago

Holy... Thank you so much, it seems that the script is working again, although the private browsing icon does not appear in the tab bar, it is a minor detail.

Sneakpeakcss commented 11 months ago

Holy... Thank you so much, it seems that the script is working again, although the private browsing icon does not appear in the tab bar, it is a minor detail.


@@ -139,8 +139,8 @@
     document.getElementById('context_pinTab').insertAdjacentElement('afterend', toggleTab);
     document.getElementById('tabContextMenu').addEventListener('popupshowing', this.tabContext);

-    let privateMask = document.getElementsByClassName('private-browsing-indicator')[0];
-    privateMask.id = 'private-mask';
+    let privateMask = document.getElementById('private-browsing-indicator-with-label');
+    privateMask.classList.add("private-mask");

     let btn2 = _uc.createElement(document, 'toolbarbutton', {
       id: this.BTN2_ID,
@@ -375,7 +375,7 @@

   toggleMask: function (win) {
     let {gBrowser} = win;
-    let privateMask = win.document.getElementById('private-mask');
+    let privateMask = win.document.getElementsByClassName('private-mask')[0];
     if (gBrowser.selectedTab.isToggling)
       privateMask.setAttribute('enabled', gBrowser.selectedTab.userContextId == this.container.userContextId ? 'false' : 'true');
     else
@@ -457,8 +457,8 @@
     this.STYLE = {
       url: Services.io.newURI('data:text/css;charset=UTF-8,' + encodeURIComponent(`
         @-moz-document url('${_uc.BROWSERCHROME}'), url-prefix('chrome://browser/content/places/') {
-          #private-mask[enabled="true"] {
-            display: block !important;
+          .private-mask[enabled="true"] {
+            display: flex !important;
           }

           .privatetab-icon {

This should fix it properly then.


You can also add this at line 471:


@@ -469,6 +469,8 @@
             list-style-image: url(chrome://browser/skin/privateBrowsing.svg);
           }

+          #history-panel #openPrivate .menu-iconic-left,
+          #contentAreaContextMenu #openLinkInPrivateTab .menu-iconic-left,
           #tabbrowser-tabs[hasadjacentnewprivatetabbutton]:not([overflow="true"]) ~ #${UC.privateTab.BTN_ID},
           #tabbrowser-tabs[overflow="true"] > #tabbrowser-arrowscrollbox > #tabbrowser-arrowscrollbox-periphery > #${UC.privateTab.BTN2_ID},
           #tabbrowser-tabs:not([hasadjacentnewprivatetabbutton]) > #tabbrowser-arrowscrollbox > #tabbrowser-arrowscrollbox-periphery > #${UC.privateTab.BTN2_ID},

This will remove the purple icon from the default context menu (RMB) when a URL on a site is clicked, and also from the history side panel. Since padding isn't there by default in these two locations, and it's usually exclusive to extensions that are added at the bottom, then this will avoid that ugly misalignment in Open Link in… / Open in… options at the top of the menu

kaos-55 commented 10 months ago

Amazing the script revived, thank you very much for the solution 👍 I will leave the issue open for a while in case someone else might find it useful.

KNnut commented 10 months ago

I got it working in this way:

@@ -139,9 +139,6 @@
     document.getElementById('context_pinTab').insertAdjacentElement('afterend', toggleTab);
     document.getElementById('tabContextMenu').addEventListener('popupshowing', this.tabContext);

-    let privateMask = document.getElementsByClassName('private-browsing-indicator')[0];
-    privateMask.id = 'private-mask';
-
     let btn2 = _uc.createElement(document, 'toolbarbutton', {
       id: this.BTN2_ID,
       label: 'New Private Tab',
@@ -375,7 +372,7 @@

   toggleMask: function (win) {
     let {gBrowser} = win;
-    let privateMask = win.document.getElementById('private-mask');
+    let privateMask = win.document.getElementById('private-browsing-indicator-with-label');
     if (gBrowser.selectedTab.isToggling)
       privateMask.setAttribute('enabled', gBrowser.selectedTab.userContextId == this.container.userContextId ? 'false' : 'true');
     else
@@ -457,8 +454,8 @@
     this.STYLE = {
       url: Services.io.newURI('data:text/css;charset=UTF-8,' + encodeURIComponent(`
         @-moz-document url('${_uc.BROWSERCHROME}'), url-prefix('chrome://browser/content/places/') {
-          #private-mask[enabled="true"] {
-            display: block !important;
+          #private-browsing-indicator-with-label[enabled="true"] {
+            display: inherit !important;
           }

           .privatetab-icon {
@@ -557,8 +554,7 @@
       win.customElements.get('tabbrowser-tabs').prototype.insertBefore = this.orig_insertBefore;
       win.customElements.get('tabbrowser-tabs').prototype._updateNewTabVisibility = this.orig__updateNewTabVisibility;
       gBrowser.tabContainer.removeAttribute('hasadjacentnewprivatetabbutton');
-      doc.getElementById('private-mask').removeAttribute('enabled');
-      doc.getElementById('private-mask').removeAttribute('id');
+      doc.getElementById('private-browsing-indicator-with-label').removeAttribute('enabled');
     }, false);

     CustomizableUI.destroyWidget(this.BTN_ID);
megamorphg commented 10 months ago

Which of the changes are better? Can someone post the full updated script?

kaos-55 commented 10 months ago

Thanks @KNnut for posting another solution, I just tried it and it works too. @megamorphg Both fixes works in the same way, no matter which one is used. Anyway I leave you the updated script. privateTab.uc.zip Just unzip the file and there is the script.👍

FaySmash commented 10 months ago

When I clicked on the new private Tab icon, always two tabs would open I fixed it by removing a few lines. I also added a "privateMaskWithLabel" toggle to hide the big private mode label.

privateTab.uc.zip