Skip to content

Commit c68eee4

Browse files
committed
(JS) update openBookmarkInContainerTab.uc.js
and openLinkInUnloadedTab.uc.js to keep up with Firefox updates and to fix a bug.
1 parent 141dcca commit c68eee4

4 files changed

Lines changed: 32 additions & 27 deletions

File tree

JS/openBookmarkInContainerTab.uc.js

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// ==UserScript==
22
// @name Open Bookmark in Container Tab (context menu)
3-
// @version 1.1
3+
// @version 1.2.1
44
// @author aminomancer
55
// @homepage https://github.com/aminomancer/uc.css.js
6-
// @description Adds a new menu to context menus prompted by right-clicking bookmarks, history entries, etc. that allows you to open them in a container tab. This does basically the same thing as the similarly-named addon by Rob Wu, just by a different method. By doing this with an autoconfig script, we can make the menu appear in a logical order towards the top of the context menu rather than at the very bottom, where context menu items from addons always go.
6+
// @description Adds a new menu to context menus prompted by right-clicking bookmarks, history entries, etc. that allows you to open them in a container tab. This does basically the same thing as the similarly-named addon by Rob Wu, just by a different method. By doing this with an autoconfig script, we can make the menu appear in a logical order towards the top of the context menu rather than at the very bottom, where context menu items from addons always go. Since Bug 1754805, the main menu created by this script is obsolete — the "Open in New Container Tab" menu opened on bookmarks and history items. So as of version 1.2, that menu has been removed. However, this still
77
// @license This Source Code Form is subject to the terms of the Creative Commons Attribution-NonCommercial-ShareAlike International License, v. 4.0. If a copy of the CC BY-NC-SA 4.0 was not distributed with this file, You can obtain one at http://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.
88
// @include main
99
// @include chrome://browser/content/places/bookmarksSidebar.xhtml
@@ -15,7 +15,6 @@ class OpenPlacesInContainerTabMenu {
1515
static config = {
1616
l10n: {
1717
openAll: `Open All in Container Tabs`, // Appears when right-clicking a container/folder in bookmarks or history.
18-
openBookmark: `Open in New Container Tab`, // Appears when right-clicking a bookmark, history item, etc.
1918
openSyncedTab: `Open in a New Container Tab`, // Appears when right-clicking a tab in the synced tabs sidebar.
2019
accessKey: `c`, // All of the menu items use a predefined access key. Access keys are underlined in the menu item's label, and pressing them on your keyboard automatically selects the menu item. They serve as hotkeys while the context menu is open. The default access key is "c" for the english "Container." This collides with the "Copy" menu item, so if you leave this set to "c" the script will change the Copy access key to "y" so they don't collide. It won't do that if you change this variable though. If the chosen access key is not present in the menu item's label, instead of being underlined in the label, it will be shown after the label in parentheses, e.g. "Open All in Container Tabs (G)"
2120
},
@@ -27,20 +26,6 @@ class OpenPlacesInContainerTabMenu {
2726

2827
if (l10n.accessKey === `c`) this.placesMenuCopy.accessKey = `y`;
2928

30-
this.placesMenuOpenInContainer = this.create(document, "menu", {
31-
id: "placesContext_open:container",
32-
label: l10n.openBookmark,
33-
accesskey: l10n.accessKey,
34-
disabled: true,
35-
hidden: true,
36-
});
37-
this.placesMenuOpenNewTab.after(this.placesMenuOpenInContainer);
38-
let openPopup = this.placesMenuOpenInContainer.appendChild(
39-
document.createXULElement("menupopup")
40-
);
41-
openPopup.addEventListener("command", (e) => this.openLinkInContainer(e, openPopup));
42-
popups.push(openPopup);
43-
4429
this.placesMenuOpenAllInContainer = this.create(document, "menu", {
4530
id: "placesContext_openContainer:container",
4631
label: l10n.openAll,
@@ -253,8 +238,6 @@ class OpenPlacesInContainerTabMenu {
253238
this.placesMenuOpenBookmarkLinks?.hidden;
254239
this.placesMenuOpenAllLinksInContainer.disabled = this.placesMenuOpenAllLinks?.disabled;
255240
this.placesMenuOpenAllLinksInContainer.hidden = this.placesMenuOpenAllLinks?.hidden;
256-
this.placesMenuOpenInContainer.disabled = this.placesMenuOpenNewTab?.disabled;
257-
this.placesMenuOpenInContainer.hidden = this.placesMenuOpenNewTab?.hidden;
258241
}
259242
onSyncedContextMenuShowing(_e) {
260243
this.syncedContextMenuInited = true;
@@ -293,10 +276,22 @@ class OpenPlacesInContainerTabMenu {
293276
let items = [];
294277
if (PlacesUtils.nodeIsContainer(folder)) {
295278
let root = PlacesUtils.getContainerNodeWithOptions(folder, false, true);
279+
let result = root.parentResult;
280+
let wasOpen = root.containerOpen;
281+
let didSuppressNotifications = false;
282+
if (!wasOpen) {
283+
didSuppressNotifications = result.suppressNotifications;
284+
if (!didSuppressNotifications) result.suppressNotifications = true;
285+
root.containerOpen = true;
286+
}
296287
for (let i = 0; i < root.childCount; ++i) {
297288
let child = root.getChild(i);
298289
if (PlacesUtils.nodeIsURI(child)) items.push({ url: child.uri });
299290
}
291+
if (!wasOpen) {
292+
root.containerOpen = false;
293+
if (!didSuppressNotifications) result.suppressNotifications = false;
294+
}
300295
} else items = folder;
301296
this.openLinkInContainer(e, popup, items);
302297
}

JS/openLinkInUnloadedTab.uc.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ==UserScript==
22
// @name Open Link in Unloaded Tab (context menu item)
3-
// @version 1.5
3+
// @version 1.5.1
44
// @author aminomancer
55
// @homepage https://github.com/aminomancer
66
// @description Add a new menu item to context menus prompted by right/accel-clicking on links or other link-like affordances. The menu item will open the link in a new background tab without loading the page. So the tab will start unloaded or "discarded." The context menu entry appears in the content area context menu when right-clicking a link; and in every menu where bookmarks, history, and synced tabs can be interacted with — sidebar, menubar, toolbar, toolbar button popup, and library window. Script is a remake of "Open in Unloaded Tab" by xiaoxiaoflood, but intended for use with fx-autoconfig by MrOtherGuy. It should still work with other loaders that load user scripts per-window, such as alice0775's loader, but is not compatible with older loaders or those like xiaoxiaoflood's loader. The difference is that those loaders run scripts in the global execution context, and simply call a global function when a window is launched, (the global function takes the window as a parameter) whereas fx-autoconfig loads normal scripts entirely within the window context, unless explicitly told to do otherwise. When you open a bookmark or history item in an unloaded tab, the tab draws its title from the entry in the places database. But when you open a link in an unloaded tab, there is no preexisting title. Normally when opening a link in a tab, the title is updated as the tab loads, but since we're opening the tab unloaded from the beginning, Firefox is less likely to know what the document's final title is. By default, the script works around this by generating a temporary title for the tab based on the text of the link that was opened. So if you click a hyperlink "https://mozilla.org" whose label text says "Mozilla" the title will be set to Mozilla until the tab is loaded. But if you click a hyperlink whose label text is the same as the URL itself, the title will simply be the URL. There's a user preference for this, however. If you just want to use the URL for the title no matter what, toggle this pref to false in about:config: "userChrome.openLinkInUnloadedTab.use_link_text_as_tab_title_when_unknown"
@@ -257,6 +257,14 @@ const unloadedTabMenuL10n = {
257257
let items = [];
258258
if (PlacesUtils.nodeIsContainer(folder)) {
259259
let root = PlacesUtils.getContainerNodeWithOptions(folder, false, true);
260+
let result = root.parentResult;
261+
let wasOpen = root.containerOpen;
262+
let didSuppressNotifications = false;
263+
if (!wasOpen) {
264+
didSuppressNotifications = result.suppressNotifications;
265+
if (!didSuppressNotifications) result.suppressNotifications = true;
266+
root.containerOpen = true;
267+
}
260268
for (let i = 0; i < root.childCount; ++i) {
261269
let child = root.getChild(i);
262270
if (PlacesUtils.nodeIsURI(child)) {
@@ -267,6 +275,10 @@ const unloadedTabMenuL10n = {
267275
});
268276
}
269277
}
278+
if (!wasOpen) {
279+
root.containerOpen = false;
280+
if (!didSuppressNotifications) result.suppressNotifications = false;
281+
}
270282
} else items = folder;
271283
items.forEach((item) => this.openTab(item, { bulkOpen: true }));
272284
}

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -820,11 +820,9 @@ This does basically the same thing as the [similarly-named addon](https://addons
820820

821821
The menu will be present in _all_ context menus where you'd be able to open a bookmark, history entry, or synced tab, including menus, popups, panels, and even the Library/Bookmarks Manager window. However, for synced tabs, it will only be present in the sidebar, not in the profile panel, because the profile panel lacks a context menu in the first place. Right-clicking a synced tab in the profile panel simply opens the synced tab rather than opening a context menu.
822822

823-
Update: The developers of Firefox Multi-Account Containers have implemented an optional setting that creates a similar menu when right-clicking bookmarks. However, this has all the same problems as the addon previously mentioned. It doesn't work on history entries or synced tabs, it puts the menu item at the bottom of the context menu instead of with the other "open x in tab" menu items, and it doesn't apply the correct colors to the container icons.
823+
Update: Firefox has implemented a similar menu for bookmarks and history items. It doesn't yet support opening all bookmarks in a folder, and it doesn't add a similar menu to the synced tabs sidebar. So for the moment, this script still has some purpose. It's been updated to avoid making a redundant menu, so if you see 2 identical menus, update your script with the version on this repo.
824824

825-
That is, the "Personal" container is set to blue by default. It shows up as blue in all the native interfaces and in the extension pages & popups. But because extensions can't control context menu CSS, it isn't blue in the extension's optional bookmark context menu. All the icons in the extension menu are just black.
826-
827-
So for several reasons, this script is still the best solution. If you use this script, turn off the redundant extension menus in `about:addons` > Firefox Multi-Account Containers > Options > "Enable Bookmark Menus"
825+
If you use this script and Firefox Multi-Account Containers, turn off the redundant extension menus in `about:addons` > Firefox Multi-Account Containers > Options > "Enable Bookmark Menus"
828826

829827
</details>
830828

uc-context-menu-icons.css

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ menuitem#sanitizeItem > .menu-text,
8080
.menu-text,
8181
#placesContext_new\:folder .menu-text,
8282
#placesContext_new\:separator .menu-text,
83-
:is(#placesContext_open\:container, #placesContext_openContainer\:container, #placesContext_openLinks\:container)
83+
:is(#placesContext_open\:container, #placesContext_openContainer\:container, #placesContext_openLinks\:container, #placesContext_open\:newcontainertab)
8484
> .menu-text,
8585
:is(#syncedTabsOpenAllInContainer, #syncedTabsOpenInContainer) > .menu-text,
8686
#bookmark-menu-container_robwu_nl-menuitem-_bookmark-menu-item:not(.menuitem-iconic) > .menu-text,
@@ -524,7 +524,7 @@ menuitem#repair-text-encoding::before,
524524
:is(#placesContext_new\:bookmark, #placesContext_createBookmark, #syncedTabsBookmarkSelected)::before,
525525
#placesContext_new\:folder::before,
526526
#placesContext_new\:separator::before,
527-
:is(#placesContext_open\:container, #placesContext_openContainer\:container, #placesContext_openLinks\:container)::before,
527+
:is(#placesContext_open\:container, #placesContext_openContainer\:container, #placesContext_openLinks\:container, #placesContext_open\:newcontainertab)::before,
528528
:is(#syncedTabsOpenAllInContainer, #syncedTabsOpenInContainer)::before,
529529
#bookmark-menu-container_robwu_nl-menuitem-_bookmark-menu-item:not(.menuitem-iconic)::before,
530530
#placesContext
@@ -1112,7 +1112,7 @@ menuitem.customize-context-CopyID::before {
11121112
background-image: url(chrome://userchrome/content/skin/tab.svg);
11131113
}
11141114

1115-
:is(#placesContext_open\:container, #placesContext_openContainer\:container, #placesContext_openLinks\:container)::before,
1115+
:is(#placesContext_open\:container, #placesContext_openContainer\:container, #placesContext_openLinks\:container, #placesContext_open\:newcontainertab)::before,
11161116
:is(#syncedTabsOpenAllInContainer, #syncedTabsOpenInContainer)::before,
11171117
#bookmark-menu-container_robwu_nl-menuitem-_bookmark-menu-item:not(.menuitem-iconic)::before,
11181118
#placesContext

0 commit comments

Comments
 (0)