How to collapse (toggle) all bookmark folder?

User Help for Mozilla Firefox
Post Reply
User avatar
Drumbrake
Posts: 1177
Joined: February 14th, 2011, 2:34 am

How to collapse (toggle) all bookmark folder?

Post by Drumbrake »

Is there any way -including extensions- to toggle all bookmark folders in the side bar to collapsed and expand them again ?
morat
Posts: 6437
Joined: February 3rd, 2009, 6:29 pm

Re: How to collapse (toggle) all bookmark folder?

Post by morat »

This is what I do.

Code: Select all

// toggle all tree nodes in the bookmarks sidebar
var browser document.getElementById("sidebar");
var 
contentDocument browser.contentDocument;
var 
tree contentDocument.getElementById("bookmarks-view");
if (
tree) {
  var 
view tree.view;
  if (
view.isContainer(0) && !view.isContainerOpen(0)) {
    
// expand all tree nodes
    
for (var 0view.rowCounti++) {
      if (
view.isContainer(i) && !view.isContainerOpen(i)) {
        
view.toggleOpenState(i);
      }
    }
  } else {
    
// collapse all tree nodes except Bookmarks Menu folder
    
for (var view.rowCount 1>= 0i--) {
      var 
name view.getCellText(itree.columns.getColumnAt(0));
      if (
view.isContainer(i) &&
          
view.isContainerOpen(i) &&
          
name != "Bookmarks Menu") {
        
view.toggleOpenState(i);
      }
    }
  }
} else {
  
// open bookmarks sidebar
  
toggleSidebar("viewBookmarksSidebar");

The code works for extensions that allow you to run javascript with chrome privileges, like PrefBar.

https://addons.mozilla.org/firefox/addon/67148
User avatar
Drumbrake
Posts: 1177
Joined: February 14th, 2011, 2:34 am

Re: How to collapse (toggle) all bookmark folder?

Post by Drumbrake »

Thank you so much,this is yet another useful feature (IMHO) that for who knows what reason has never been considered-if I got it right from your last comment,this won't work as bookmarklet:will it also work (aside of PrefBar) if executed in the Error Console (not a fast way to do this for sure) or with Custom Buttons
https://addons.mozilla.org/en-US/firefox/addon/custom-buttons/ ?
morat
Posts: 6437
Joined: February 3rd, 2009, 6:29 pm

Re: How to collapse (toggle) all bookmark folder?

Post by morat »

Drumbrake wrote:if executed in the error console

You can run the code in scratchpad in the browser environment.

1. open about:config
2. set devtools.chrome.enabled to true
3. tools > web developer > scratchpad
4. environment > browser
5. edit > paste (i.e. copy and paste code above)
6. execute > run
Post Reply