Last active
January 15, 2020 21:13
-
-
Save GoesuZuegs/6ed96b20725d40262fac947b8501b1d9 to your computer and use it in GitHub Desktop.
A user script for Firefox, which opens bookmarks folders on the bookmarks toolbar when one hovers over them.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
if (window.location.href !== "chrome://browser/content/browser.xul") { | |
return; | |
} | |
const bookmarksToolbar = document.getElementById("PlacesToolbarItems"); | |
if (!(bookmarksToolbar instanceof Element)) { | |
return; | |
} | |
const isFolder = (node) => { | |
if (node instanceof Element) { | |
if (node.classList.contains("bookmark-item")) { | |
if (node.getAttribute("type") === "menu" && node.getAttribute("container") === "true") { | |
return true; | |
} | |
} | |
} | |
}; | |
const hoverListener = (event) => { | |
if (isFolder(event.target)) { | |
Array.from(event.target.parentNode.childNodes).filter(isFolder).forEach(current => { | |
current.open = false; | |
}); | |
event.target.open = true; | |
} | |
}; | |
const closeListener = (event) => { | |
if (isFolder(event.target)) { | |
event.target.open = false; | |
} | |
}; | |
const foldersObserver = new MutationObserver(mutationsList => { | |
for (const mutation of mutationsList) { | |
if (mutation.type === "childList") { | |
if (mutation.addedNodes) { | |
const addedFolders = Array.from(mutation.addedNodes).filter(isFolder); | |
addedFolders.forEach(folder => { | |
folder.addEventListener("mouseenter", hoverListener); | |
folder.addEventListener("mouseleave", closeListener); | |
}); | |
} | |
if (mutation.removedNodes) { | |
const removedFolders = Array.from(mutation.removedNodes).filter(isFolder); | |
removedFolders.forEach(folder => { | |
folder.removeEventListener("mouseenter", hoverListener); | |
folder.removeEventListener("mouseleave", closeListener); | |
}); | |
} | |
} | |
} | |
}); | |
foldersObserver.observe(bookmarksToolbar, { | |
childList: true | |
}); | |
})(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Hamburger menu | |
const menuButton = document.getElementById("PanelUI-menu-button"); | |
if (menuButton instanceof Element) { | |
menuButton.addEventListener("mouseenter", () => { | |
menuButton.click(); | |
}); | |
} | |
// Page actions | |
const pageActionsButton = document.getElementById("pageActionButton"); | |
if (pageActionsButton instanceof Element) { | |
pageActionsButton.addEventListener("mouseenter", () => { | |
pageActionsButton.click(); | |
}); | |
} | |
// Bookmarks menu | |
const bookmarksMenuButton = document.getElementById("bookmarks-menu-button"); | |
if (bookmarksMenuButton instanceof Element) { | |
bookmarksMenuButton.addEventListener("mouseenter", () => { | |
bookmarksMenuButton.open = true; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you. Bookmarks auto-expand doesn't seem to work on FF 69.0.2 (CSS is 'unlocked' in about:config).