MozillaZine

[MenuWizard] Submenu "Tab-history" in tab context menu

Announce and Discuss the Latest Theme and Extension Releases.
pag77
 
Posts: 1524
Joined: December 26th, 2013, 10:46 pm

Post Posted February 8th, 2016, 5:16 am

It is a solution for the add-on "Menu Wizard"
https://addons.mozilla.org/addon/s3menu-wizard/
http://forums.mozillazine.org/viewtopic.php?f=48&t=2828771

This solution is added Tab-history to the tab context menu with the ability to open links in a new browser tab.
Image

Install:
  1. Install Menu Wizard, if it is not already in your browser
  2. Open the settings Menu Wizard: "Tools > Menu Wizard", "Add-ons > Menu Wizard > Settings" or type in the address bar about:config-menu
  3. Open the menu "Tab Context Menu"
  4. Top right click on the "Add new items"
  5. Drag and drop the "New menu folder" in the "Tab Context Menu"
  6. Open the properties for "New menu folder"
    Image
  7. In the "Command > onPopupShowing", insert this code:
    Code: Select all
    FillHistoryMenu_new(event.target);

    function FillHistoryMenu_new(aParent) {
      // Lazily add the hover listeners on first showing and never remove them
      if (!aParent.hasStatusListener) {
        // Show history item's uri in the status bar when hovering, and clear on exit
        aParent.addEventListener("DOMMenuItemActive", function(aEvent) {
          // Only the current page should have the checked attribute, so skip it
          if (!aEvent.target.hasAttribute("checked"))
            XULBrowserWindow.setOverLink(aEvent.target.getAttribute("uri"));
        }, false);
        aParent.addEventListener("DOMMenuItemInactive", function() {
          XULBrowserWindow.setOverLink("");
        }, false);

        aParent.hasStatusListener = true;
      }

      // Remove old entries if any
      var children = aParent.childNodes;
      for (var i = children.length - 1; i >= 0; --i) {
        if (children[i].hasAttribute("index"))
          aParent.removeChild(children[i]);
      }

      var aTab = (window.TabContextMenu && window.TabContextMenu.contextTab) ? window.TabContextMenu.contextTab : gBrowser.selectedTab;
      var webNav = gBrowser.getBrowserForTab(aTab).webNavigation;
      var sessionHistory = webNav.sessionHistory;

      var count = sessionHistory.count;
      if (count <= 1) // don't display the popup for a single item
        return false;

      const MAX_HISTORY_MENU_ITEMS = 15;
      var index = sessionHistory.index;
      var half_length = Math.floor(MAX_HISTORY_MENU_ITEMS / 2);
      var start = Math.max(index - half_length, 0);
      var end = Math.min(start == 0 ? MAX_HISTORY_MENU_ITEMS : index + half_length + 1, count);
      if (end == count)
        start = Math.max(count - MAX_HISTORY_MENU_ITEMS, 0);

      var tooltipBack = gNavigatorBundle.getString("tabHistory.goBack");
      var tooltipCurrent = gNavigatorBundle.getString("tabHistory.current");
      var tooltipForward = gNavigatorBundle.getString("tabHistory.goForward");

      for (var j = end - 1; j >= start; j--) {
        var item = document.createElement("menuitem");
        var entry = sessionHistory.getEntryAtIndex(j, false);
        var uri = entry.URI.spec;
        var entryURI = BrowserUtils.makeURIFromCPOW(entry.URI);

        item.setAttribute("uri", uri);
        item.setAttribute("label", entry.title || uri);
        item.setAttribute("index", j);
        item.setAttribute("onclick", "gBrowser.selectedTab = gBrowser.addTab(this.getAttribute('uri'));");

        if (j != index) {
          PlacesUtils.favicons.getFaviconURLForPage(entryURI, function (aURI) {
            if (aURI) {
              var iconURL = PlacesUtils.favicons.getFaviconLinkForIcon(aURI).spec;
              iconURL = PlacesUtils.getImageURLForResolution(window, iconURL);
              item.style.listStyleImage = "url(" + iconURL + ")";
            }
          });
        }

        if (j < index) {
          item.className = "unified-nav-back menuitem-iconic menuitem-with-favicon";
          item.setAttribute("tooltiptext", tooltipBack);
        } else if (j == index) {
          item.setAttribute("type", "radio");
          item.setAttribute("checked", "true");
          item.className = "unified-nav-current";
          item.setAttribute("tooltiptext", tooltipCurrent);
        } else {
          item.className = "unified-nav-forward menuitem-iconic menuitem-with-favicon";
          item.setAttribute("tooltiptext", tooltipForward);
        }

        aParent.appendChild(item);
      }
      return true;
    }
  8. Click "Apply"
  9. If desired, you can change the name of the menu: "Properties > Name" and change the icon

Return to Extension/Theme Releases


Who is online

Users browsing this forum: No registered users and 2 guests