Skip to content

Commit

Permalink
(JS) update privateTabs.uc.js,
Browse files Browse the repository at this point in the history
searchModeIndicatorIcons.uc.js.
(CSS) add new icons for quick action urlbar results
and Want My RSS extension.
update quick action urlbar results styles.
  • Loading branch information
aminomancer committed Aug 24, 2022
1 parent 1fc88e0 commit 2b4a435
Show file tree
Hide file tree
Showing 10 changed files with 171 additions and 94 deletions.
141 changes: 63 additions & 78 deletions JS/privateTabs.uc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ==UserScript==
// @name Private Tabs
// @version 1.1
// @version 1.2.0
// @author aminomancer
// @homepage https://github.com/aminomancer
// @description An fx-autoconfig port of Private Tab by xiaoxiaoflood. Adds
Expand All @@ -20,51 +20,47 @@
// ==/UserScript==

class PrivateTabManager {
config = {
// if you want to not record history but don't care about other data, maybe even want to keep private logins
neverClearData: false,
restoreTabsOnRestart: true,
doNotClearDataUntilFxIsClosed: true,
deleteContainerOnDisable: false,
clearDataOnDisable: false,

// key for toggling private mode for the active tab. ctrl + alt + T by default.
toggleHotkey: "T",

// key for opening a new private tab. ctrl + alt + P by default.
newTabHotkey: "P",

// modifiers for toggle hotkey. this means alt+ctrl on windows or alt+cmd on mac
toggleModifiers: "alt accel",

// modifiers for new tab hotkey.
newTabModifiers: "alt accel",
};
openTabs = new Set();
BTN_ID = "privateTab-button";
BTN2_ID = "newPrivateTab-button";
constructor() {
if (!_ucUtils.sharedGlobal.privateTabGlobal) _ucUtils.sharedGlobal.privateTabGlobal = {};
let privateTabGlobal = _ucUtils.sharedGlobal.privateTabGlobal;
this.config = {
// if you want to not record history but don't care about other data, maybe even want to keep private logins
neverClearData: false,
restoreTabsOnRestart: true,
doNotClearDataUntilFxIsClosed: true,
deleteContainerOnDisable: false,
clearDataOnDisable: false,

// key for toggling private mode for the active tab. ctrl + alt + T by default.
toggleHotkey: "T",

// key for opening a new private tab. ctrl + alt + P by default.
newTabHotkey: "P",

// modifiers for toggle hotkey. this means alt+ctrl on windows or alt+cmd on mac
toggleModifiers: "alt accel",

// modifiers for new tab hotkey.
newTabModifiers: "alt accel",
};
// isn't strictly necessary, but due to a programmer's oversight, this seems to
// be the only way to prevent irritating animations when toggling private mode
// on/off for a tab. what's actually happening under the hood is not a simple
// state change, since that would be insecure. the whole point of all this is to
// avoid leaking information, so when we turn private mode on, we need to create
// a brand new tab and restore it from cached data. but the internal duplicateTab
// method doesn't pass the skipAnimation parameter to addTrustedTab. so we need
// to make our own function, which requires these unexposed modules.
let { SessionStoreInternal } = Cu.import("resource:///modules/sessionstore/SessionStore.jsm");
// the internal duplicateTab method doesn't pass the skipAnimation parameter
// to addTrustedTab. so we need to make our own function, which requires us
// to access some private objects.
let { SessionStoreInternal, TAB_CUSTOM_VALUES } = Cu.import(
"resource:///modules/sessionstore/SessionStore.jsm"
);
this.SSI = SessionStoreInternal;
this.TAB_CUSTOM_VALUES = TAB_CUSTOM_VALUES;
XPCOMUtils.defineLazyModuleGetters(this, {
TabState: "resource:///modules/sessionstore/TabState.jsm",
TabStateFlusher: "resource:///modules/sessionstore/TabStateFlusher.jsm",
ContextualIdentityService: "resource://gre/modules/ContextualIdentityService.jsm",
});
this.sss = Cc["@mozilla.org/content/style-sheet-service;1"].getService(Ci.nsIStyleSheetService);
privateTabGlobal.openTabs = new Set();
if (typeof window.gProton != "undefined") privateTabGlobal.gProton = window.gProton;
this.menuClass = privateTabGlobal.gProton ? `` : `menuitem-iconic privatetab-icon`;
this.openTabs = privateTabGlobal.openTabs;
this.menuClass = typeof window.gProton != "undefined" ? `` : `menuitem-iconic privatetab-icon`;
this.orig_getAttribute = MozElements.MozTab.prototype.getAttribute;
this.BTN_ID = "privateTab-button";
this.BTN2_ID = "newPrivateTab-button";
this.init();
if (location.href != "chrome://browser/content/browser.xhtml") return this.exec();
if (gBrowserInit.delayedStartupFinished) this.exec();
Expand All @@ -80,7 +76,7 @@ class PrivateTabManager {
}

exec() {
let privateTabGlobal = _ucUtils.sharedGlobal.privateTabGlobal;
let { privateTabGlobal } = _ucUtils.sharedGlobal;
if (PrivateBrowsingUtils.isWindowPrivate(window)) return;
let openAll = document.getElementById("placesContext_openBookmarkContainer:tabs");
let openAllPrivate = _ucUtils.createElement(document, "menuitem", {
Expand Down Expand Up @@ -202,34 +198,14 @@ class PrivateTabManager {
MozElements.MozTab.prototype.getAttribute = function (att) {
if (att == "usercontextid" && this.isToggling) {
delete this.isToggling;
return privateTab.orig_getAttribute.call(this, att)
return privateTab.orig_getAttribute.call(this, att) == privateTab.container.userContextId
? 0
: privateTab.container.userContextId;
} else {
return privateTab.orig_getAttribute.call(this, att);
}
};

Object.defineProperty(customElements.get("tabbrowser-tabs").prototype, "allTabs", {
get: function allTabs() {
let children = Array.from(this.arrowScrollbox.children);
while (children.length && children[children.length - 1].tagName != "tab") children.pop();
return children;
},
});

customElements.get("tabbrowser-tabs").prototype.insertBefore = function (tab, node) {
if (!this.arrowScrollbox) {
throw new Error("Shouldn't call this without arrowscrollbox");
}

let { arrowScrollbox } = this;
if (node == null) {
node = arrowScrollbox.lastChild.previousSibling.previousSibling;
}
return arrowScrollbox.insertBefore(tab, node);
};

customElements.get("tabbrowser-tabs").prototype._updateNewTabVisibility = function () {
let wrap = n => (n.parentNode.localName == "toolbarpaletteitem" ? n.parentNode : n);
let unwrap = n => (n && n.localName == "toolbarpaletteitem" ? n.firstElementChild : n);
Expand Down Expand Up @@ -292,14 +268,14 @@ class PrivateTabManager {
}

init() {
let privateTabGlobal = _ucUtils.sharedGlobal.privateTabGlobal;
ContextualIdentityService.ensureDataReady();
this.container = ContextualIdentityService._identities.find(
let { privateTabGlobal } = _ucUtils.sharedGlobal;
this.ContextualIdentityService.ensureDataReady();
this.container = this.ContextualIdentityService._identities.find(
container => container.name == "Private"
);
if (!this.container) {
ContextualIdentityService.create("Private", "fingerprint", "purple");
this.container = ContextualIdentityService._identities.find(
this.ContextualIdentityService.create("Private", "fingerprint", "purple");
this.container = this.ContextualIdentityService._identities.find(
container => container.name == "Private"
);
} else if (!this.config.neverClearData) {
Expand All @@ -312,7 +288,22 @@ class PrivateTabManager {
CustomizableUI.addListener(this);

if (!privateTabGlobal.privateTabsInited) {
let { getBrowserWindow } = Cu.import("resource:///modules/PlacesUIUtils.jsm");
const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
PlacesUtils: "resource://gre/modules/PlacesUtils.sys.mjs",
});
XPCOMUtils.defineLazyModuleGetters(lazy, {
BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.jsm",
PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.jsm",
});
function getBrowserWindow(aWindow) {
// Prefer the caller window if it's a browser window, otherwise use
// the top browser window.
return aWindow &&
aWindow.document.documentElement.getAttribute("windowtype") == "navigator:browser"
? aWindow
: lazy.BrowserWindowTracker.getTopWindow();
}
let openTabsetString = PlacesUIUtils.openTabset.toString();
eval(
`PlacesUIUtils.openTabset = ${openTabsetString.startsWith("function") ? "" : "function "}` +
Expand All @@ -321,14 +312,6 @@ class PrivateTabManager {
"$1$2$1userContextId: aEvent.userContextId || 0,"
)
);

eval(
"PlacesUIUtils._openNodeIn = " +
PlacesUIUtils._openNodeIn
.toString()
.replace(/(\s+)(aPrivate = false)\n/, "$1$2,$1userContextId = 0\n")
.replace(/(\s+)(private: aPrivate,)\n/, "$1$2$1userContextId,\n")
);
}

let { UUIDMap } = Cu.import("resource://gre/modules/Extension.jsm");
Expand Down Expand Up @@ -363,7 +346,7 @@ class PrivateTabManager {
}

closeTabs() {
ContextualIdentityService._forEachContainerTab((tab, tabbrowser) => {
this.ContextualIdentityService._forEachContainerTab((tab, tabbrowser) => {
if (tab.userContextId == this.container.userContextId) tabbrowser.removeTab(tab);
});
}
Expand All @@ -377,6 +360,8 @@ class PrivateTabManager {
index,
skipAnimation: true,
...(tab == gBrowser.selectedTab ? { relatedToCurrent: true, ownerTab: tab } : {}),
skipLoad: true,
preferredRemoteType: aTab.linkedBrowser.remoteType,
};
let newTab = gBrowser.addTrustedTab(null, tabOptions);

Expand All @@ -394,7 +379,7 @@ class PrivateTabManager {
gBrowser.setDefaultIcon(newTab, uriObj);

// Collect state before flushing.
let tabState = this.TabState.collect(tab, SessionStore.getCustomTabValue(tab));
let tabState = this.TabState.collect(tab, this.TAB_CUSTOM_VALUES.get(tab));

// Flush to get the latest tab state to duplicate.
let browser = tab.linkedBrowser;
Expand Down Expand Up @@ -431,11 +416,11 @@ class PrivateTabManager {
togglePrivate(tab = gBrowser.selectedTab) {
tab.isToggling = true;
let shouldSelect = tab == gBrowser.selectedTab;
let newTab = this.duplicateTab(tab, {
this.duplicateTab(tab, {
index: shouldSelect ? tab._tPos + 1 : tab._tPos,
inBackground: !shouldSelect,
});
if (shouldSelect) if (gURLBar.focused) gURLBar.focus();
if (shouldSelect && gURLBar.focused) gURLBar.focus();
gBrowser.removeTab(tab, { animate: false, closeWindowWithLastTab: false });
}

Expand Down Expand Up @@ -599,7 +584,7 @@ class PrivateTabManager {
url: Services.io.newURI(
"data:text/css;charset=UTF-8," +
encodeURIComponent(
`.privatetab-icon, #${this.BTN_ID}, #${this.BTN2_ID} { list-style-image: url(chrome://browser/skin/privateBrowsing.svg) !important; fill: currentColor; -moz-context-properties: fill; } @-moz-document url('chrome://browser/content/browser.xhtml') { #private-mask[enabled="true"] { display: block !important; } #tabbrowser-tabs[hasadjacentnewprivatetabbutton]:not([overflow="true"]) ~ #${this.BTN_ID}, #tabbrowser-tabs[overflow="true"] > #tabbrowser-arrowscrollbox > #${this.BTN2_ID}, #tabbrowser-tabs:not([hasadjacentnewprivatetabbutton]) > #tabbrowser-arrowscrollbox > #${this.BTN2_ID}, #TabsToolbar[customizing="true"] #${this.BTN2_ID} { display: none; } .tabbrowser-tab[usercontextid="${this.container.userContextId}"] .tab-label { text-decoration: underline !important; text-decoration-color: -moz-nativehyperlinktext !important; text-decoration-style: dashed !important; } .tabbrowser-tab[usercontextid="${this.container.userContextId}"][pinned] .tab-icon-image, .tabbrowser-tab[usercontextid="${this.container.userContextId}"][pinned] .tab-throbber { border-bottom: 1px dashed -moz-nativehyperlinktext !important; }}`
`.privatetab-icon, #${this.BTN_ID}, #${this.BTN2_ID} { list-style-image: url(chrome://browser/skin/privateBrowsing.svg) !important; fill: currentColor; -moz-context-properties: fill; } @-moz-document url('chrome://browser/content/browser.xhtml') { #private-mask[enabled="true"] { display: block !important; } #tabbrowser-tabs[hasadjacentnewprivatetabbutton]:not([overflow="true"]) ~ #${this.BTN_ID}, #tabbrowser-tabs[overflow="true"] > #tabbrowser-arrowscrollbox > #tabbrowser-arrowscrollbox-periphery > #${this.BTN2_ID}, #tabbrowser-tabs:not([hasadjacentnewprivatetabbutton]) > #tabbrowser-arrowscrollbox > #tabbrowser-arrowscrollbox-periphery > #${this.BTN2_ID}, #TabsToolbar[customizing="true"] #${this.BTN2_ID} { display: none; } .tabbrowser-tab[usercontextid="${this.container.userContextId}"] .tab-label { text-decoration: underline !important; text-decoration-color: -moz-nativehyperlinktext !important; text-decoration-style: dashed !important; } .tabbrowser-tab[usercontextid="${this.container.userContextId}"][pinned] .tab-icon-image, .tabbrowser-tab[usercontextid="${this.container.userContextId}"][pinned] .tab-throbber { border-bottom: 1px dashed -moz-nativehyperlinktext !important; }}`
)
),
type: this.sss.USER_SHEET,
Expand Down
7 changes: 5 additions & 2 deletions JS/searchModeIndicatorIcons.uc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ==UserScript==
// @name Search Mode Indicator Icons
// @version 1.4.2
// @version 1.4.3
// @author aminomancer
// @homepage https://github.com/aminomancer
// @description Automatically replace the urlbar's identity icon with the
Expand Down Expand Up @@ -232,7 +232,7 @@
// integer sources. the icons are defined in browser.css so we'll use
// those icons.
else if (gURLBar.searchMode?.source) {
let { BOOKMARKS, HISTORY, TABS } = UrlbarUtils.RESULT_SOURCE;
let { BOOKMARKS, HISTORY, TABS, ACTIONS } = UrlbarUtils.RESULT_SOURCE;
switch (gURLBar.searchMode.source) {
case BOOKMARKS:
url = `chrome://browser/skin/bookmark.svg`;
Expand All @@ -243,6 +243,9 @@
case TABS:
url = `chrome://browser/skin/tab.svg`;
break;
case ACTIONS:
url = `chrome://browser/skin/quickactions.svg`;
break;
}
}
if (!url) {
Expand Down
7 changes: 7 additions & 0 deletions resources/material/bolt.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions resources/material/flash.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions resources/material/quickactions.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions resources/material/rss.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 7 additions & 2 deletions uc-extensions.css
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,17 @@ menupopup#viewSidebarMenu
list-style-image: url(chrome://userchrome/content/skin/container-base.svg);
}

#pageAction-urlbar-_testpilot-containers,
#pageAction-panel-_testpilot-containers {
:is(.pageAction-panel-button, .urlbar-page-action)[actionid="_testpilot-containers"] {
--pageAction-image-16px: url(chrome://userchrome/content/skin/container-go.svg) !important;
--pageAction-image-32px: url(chrome://userchrome/content/skin/container-go.svg) !important;
}

/* Want My RSS */
:is(.pageAction-panel-button, .urlbar-page-action)[actionid="_4d567245-e70d-466a-bb2f-390fc7fb25c2_"] {
--pageAction-image-16px: url(chrome://userchrome/content/material/rss.svg) !important;
--pageAction-image-32px: url(chrome://userchrome/content/material/rss.svg) !important;
}

/* sort bookmarks */
:is(.webextension-browser-action, .eom-addon-button)[data-extensionid="sort-bookmarks@heftig"]
.toolbarbutton-icon {
Expand Down
4 changes: 4 additions & 0 deletions uc-search-mode-icons.css
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ a rule for it. */
--search-engine-icon: url(chrome://userchrome/content/skin/bookmark.svg) !important;
}

#identity-icon-box[engine="Actions"] {
--search-engine-icon: url(chrome://browser/skin/quickactions.svg) !important;
}

/* for google */
#identity-icon-box[engine="Google"] {
--search-engine-icon: url(chrome://userchrome/content/engines/google.svg) !important;
Expand Down
Loading

0 comments on commit 2b4a435

Please sign in to comment.