MozillaZine

How to collapse (toggle) all bookmark folder?

User Help for Mozilla Firefox
Drumbrake

User avatar
 
Posts: 1177
Joined: February 14th, 2011, 2:34 am

Post Posted August 26th, 2013, 3:28 am

Is there any way -including extensions- to toggle all bookmark folders in the side bar to collapsed and expand them again ?

morat
 
Posts: 4087
Joined: February 3rd, 2009, 6:29 pm

Post Posted August 31st, 2013, 9:46 am

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

Drumbrake

User avatar
 
Posts: 1177
Joined: February 14th, 2011, 2:34 am

Post Posted September 1st, 2013, 2:50 am

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: 4087
Joined: February 3rd, 2009, 6:29 pm

Post Posted September 1st, 2013, 7:31 am

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

Return to Firefox Support


Who is online

Users browsing this forum: No registered users and 9 guests