Button für kürzlich geschlossene Tabs

Schrauberecke: Hier geht es um optische und funktionelle Veränderungen (ohne Themes oder Personas) von Firefox oder von Webseiten per CSS-Codes oder JavaScript.
Benutzeravatar
aborix
Senior-Mitglied
Beiträge: 3983
Registriert: So, 06. Sep 2009 0:57

Re: Button für kürzlich geschlossene Tabs

#46

Beitrag von aborix » Sa, 31. Mär 2018 17:59

Entferne in den Zeilen 12 und 25 das  //  am Anfang.

Benutzeravatar
captain chaos
Senior-Mitglied
Beiträge: 3154
Registriert: Mi, 15. Jun 2005 13:57

Re: Button für kürzlich geschlossene Tabs

#47

Beitrag von captain chaos » Sa, 31. Mär 2018 18:08

Die Menüleiste blendet sich immer noch ein, diesmal aber nicht ausgeklappt.

Benutzeravatar
Speravir
Senior-Mitglied
Beiträge: 724
Registriert: Do, 15. Dez 2005 1:33
Wohnort: Potsdam

Re: Button für kürzlich geschlossene Tabs

#48

Beitrag von Speravir Themen-Starter » Sa, 31. Mär 2018 18:24

captain chaos hat geschrieben:
Sa, 31. Mär 2018 16:43
Endor hat geschrieben:
So, 26. Nov 2017 12:52
Betrifft Script aus Beitrag 2, bitte mal diese Version testen,
der Autor hat sie erst vor ein zwei Tagen aktualisiert:
[…]
Dieses Script funktioniert im aktuellen Firefox leider nicht mehr. Kennt jemand einen Ersatz oder möchte es updaten?
Hmm, bei mir funktioniert dieses Skript so unverändert in Firefox 59.0.2 fehlerlos.
Steffen "Speravir"
---
Spiro, ergo sum.
Avatar: Vorlage Fox Head and Tail Tribal by Majykal-Melodi on DeviantArt, bearbeitet (Lizenz: CC by-sa 3.0)

Benutzeravatar
captain chaos
Senior-Mitglied
Beiträge: 3154
Registriert: Mi, 15. Jun 2005 13:57

Re: Button für kürzlich geschlossene Tabs

#49

Beitrag von captain chaos » Sa, 31. Mär 2018 18:38

Benutzt du das Script aus Beitrag 2 dieses Threads oder das von Endor hier vorgeschlagene?

Benutzeravatar
aborix
Senior-Mitglied
Beiträge: 3983
Registriert: So, 06. Sep 2009 0:57

Re: Button für kürzlich geschlossene Tabs

#50

Beitrag von aborix » Sa, 31. Mär 2018 20:52

captain chaos hat geschrieben:
Sa, 31. Mär 2018 18:08
Die Menüleiste blendet sich immer noch ein, diesmal aber nicht ausgeklappt.
Schreibe zusätzlich in die userChrome.css:

Code: Alles auswählen

#toolbar-menubar {visibility: collapse !important}

Benutzeravatar
captain chaos
Senior-Mitglied
Beiträge: 3154
Registriert: Mi, 15. Jun 2005 13:57

Re: Button für kürzlich geschlossene Tabs

#51

Beitrag von captain chaos » So, 01. Apr 2018 12:11

Damit funktioniert es. Dankeschön!

Benutzeravatar
aborix
Senior-Mitglied
Beiträge: 3983
Registriert: So, 06. Sep 2009 0:57

Re: Button für kürzlich geschlossene Tabs

#52

Beitrag von aborix » So, 01. Apr 2018 21:24

Gern geschehen.

Mit dem CSS-Code sind die Zeilen 12 und 25 nicht mehr nötig und können wieder auskommentiert werden.

Benutzeravatar
Speravir
Senior-Mitglied
Beiträge: 724
Registriert: Do, 15. Dez 2005 1:33
Wohnort: Potsdam

Re: Button für kürzlich geschlossene Tabs

#53

Beitrag von Speravir Themen-Starter » Mo, 02. Apr 2018 20:38

captain chaos hat geschrieben:
Sa, 31. Mär 2018 18:38
Benutzt du das Script aus Beitrag 2 dieses Threads oder das von Endor hier vorgeschlagene?
Endors Version, deshalb hatte ich das nicht aus dem Zitat gelöscht.
Steffen "Speravir"
---
Spiro, ergo sum.
Avatar: Vorlage Fox Head and Tail Tribal by Majykal-Melodi on DeviantArt, bearbeitet (Lizenz: CC by-sa 3.0)

Benutzeravatar
Zitronella
Senior-Mitglied
Beiträge: 8578
Registriert: Di, 07. Feb 2012 18:06

Styles und css funktioniert in aktueller Nightly nicht mehr

#54

Beitrag von Zitronella » So, 08. Apr 2018 21:23

hm, aber das Skript für die Anzeige kürzlich geschlossener Tabs wiederherstellen funktioniert nicht in Nightly 61.0a1 (2018-04-08) (64-Bit)
Hat da wer ne Lösung? Das ist der Skript-Code:

Code: Alles auswählen

// ==UserScript==
// @name           UndoListInTabmenuToo
// @namespace      http://space.geocities.yahoo.co.jp/gl/alice0775
// @description    UndoListInTabmenuToo.uc.js
// @include        main
// @compatibility  Firefox 4.0 - 59
// @author         Alice0775
// @version        2017/11/18 nsIPrefBranch to nsIPrefBranch
// @version        2010/09/18 00:00 4.0b7pre
// @version        2009/02/03 13:00 ツールチップにタブ内履歴を表示するようにした
// @Note           タブやコンテキストメニューにもUndoClose Tab Listを追加するもの
// @OriginalCode   browser.jsからpopulateUndoSubmenuを拝借し, ごにょごにょした
// @version        2010/03/26 13:00  Minefield/3.7a4pre Bug 554991 -  allow tab context menu to be modified by normal XUL overlays
// @version        2010/03/15 00:00  Minefield/3.7a4pre Bug 347930 -  Tab strip should be a toolbar instead
// @version        2009/09/09 15:00 中クリック処理
// ==/UserScript==
// @version        2009/09/03 22:00 Firegox3.7a1preで動かなくなっていたのを修正(Bug 489925. getElementById should not return anonymous nodes)
// @version        2009/08/22 00:00 Firegox3.6 stringbandleの変更による
// @version        2009/04/24 00:00 #394759 [Firefox:Session Restore]-Add undo close window feature
// @version        2008/10/12 18:00 Fx3.0.4pre中クリックしたときメニューポップアップが閉じないおよびその他fix
// @version        2007/10/05 10:00

var UndoListInTabmenu = {
// -- config --
  TABCONTEXTMENU : true , //Im Tabkontextmenü: anzeigen: true, nicht anzeigen: false
  CONTEXTMENU    : true,  //Im Hauptkontextmenü: anzeigen: true , nicht anzeigen: false
// -- config end--
  ss: null,

  get tabContext() {
    return document.getAnonymousElementByAttribute(
                        gBrowser, "anonid", "tabContextMenu")||
           gBrowser.tabContainer.contextMenu;
;
  },

  init: function(){

    if (this.TABCONTEXTMENU){
      //タブコンテキスト
      var tabContext = this.tabContext;
      this.makePopup(tabContext, null, "tabContextUndoList");
    }
    if (this.CONTEXTMENU){
      //コンテンツエリアコンテキスト
      var contextMenu = document.getElementById("contentAreaContextMenu");
      var refItem = document.getElementById("context-sep-stop");
      this.makePopup(contextMenu, refItem, "ContextUndoList");
    }
    // get closed-tabs from nsSessionStore
    this._ss = Cc["@mozilla.org/browser/sessionstore;1"].
               getService(Ci.nsISessionStore);

  },

  makePopup: function(popup, refItem, id){
    var menu;
    //label
    const locale = Components.classes["@mozilla.org/preferences-service;1"]
                   .getService(Components.interfaces.nsIPrefBranch).getCharPref("general.useragent.locale");
    if (this.getVer() > 3.0) {
      // "Recently Closed Windows"
      menu = document.createElement("menu");
      menu.setAttribute("id", "historyUndoWindowMenu3");
      menu.setAttribute("label", "K\u00FCrzlich geschlossene Fenster");
      menu.setAttribute("accesskey", "F");
      menu.setAttribute("disabled", "true");
      popup.insertBefore(menu, refItem);

      this.historyUndoWindowPopup3 = menu = menu.appendChild(document.createElement("menupopup"));
      menu.setAttribute("id", "historyUndoWindowPopup3");
      menu.setAttribute("onpopupshowing", "UndoListInTabmenu.populateUndoWindowSubmenu();");
    }

    //UndoClose Tab List  最近閉じたタブ
    const LABELTEXT = locale.indexOf("ja") == -1?"K\u00FCrzlich geschlossene Tabs":"\u6700\u8fd1\u9589\u3058\u305f\u30bf\u30d6";    //create menu
    menu = document.createElement("menu");
    menu.setAttribute("label", LABELTEXT);
    menu.setAttribute("accesskey", "T");
    if (id)
      menu.setAttribute("id", id);
    //menu.setAttribute("disabled", true);
    var menupopup = document.createElement("menupopup");
    if (this.getVer()<3) {
      menupopup.setAttribute("onpopupshowing", "UndoListInTabmenu.populateUndoSubmenu(this);");
    } else if (this.getVer()<3.6) {
      menupopup.setAttribute("onpopupshowing", "UndoListInTabmenu.populateUndoSubmenu3(this);");
    } else {
      menupopup.setAttribute("onpopupshowing", "UndoListInTabmenu.populateUndoSubmenu36(this);");
    }
    menu.appendChild(menupopup);
    popup.insertBefore(menu, refItem);

    //add event listener
    popup.addEventListener('popupshowing',function(event) {
      if (UndoListInTabmenu.getVer() > 3.0)
        UndoListInTabmenu.toggleRecentlyClosedWindows();
      // no restorable tabs, so make sure menu is disabled, and return
      if (UndoListInTabmenu._ss.getClosedTabCount(window) == 0) {
        menu.setAttribute("disabled", true);
        //menu.setAttribute("hidden", true);
        return;
      }
        menu.removeAttribute("disabled");
      //menu.setAttribute("hidden", false);
    },false);
  },

  /**
   * Populate when the history menu is opened  (Fx2)
   */
  populateUndoSubmenu: function(undoPopup) {

    // remove existing menu items
    while (undoPopup.hasChildNodes())
      undoPopup.removeChild(undoPopup.firstChild);

    // populate menu
    var undoItems = eval("(" + UndoListInTabmenu._ss.getClosedTabData(window) + ")");
    for (var i = 0; i < undoItems.length; i++) {
        var m = undoPopup.appendChild(document.createElement("menuitem"));
      m.setAttribute("label", undoItems[i].title);
      m.setAttribute("value", i);
      m.setAttribute("oncommand", "undoCloseTab(" + i + ");");
      m.setAttribute("onclick", "UndoListInTabmenu._undoCloseMiddleClick(event);");
    }

    // "open in tabs"
    var bundleService = Cc["@mozilla.org/intl/stringbundle;1"].
                        getService(Ci.nsIStringBundleService);
    var stringBundle = bundleService.createBundle("chrome://browser/locale/bookmarks/bookmarks.properties");
    undoPopup.appendChild(document.createElement("menuseparator"));
    m = undoPopup.appendChild(document.createElement("menuitem"));
    m.setAttribute("label", stringBundle.GetStringFromName("cmd_bm_openfolder"));
    m.setAttribute("accesskey", stringBundle.GetStringFromName("cmd_bm_openfolder_accesskey"));
    m.addEventListener("command", function() {
      for (var i = 0; i < undoItems.length; i++)
        undoCloseTab();
    }, false);
  },

  /**
    * Re-open a closed tab and put it to the end of the tab strip.
    * Used for a middle click.
    * @param aEvent
    *        The event when the user clicks the menu item
    */
  _undoCloseMiddleClick: function PHM__undoCloseMiddleClick(aEvent) {
    if (aEvent.button != 1)
      return;

    undoCloseTab(aEvent.originalTarget.value);
    gBrowser.moveTabToEnd();
    if (!aEvent.ctrlKey)
      aEvent.originalTarget.parentNode.parentNode.parentNode.hidePopup();
  },

  /**
   * Populate when the history menu is opened (Fx3)
   */
  populateUndoSubmenu3: function(undoPopup) {

    // remove existing menu items
    while (undoPopup.hasChildNodes())
      undoPopup.removeChild(undoPopup.firstChild);

    // "Open All in Tabs"
    var strings = gNavigatorBundle;
    m = undoPopup.appendChild(document.createElement("menuitem"));
    m.setAttribute("label", strings.getString("menuOpenAllInTabs.label"));
    m.setAttribute("accesskey", strings.getString("menuOpenAllInTabs.accesskey"));
    m.addEventListener("command", function() {
      for (var i = 0; i < undoItems.length; i++)
        undoCloseTab();
    }, false);

    undoPopup.appendChild(document.createElement("menuseparator"));

    // populate menu
    var undoItems = eval("(" + UndoListInTabmenu._ss.getClosedTabData(window) + ")");
    for (var i = 0; i < undoItems.length; i++) {
      var entries = undoItems[i].state.entries;
      var tooltiptext = "";
      for (var j = entries.length - 1; j > -1; j--){
        if (j != entries.length - 1)
          tooltiptext += "\n";
        tooltiptext += parseInt(j + 1, 10) + ". " + entries[j].title;
      }
      var m = document.createElement("menuitem");
      m.setAttribute("tooltiptext", tooltiptext);
      m.setAttribute("label", undoItems[i].title);
      if (undoItems[i].image)
        m.setAttribute("image", undoItems[i].image);
      m.setAttribute("class", "menuitem-iconic bookmark-item");
      m.setAttribute("value", i);
      m.setAttribute("oncommand", "undoCloseTab(" + i + ");");
      m.setAttribute("onclick", "UndoListInTabmenu._undoCloseMiddleClick(event);");
      if (i == 0)
        m.setAttribute("key", "key_undoCloseTab");
      undoPopup.appendChild(m);
    }

    // "Clear undo close tb list"
    undoPopup.appendChild(document.createElement("menuseparator"));

    m = undoPopup.appendChild(document.createElement("menuitem"));
    m.setAttribute("label", "Liste der letzten Tabs l\u00F6schen");
    m.setAttribute("accesskey", "l");
    m.addEventListener("command", function() {
      var max_undo = UndoListInTabmenu.getPref("browser.sessionstore.max_tabs_undo", "int", 10);
      UndoListInTabmenu.setPref("browser.sessionstore.max_tabs_undo", "int", 0);
      UndoListInTabmenu.setPref("browser.sessionstore.max_tabs_undo", "int", max_undo);
      if (max_undo != UndoListInTabmenu.getPref("browser.sessionstore.max_tabs_undo", "int", 10))
        UndoListInTabmenu.setPref("browser.sessionstore.max_tabs_undo", "int", max_undo);
    }, false);
  },

  /**
   * Populate when the history menu is opened (Fx3.6)
   */
  populateUndoSubmenu36: function(undoPopup) {

    // remove existing menu items
    while (undoPopup.hasChildNodes())
      undoPopup.removeChild(undoPopup.firstChild);

    // "Open All in Tabs"
    var strings = gNavigatorBundle;
    m = undoPopup.appendChild(document.createElement("menuitem"));
    m.setAttribute("label", strings.getString("menuRestoreAllTabs.label"));
    //m.setAttribute("class", "menuitem-iconic bookmark-item");
    m.setAttribute("accesskey", "R" /*strings.getString("menuRestoreAllTabs.accesskey")*/);
    m.addEventListener("command", function() {
      for (var i = 0; i < undoItems.length; i++)
        undoCloseTab();
    }, false);

    undoPopup.appendChild(document.createElement("menuseparator"));

    // populate menu
    var undoItems = eval("(" + UndoListInTabmenu._ss.getClosedTabData(window) + ")");
    for (var i = 0; i < undoItems.length; i++) {
      var entries = undoItems[i].state.entries;
      var tooltiptext = "";
      for (var j = entries.length - 1; j > -1; j--){
        if (j != entries.length - 1)
          tooltiptext += "\n";
        tooltiptext += parseInt(j + 1, 10) + ". " + entries[j].title;
      }
      var m = document.createElement("menuitem");
      m.setAttribute("tooltiptext", tooltiptext);
      m.setAttribute("label", undoItems[i].title);
      if (undoItems[i].image)
        m.setAttribute("image", undoItems[i].image);
      m.setAttribute("class", "menuitem-iconic bookmark-item");
      m.setAttribute("value", i);
      m.setAttribute("oncommand", "undoCloseTab(" + i + ");");
      m.setAttribute("onclick", "UndoListInTabmenu._undoCloseMiddleClick(event);");
      if (i == 0)
        m.setAttribute("key", "key_undoCloseTab");
      undoPopup.appendChild(m);
    }

    // "Clear undo close tb list"
    undoPopup.appendChild(document.createElement("menuseparator"));

    m = undoPopup.appendChild(document.createElement("menuitem"));
    m.setAttribute("label", "Liste der letzten Tabs l\u00F6schen");
    m.setAttribute("class", "menuitem-iconic bookmark-item");
    m.setAttribute("accesskey", "l");
    m.addEventListener("command", function() {
      var max_undo = UndoListInTabmenu.getPref("browser.sessionstore.max_tabs_undo", "int", 10);
      UndoListInTabmenu.setPref("browser.sessionstore.max_tabs_undo", "int", 0);
      UndoListInTabmenu.setPref("browser.sessionstore.max_tabs_undo", "int", max_undo);
      if (max_undo != UndoListInTabmenu.getPref("browser.sessionstore.max_tabs_undo", "int", 10))
        UndoListInTabmenu.setPref("browser.sessionstore.max_tabs_undo", "int", max_undo);
    }, false);
  },

  toggleRecentlyClosedWindows: function PHM_toggleRecentlyClosedWindows() {
    // enable/disable the Recently Closed Windows sub menu
    let undoPopup = this.historyUndoWindowPopup3;
    // no restorable windows, so disable menu
    if (this._ss.getClosedWindowCount() == 0)
      this.historyUndoWindowPopup3.parentNode.setAttribute("disabled", true);
    else
      this.historyUndoWindowPopup3.parentNode.removeAttribute("disabled");
  },

  /**
   * Populate when the history menu is opened
   */
  populateUndoWindowSubmenu: function PHM_populateUndoWindowSubmenu() {
    let undoPopup = this.historyUndoWindowPopup3;
    let menuLabelString = gNavigatorBundle.getString("menuUndoCloseWindowLabel");
    let menuLabelStringSingleTab =
      gNavigatorBundle.getString("menuUndoCloseWindowSingleTabLabel");

    // remove existing menu items
    while (undoPopup.hasChildNodes())
      undoPopup.removeChild(undoPopup.firstChild);

    // no restorable windows, so make sure menu is disabled, and return
    if (this._ss.getClosedWindowCount() == 0) {
      undoPopup.parentNode.setAttribute("disabled", true);
      return;
    }
    // enable menu
    undoPopup.parentNode.removeAttribute("disabled");
    let undoItems = JSON.parse(this._ss.getClosedWindowData());
    // "Open All in Windows"
    let m = undoPopup.appendChild(document.createElement("menuitem"));
    m.setAttribute("label", gNavigatorBundle.getString("menuRestoreAllWindows.label"));
    //m.setAttribute("class", "menuitem-iconic bookmark-item");
    m.setAttribute("accesskey", "W"/*gNavigatorBundle.getString("menuRestoreAllWindows.accesskey")*/);
    m.setAttribute("oncommand",
      "for (var i = 0; i < " + undoItems.length + "; i++) UndoListInTabmenu.undoCloseWindow();");
    undoPopup.appendChild(document.createElement("menuseparator"));
    // populate menu
    for (let i = 0; i < undoItems.length; i++) {
      let undoItem = undoItems[i];
      let otherTabsCount = undoItem.tabs.length - 1;
      let label = (otherTabsCount == 0) ? menuLabelStringSingleTab
                                        : PluralForm.get(otherTabsCount, menuLabelString);
      let menuLabel = label.replace("#1", undoItem.title)
                           .replace("#2", otherTabsCount);
      let m = document.createElement("menuitem");
      m.setAttribute("label", menuLabel);
      let selectedTab = undoItem.tabs[undoItem.selected - 1];
      if (selectedTab.attributes.image) {
        let iconURL = selectedTab.attributes.image;
        // don't initiate a connection just to fetch a favicon (see bug 467828)
        if (/^https?:/.test(iconURL))
          iconURL = "moz-anno:favicon:" + iconURL;
        m.setAttribute("image", iconURL);
      }
      m.setAttribute("class", "menuitem-iconic bookmark-item");
      m.setAttribute("oncommand", "UndoListInTabmenu.undoCloseWindow(" + i + ");");
      if (i == 0)
        m.setAttribute("key", "key_undoCloseWindow");
      undoPopup.appendChild(m);
    }
  },


  /**
   * Re-open a closed window.
   * @param aIndex
   *        The index of the window (via nsSessionStore.getClosedWindowData)
   * @returns a reference to the reopened window.
   */
  undoCloseWindow: function (aIndex) {
    let ss = Cc["@mozilla.org/browser/sessionstore;1"].
             getService(Ci.nsISessionStore);
    let window = null;
    if (ss.getClosedWindowCount() > (aIndex || 0))
      window = ss.undoCloseWindow(aIndex || 0);

    return window;
  },

  getPref: function(aPrefString, aPrefType, aDefault){
    var xpPref = Components.classes['@mozilla.org/preferences-service;1']
                  .getService(Components.interfaces.nsIPrefBranch);
    try{
      switch (aPrefType){
        case 'complex':
          return xpPref.getComplexValue(aPrefString, Components.interfaces.nsILocalFile); break;
        case 'str':
          return xpPref.getCharPref(aPrefString).toString(); break;
        case 'int':
          return xpPref.getIntPref(aPrefString); break;
        case 'bool':
        default:
          return xpPref.getBoolPref(aPrefString); break;
      }
    }catch(e){
    }
    return aDefault;
  },

  setPref: function(aPrefString, aPrefType, aValue){
    var xpPref = Components.classes['@mozilla.org/preferences-service;1']
                  .getService(Components.interfaces.nsIPrefBranch);
    try{
      switch (aPrefType){
        case 'complex':
          return xpPref.setComplexValue(aPrefString, Components.interfaces.nsILocalFile, aValue); break;
        case 'str':
          return xpPref.setCharPref(aPrefString, aValue); break;
        case 'int':
          aValue = parseInt(aValue);
          return xpPref.setIntPref(aPrefString, aValue);  break;
        case 'bool':
        default:
          return xpPref.setBoolPref(aPrefString, aValue); break;
      }
    }catch(e){
    }
    return null;
  },

  //Fxのバージョンを得る
    //Fxのバージョン
  getVer: function(){
    const Cc = Components.classes;
    const Ci = Components.interfaces;
    var info = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULAppInfo);
    var ver = parseInt(info.version.substr(0,3) * 10,10) / 10;
    return ver;
  }
};

if(!('TM_init' in window)) UndoListInTabmenu.init();
Hilfe auch im deutschsprachigen Firefox-Chat möglich.
Meine Anleitungstexte dürfen gerne "geklaut" und weiter verwendet/kopiert werden ;)

Benutzeravatar
2002Andreas
Moderator
Beiträge: 37518
Registriert: Fr, 04. Jul 2008 19:25
Wohnort: Niedersachsen

Re: Styles und css funktioniert in aktueller Nightly nicht mehr

#55

Beitrag von 2002Andreas » So, 08. Apr 2018 22:24

Hallo Zitronella...

ich nutze dieses Script:

Code: Alles auswählen

(function() {

  if (location != 'chrome://browser/content/browser.xul')
    return;

  let tabContextMenu = document.getElementById('tabContextMenu');
  let historyPopup = document.getElementById('goPopup');

  tabContextMenu.addEventListener('popupshowing', function(event) {
    if (event.target != this)
      return;
    historyPopup.style.visibility = 'collapse';
    historyPopup.showPopup();
    document.getElementById('historyUndoPopup').showPopup();
    let dblHistoryUndoMenu = document.getElementById('historyUndoMenu').cloneNode(true);
    dblHistoryUndoMenu.id = 'context_historyUndoMenu';
    dblHistoryUndoMenu.getElementsByTagName('menupopup')[0].removeAttribute('id');
    tabContextMenu.appendChild(dblHistoryUndoMenu);
  });

  tabContextMenu.addEventListener('popuphiding', function(event) {
    if (event.target != this)
      return;
    tabContextMenu.removeChild(document.getElementById('context_historyUndoMenu'));
    historyPopup.style.visibility = 'visible';
  });

})();
Screenshot (949).png
Mit freundlichem Gruß
Andreas
Mein System    Meine Add-ons

Benutzeravatar
Zitronella
Senior-Mitglied
Beiträge: 8578
Registriert: Di, 07. Feb 2012 18:06

Re: Styles und css funktioniert in aktueller Nightly nicht mehr

#56

Beitrag von Zitronella » So, 08. Apr 2018 22:40

ja danke, das hatte ich auch schon entdeckt, aber es gefällt mir nicht. sorry
Da geht beim Rechtsklick auf den Tab immer die Menüleiste auf. Ich weiß, das kann man zwar mit Einträgen in der userChrome.css wieder ausblenden, aber ich möchte sie manchmal dann doch bei Bedarf mit der Alt Taste wieder einblenden können und das wird durch den Eintrag in der userChrome.css dann wieder verhindert.
Kurz und knapp: Das ist mir zu viel Manipulation an zu vielen verschiedenen Stellen :D

In der momentanen Firefox Version 59.0.2 funktioniert der mein obiger Code noch, aber ich dachte, ich frage schon mal nach, damit ich mit Firefox <60* nicht allzu sehr überrascht werde.
Vielleicht kann da ein erfahrener Skript-Schreiber noch was dran drehen :D
Hilfe auch im deutschsprachigen Firefox-Chat möglich.
Meine Anleitungstexte dürfen gerne "geklaut" und weiter verwendet/kopiert werden ;)

Benutzeravatar
aborix
Senior-Mitglied
Beiträge: 3983
Registriert: So, 06. Sep 2009 0:57

Re: Styles und css funktioniert in aktueller Nightly nicht mehr

#57

Beitrag von aborix » Mo, 09. Apr 2018 6:37

Bitte teste beide:

Code: Alles auswählen

// ==UserScript==
// @name           UndoListInTabmenuToo
// @namespace      http://space.geocities.yahoo.co.jp/gl/alice0775
// @description    UndoListInTabmenuToo.uc.js
// @include        main
// @compatibility  Firefox 4.0 - 59
// @author         Alice0775
// @version        2017/11/18 nsIPrefBranch to nsIPrefBranch
// @version        2010/09/18 00:00 4.0b7pre
// @version        2009/02/03 13:00 ツールチップにタブ内履歴を表示するようにした
// @Note           タブやコンテキストメニューにもUndoClose Tab Listを追加するもの
// @OriginalCode   browser.jsからpopulateUndoSubmenuを拝借し, ごにょごにょした
// @version        2010/03/26 13:00  Minefield/3.7a4pre Bug 554991 -  allow tab context menu to be modified by normal XUL overlays
// @version        2010/03/15 00:00  Minefield/3.7a4pre Bug 347930 -  Tab strip should be a toolbar instead
// @version        2009/09/09 15:00 中クリック処理
// ==/UserScript==
// @version        2009/09/03 22:00 Firegox3.7a1preで動かなくなっていたのを修正(Bug 489925. getElementById should not return anonymous nodes)
// @version        2009/08/22 00:00 Firegox3.6 stringbandleの変更による
// @version        2009/04/24 00:00 #394759 [Firefox:Session Restore]-Add undo close window feature
// @version        2008/10/12 18:00 Fx3.0.4pre中クリックしたときメニューポップアップが閉じないおよびその他fix
// @version        2007/10/05 10:00

var UndoListInTabmenu = {
// -- config --
  TABCONTEXTMENU : true , //Im Tabkontextmenü: anzeigen: true, nicht anzeigen: false
  CONTEXTMENU    : true,  //Im Hauptkontextmenü: anzeigen: true , nicht anzeigen: false
// -- config end--
  ss: null,

  get tabContext() {
/*  return document.getAnonymousElementByAttribute(
                        gBrowser, "anonid", "tabContextMenu")||
           gBrowser.tabContainer.contextMenu; 
*/  return gBrowser.tabContainer.contextMenu;
  },

  init: function(){

    if (this.TABCONTEXTMENU){
      //タブコンテキスト
      var tabContext = this.tabContext;
      this.makePopup(tabContext, null, "tabContextUndoList");
    }
    if (this.CONTEXTMENU){
      //コンテンツエリアコンテキスト
      var contextMenu = document.getElementById("contentAreaContextMenu");
      var refItem = document.getElementById("context-sep-stop");
      this.makePopup(contextMenu, refItem, "ContextUndoList");
    }
    // get closed-tabs from nsSessionStore
/*  this._ss = Cc["@mozilla.org/browser/sessionstore;1"].
               getService(Ci.nsISessionStore);
*/  this._ss = SessionStore;

  },

  makePopup: function(popup, refItem, id){
    var menu;
    //label
/*  const locale = Components.classes["@mozilla.org/preferences-service;1"]
                   .getService(Components.interfaces.nsIPrefBranch).getCharPref("general.useragent.locale");
*/  const locale = '';
    if (this.getVer() > 3.0) {
      // "Recently Closed Windows"
      menu = document.createElement("menu");
      menu.setAttribute("id", "historyUndoWindowMenu3");
      menu.setAttribute("label", "K\u00FCrzlich geschlossene Fenster");
      menu.setAttribute("accesskey", "F");
      menu.setAttribute("disabled", "true");
      popup.insertBefore(menu, refItem);

      this.historyUndoWindowPopup3 = menu = menu.appendChild(document.createElement("menupopup"));
      menu.setAttribute("id", "historyUndoWindowPopup3");
      menu.setAttribute("onpopupshowing", "UndoListInTabmenu.populateUndoWindowSubmenu();");
    }

    //UndoClose Tab List  最近閉じたタブ
    const LABELTEXT = locale.indexOf("ja") == -1?"K\u00FCrzlich geschlossene Tabs":"\u6700\u8fd1\u9589\u3058\u305f\u30bf\u30d6";    //create menu
    menu = document.createElement("menu");
    menu.setAttribute("label", LABELTEXT);
    menu.setAttribute("accesskey", "T");
    if (id)
      menu.setAttribute("id", id);
    //menu.setAttribute("disabled", true);
    var menupopup = document.createElement("menupopup");
    if (this.getVer()<3) {
      menupopup.setAttribute("onpopupshowing", "UndoListInTabmenu.populateUndoSubmenu(this);");
    } else if (this.getVer()<3.6) {
      menupopup.setAttribute("onpopupshowing", "UndoListInTabmenu.populateUndoSubmenu3(this);");
    } else {
      menupopup.setAttribute("onpopupshowing", "UndoListInTabmenu.populateUndoSubmenu36(this);");
    }
    menu.appendChild(menupopup);
    popup.insertBefore(menu, refItem);

    //add event listener
    popup.addEventListener('popupshowing',function(event) {
      if (UndoListInTabmenu.getVer() > 3.0)
        UndoListInTabmenu.toggleRecentlyClosedWindows();
      // no restorable tabs, so make sure menu is disabled, and return
      if (UndoListInTabmenu._ss.getClosedTabCount(window) == 0) {
        menu.setAttribute("disabled", true);
        //menu.setAttribute("hidden", true);
        return;
      }
        menu.removeAttribute("disabled");
      //menu.setAttribute("hidden", false);
    },false);
  },

  /**
   * Populate when the history menu is opened  (Fx2)
   */
  populateUndoSubmenu: function(undoPopup) {

    // remove existing menu items
    while (undoPopup.hasChildNodes())
      undoPopup.removeChild(undoPopup.firstChild);

    // populate menu
    var undoItems = eval("(" + UndoListInTabmenu._ss.getClosedTabData(window) + ")");
    for (var i = 0; i < undoItems.length; i++) {
        var m = undoPopup.appendChild(document.createElement("menuitem"));
      m.setAttribute("label", undoItems[i].title);
      m.setAttribute("value", i);
      m.setAttribute("oncommand", "undoCloseTab(" + i + ");");
      m.setAttribute("onclick", "UndoListInTabmenu._undoCloseMiddleClick(event);");
    }

    // "open in tabs"
    var bundleService = Cc["@mozilla.org/intl/stringbundle;1"].
                        getService(Ci.nsIStringBundleService);
    var stringBundle = bundleService.createBundle("chrome://browser/locale/bookmarks/bookmarks.properties");
    undoPopup.appendChild(document.createElement("menuseparator"));
    m = undoPopup.appendChild(document.createElement("menuitem"));
    m.setAttribute("label", stringBundle.GetStringFromName("cmd_bm_openfolder"));
    m.setAttribute("accesskey", stringBundle.GetStringFromName("cmd_bm_openfolder_accesskey"));
    m.addEventListener("command", function() {
      for (var i = 0; i < undoItems.length; i++)
        undoCloseTab();
    }, false);
  },

  /**
    * Re-open a closed tab and put it to the end of the tab strip.
    * Used for a middle click.
    * @param aEvent
    *        The event when the user clicks the menu item
    */
  _undoCloseMiddleClick: function PHM__undoCloseMiddleClick(aEvent) {
    if (aEvent.button != 1)
      return;

    undoCloseTab(aEvent.originalTarget.value);
    gBrowser.moveTabToEnd();
    if (!aEvent.ctrlKey)
      aEvent.originalTarget.parentNode.parentNode.parentNode.hidePopup();
  },

  /**
   * Populate when the history menu is opened (Fx3)
   */
  populateUndoSubmenu3: function(undoPopup) {

    // remove existing menu items
    while (undoPopup.hasChildNodes())
      undoPopup.removeChild(undoPopup.firstChild);

    // "Open All in Tabs"
    var strings = gNavigatorBundle;
    m = undoPopup.appendChild(document.createElement("menuitem"));
    m.setAttribute("label", strings.getString("menuOpenAllInTabs.label"));
    m.setAttribute("accesskey", strings.getString("menuOpenAllInTabs.accesskey"));
    m.addEventListener("command", function() {
      for (var i = 0; i < undoItems.length; i++)
        undoCloseTab();
    }, false);

    undoPopup.appendChild(document.createElement("menuseparator"));

    // populate menu
    var undoItems = eval("(" + UndoListInTabmenu._ss.getClosedTabData(window) + ")");
    for (var i = 0; i < undoItems.length; i++) {
      var entries = undoItems[i].state.entries;
      var tooltiptext = "";
      for (var j = entries.length - 1; j > -1; j--){
        if (j != entries.length - 1)
          tooltiptext += "\n";
        tooltiptext += parseInt(j + 1, 10) + ". " + entries[j].title;
      }
      var m = document.createElement("menuitem");
      m.setAttribute("tooltiptext", tooltiptext);
      m.setAttribute("label", undoItems[i].title);
      if (undoItems[i].image)
        m.setAttribute("image", undoItems[i].image);
      m.setAttribute("class", "menuitem-iconic bookmark-item");
      m.setAttribute("value", i);
      m.setAttribute("oncommand", "undoCloseTab(" + i + ");");
      m.setAttribute("onclick", "UndoListInTabmenu._undoCloseMiddleClick(event);");
      if (i == 0)
        m.setAttribute("key", "key_undoCloseTab");
      undoPopup.appendChild(m);
    }

    // "Clear undo close tb list"
    undoPopup.appendChild(document.createElement("menuseparator"));

    m = undoPopup.appendChild(document.createElement("menuitem"));
    m.setAttribute("label", "Liste der letzten Tabs l\u00F6schen");
    m.setAttribute("accesskey", "l");
    m.addEventListener("command", function() {
      var max_undo = UndoListInTabmenu.getPref("browser.sessionstore.max_tabs_undo", "int", 10);
      UndoListInTabmenu.setPref("browser.sessionstore.max_tabs_undo", "int", 0);
      UndoListInTabmenu.setPref("browser.sessionstore.max_tabs_undo", "int", max_undo);
      if (max_undo != UndoListInTabmenu.getPref("browser.sessionstore.max_tabs_undo", "int", 10))
        UndoListInTabmenu.setPref("browser.sessionstore.max_tabs_undo", "int", max_undo);
    }, false);
  },

  /**
   * Populate when the history menu is opened (Fx3.6)
   */
  populateUndoSubmenu36: function(undoPopup) {

    // remove existing menu items
    while (undoPopup.hasChildNodes())
      undoPopup.removeChild(undoPopup.firstChild);

    // "Open All in Tabs"
    var strings = gNavigatorBundle;
    m = undoPopup.appendChild(document.createElement("menuitem"));
    m.setAttribute("label", strings.getString("menuRestoreAllTabs.label"));
    //m.setAttribute("class", "menuitem-iconic bookmark-item");
    m.setAttribute("accesskey", "R" /*strings.getString("menuRestoreAllTabs.accesskey")*/);
    m.addEventListener("command", function() {
      for (var i = 0; i < undoItems.length; i++)
        undoCloseTab();
    }, false);

    undoPopup.appendChild(document.createElement("menuseparator"));

    // populate menu
    var undoItems = eval("(" + UndoListInTabmenu._ss.getClosedTabData(window) + ")");
    for (var i = 0; i < undoItems.length; i++) {
      var entries = undoItems[i].state.entries;
      var tooltiptext = "";
      for (var j = entries.length - 1; j > -1; j--){
        if (j != entries.length - 1)
          tooltiptext += "\n";
        tooltiptext += parseInt(j + 1, 10) + ". " + entries[j].title;
      }
      var m = document.createElement("menuitem");
      m.setAttribute("tooltiptext", tooltiptext);
      m.setAttribute("label", undoItems[i].title);
      if (undoItems[i].image)
        m.setAttribute("image", undoItems[i].image);
      m.setAttribute("class", "menuitem-iconic bookmark-item");
      m.setAttribute("value", i);
      m.setAttribute("oncommand", "undoCloseTab(" + i + ");");
      m.setAttribute("onclick", "UndoListInTabmenu._undoCloseMiddleClick(event);");
      if (i == 0)
        m.setAttribute("key", "key_undoCloseTab");
      undoPopup.appendChild(m);
    }

    // "Clear undo close tb list"
    undoPopup.appendChild(document.createElement("menuseparator"));

    m = undoPopup.appendChild(document.createElement("menuitem"));
    m.setAttribute("label", "Liste der letzten Tabs l\u00F6schen");
    m.setAttribute("class", "menuitem-iconic bookmark-item");
    m.setAttribute("accesskey", "l");
    m.addEventListener("command", function() {
      var max_undo = UndoListInTabmenu.getPref("browser.sessionstore.max_tabs_undo", "int", 10);
      UndoListInTabmenu.setPref("browser.sessionstore.max_tabs_undo", "int", 0);
      UndoListInTabmenu.setPref("browser.sessionstore.max_tabs_undo", "int", max_undo);
      if (max_undo != UndoListInTabmenu.getPref("browser.sessionstore.max_tabs_undo", "int", 10))
        UndoListInTabmenu.setPref("browser.sessionstore.max_tabs_undo", "int", max_undo);
    }, false);
  },

  toggleRecentlyClosedWindows: function PHM_toggleRecentlyClosedWindows() {
    // enable/disable the Recently Closed Windows sub menu
    let undoPopup = this.historyUndoWindowPopup3;
    // no restorable windows, so disable menu
    if (this._ss.getClosedWindowCount() == 0)
      this.historyUndoWindowPopup3.parentNode.setAttribute("disabled", true);
    else
      this.historyUndoWindowPopup3.parentNode.removeAttribute("disabled");
  },

  /**
   * Populate when the history menu is opened
   */
  populateUndoWindowSubmenu: function PHM_populateUndoWindowSubmenu() {
    let undoPopup = this.historyUndoWindowPopup3;
    let menuLabelString = gNavigatorBundle.getString("menuUndoCloseWindowLabel");
    let menuLabelStringSingleTab =
      gNavigatorBundle.getString("menuUndoCloseWindowSingleTabLabel");

    // remove existing menu items
    while (undoPopup.hasChildNodes())
      undoPopup.removeChild(undoPopup.firstChild);

    // no restorable windows, so make sure menu is disabled, and return
    if (this._ss.getClosedWindowCount() == 0) {
      undoPopup.parentNode.setAttribute("disabled", true);
      return;
    }
    // enable menu
    undoPopup.parentNode.removeAttribute("disabled");
    let undoItems = JSON.parse(this._ss.getClosedWindowData());
    // "Open All in Windows"
    let m = undoPopup.appendChild(document.createElement("menuitem"));
    m.setAttribute("label", gNavigatorBundle.getString("menuRestoreAllWindows.label"));
    //m.setAttribute("class", "menuitem-iconic bookmark-item");
    m.setAttribute("accesskey", "W"/*gNavigatorBundle.getString("menuRestoreAllWindows.accesskey")*/);
    m.setAttribute("oncommand",
      "for (var i = 0; i < " + undoItems.length + "; i++) UndoListInTabmenu.undoCloseWindow();");
    undoPopup.appendChild(document.createElement("menuseparator"));
    // populate menu
    for (let i = 0; i < undoItems.length; i++) {
      let undoItem = undoItems[i];
      let otherTabsCount = undoItem.tabs.length - 1;
      let label = (otherTabsCount == 0) ? menuLabelStringSingleTab
                                        : PluralForm.get(otherTabsCount, menuLabelString);
      let menuLabel = label.replace("#1", undoItem.title)
                           .replace("#2", otherTabsCount);
      let m = document.createElement("menuitem");
      m.setAttribute("label", menuLabel);
      let selectedTab = undoItem.tabs[undoItem.selected - 1];
      if (selectedTab.attributes.image) {
        let iconURL = selectedTab.attributes.image;
        // don't initiate a connection just to fetch a favicon (see bug 467828)
        if (/^https?:/.test(iconURL))
          iconURL = "moz-anno:favicon:" + iconURL;
        m.setAttribute("image", iconURL);
      }
      m.setAttribute("class", "menuitem-iconic bookmark-item");
      m.setAttribute("oncommand", "UndoListInTabmenu.undoCloseWindow(" + i + ");");
      if (i == 0)
        m.setAttribute("key", "key_undoCloseWindow");
      undoPopup.appendChild(m);
    }
  },


  /**
   * Re-open a closed window.
   * @param aIndex
   *        The index of the window (via nsSessionStore.getClosedWindowData)
   * @returns a reference to the reopened window.
   */
  undoCloseWindow: function (aIndex) {
/*  let ss = Cc["@mozilla.org/browser/sessionstore;1"].
             getService(Ci.nsISessionStore);
*/  let ss = SessionStore;      
    let window = null;
    if (ss.getClosedWindowCount() > (aIndex || 0))
      window = ss.undoCloseWindow(aIndex || 0);

    return window;
  },

  getPref: function(aPrefString, aPrefType, aDefault){
    var xpPref = Components.classes['@mozilla.org/preferences-service;1']
                  .getService(Components.interfaces.nsIPrefBranch);
    try{
      switch (aPrefType){
        case 'complex':
          return xpPref.getComplexValue(aPrefString, Components.interfaces.nsILocalFile); break;
        case 'str':
          return xpPref.getCharPref(aPrefString).toString(); break;
        case 'int':
          return xpPref.getIntPref(aPrefString); break;
        case 'bool':
        default:
          return xpPref.getBoolPref(aPrefString); break;
      }
    }catch(e){
    }
    return aDefault;
  },

  setPref: function(aPrefString, aPrefType, aValue){
    var xpPref = Components.classes['@mozilla.org/preferences-service;1']
                  .getService(Components.interfaces.nsIPrefBranch);
    try{
      switch (aPrefType){
        case 'complex':
          return xpPref.setComplexValue(aPrefString, Components.interfaces.nsILocalFile, aValue); break;
        case 'str':
          return xpPref.setCharPref(aPrefString, aValue); break;
        case 'int':
          aValue = parseInt(aValue);
          return xpPref.setIntPref(aPrefString, aValue);  break;
        case 'bool':
        default:
          return xpPref.setBoolPref(aPrefString, aValue); break;
      }
    }catch(e){
    }
    return null;
  },

  //Fxのバージョンを得る
    //Fxのバージョン
  getVer: function(){
    const Cc = Components.classes;
    const Ci = Components.interfaces;
    var info = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULAppInfo);
    var ver = parseInt(info.version.substr(0,3) * 10,10) / 10;
    return ver;
  }
};

if(!('TM_init' in window)) UndoListInTabmenu.init();

Code: Alles auswählen

(function() {

  if (location != 'chrome://browser/content/browser.xul')
    return;

  let tabContextMenu = document.getElementById('tabContextMenu');
  let historyPopup = document.getElementById('goPopup');
  let menubar = document.getElementById('toolbar-menubar');

  tabContextMenu.addEventListener('popupshowing', function(event) {
    if (event.target != this)
      return;
    menubar.style.visibility = 'collapse';
    historyPopup.showPopup();
    document.getElementById('historyUndoPopup').showPopup();
    let dblHistoryUndoMenu = document.getElementById('historyUndoMenu').cloneNode(true);
    dblHistoryUndoMenu.id = 'context_historyUndoMenu';
    dblHistoryUndoMenu.getElementsByTagName('menupopup')[0].removeAttribute('id');
    tabContextMenu.appendChild(dblHistoryUndoMenu);
  });

  tabContextMenu.addEventListener('popuphidden', function(event) {
    if (event.target != this)
      return;
    tabContextMenu.removeChild(document.getElementById('context_historyUndoMenu'));
    setTimeout(function() {
      menubar.style.visibility = '';
    }, 300);
  });

})();

Zuletzt geändert von aborix am Mo, 09. Apr 2018 20:43, insgesamt 1-mal geändert.

Benutzeravatar
Zitronella
Senior-Mitglied
Beiträge: 8578
Registriert: Di, 07. Feb 2012 18:06

Re: Styles und css funktioniert in aktueller Nightly nicht mehr

#58

Beitrag von Zitronella » Mo, 09. Apr 2018 10:59

Danke, es funktionieren beide in Nightly :klasse:
auch wenn sie unterschiedlich aussehen.

Vom ersten Code:
kuerzlich-geschlossene-Tabs-01.png
kuerzlich-geschlossene-Tabs-01.png (6.65 KiB) 402 mal betrachtet
Vom zweiten Code:
kuerzlich-geschlossene-Tabs-02.png
kuerzlich-geschlossene-Tabs-02.png (5.63 KiB) 402 mal betrachtet
Hilfe auch im deutschsprachigen Firefox-Chat möglich.
Meine Anleitungstexte dürfen gerne "geklaut" und weiter verwendet/kopiert werden ;)

Benutzeravatar
Boersenfeger
Senior-Mitglied
Beiträge: 51266
Registriert: So, 21. Mär 2004 13:21
Wohnort: Brunswiek anne Oker dranne

Re: Styles und css funktioniert in aktueller Nightly nicht mehr

#59

Beitrag von Boersenfeger » Mo, 09. Apr 2018 16:30

Auch in Beta... Vielen herzlichen Dank! :) :klasse:
BTW: Das adapierte Script aus der Sammlung UndoListInTabmenuToo.uc.js sollte ggf auf GitHub hochgeladen werden, Firefox 60 kommt.....
Stand 24.5.2018
Mozilla/5.0 (Windows NT 6.1 Win64 x64 rv:60.0) 20100101 Firefox/60.0.1
Mozilla/5.0 (Windows NT 6.1 Win64 x64 rv:61.0) 20180521 Firefox/61.0b7
Mozilla/5.0 (Windows NT 6.1 Win64 x64 rv:62.0) 20180524 Firefox/62.0a1

Meine Füchse|Fehlersuche|Anleitung für Fragen im Forum|Sicherheitskonzept für Windowsnutzer

Benutzeravatar
aborix
Senior-Mitglied
Beiträge: 3983
Registriert: So, 06. Sep 2009 0:57

Re: Button für kürzlich geschlossene Tabs

#60

Beitrag von aborix » Mo, 09. Apr 2018 20:02

In UndoListInTabmenuToo.uc.js aus #57 funktioniert im Tab-Kontextmenü das Wiederherstellen kürzlich geschlossener Fenster nicht.

In folgender Version funktioniert auch das und von mir aus kann das Skript nach GitHub:

Code: Alles auswählen

// ==UserScript==
// @name           UndoListInTabmenuToo
// @namespace      http://space.geocities.yahoo.co.jp/gl/alice0775
// @description    UndoListInTabmenuToo.uc.js
// @include        main
// @compatibility  Firefox 4.0 - 59
// @author         Alice0775
// @version        2017/11/18 nsIPrefBranch to nsIPrefBranch
// @version        2010/09/18 00:00 4.0b7pre
// @version        2009/02/03 13:00 ツールチップにタブ内履歴を表示するようにした
// @Note           タブやコンテキストメニューにもUndoClose Tab Listを追加するもの
// @OriginalCode   browser.jsからpopulateUndoSubmenuを拝借し, ごにょごにょした
// @version        2010/03/26 13:00  Minefield/3.7a4pre Bug 554991 -  allow tab context menu to be modified by normal XUL overlays
// @version        2010/03/15 00:00  Minefield/3.7a4pre Bug 347930 -  Tab strip should be a toolbar instead
// @version        2009/09/09 15:00 中クリック処理
// ==/UserScript==
// @version        2009/09/03 22:00 Firegox3.7a1preで動かなくなっていたのを修正(Bug 489925. getElementById should not return anonymous nodes)
// @version        2009/08/22 00:00 Firegox3.6 stringbandleの変更による
// @version        2009/04/24 00:00 #394759 [Firefox:Session Restore]-Add undo close window feature
// @version        2008/10/12 18:00 Fx3.0.4pre中クリックしたときメニューポップアップが閉じないおよびその他fix
// @version        2007/10/05 10:00

var UndoListInTabmenu = {
// -- config --
  TABCONTEXTMENU : true , //Im Tabkontextmenü: anzeigen: true, nicht anzeigen: false
  CONTEXTMENU    : true,  //Im Hauptkontextmenü: anzeigen: true , nicht anzeigen: false
// -- config end--
  ss: null,

  get tabContext() {
/*  return document.getAnonymousElementByAttribute(
                        gBrowser, "anonid", "tabContextMenu")||
           gBrowser.tabContainer.contextMenu;
*/  return gBrowser.tabContainer.contextMenu;
  },

  init: function(){

    if (this.TABCONTEXTMENU){
      //タブコンテキスト
      var tabContext = this.tabContext;
      this.makePopup(tabContext, null, "tabContextUndoList");
    }
    if (this.CONTEXTMENU){
      //コンテンツエリアコンテキスト
      var contextMenu = document.getElementById("contentAreaContextMenu");
      var refItem = document.getElementById("context-sep-stop");
      this.makePopup(contextMenu, refItem, "ContextUndoList");
    }
    // get closed-tabs from nsSessionStore
/*  this._ss = Cc["@mozilla.org/browser/sessionstore;1"].
               getService(Ci.nsISessionStore);
*/  this._ss = SessionStore;

  },

  makePopup: function(popup, refItem, id){
    var menu;
    //label
/*  const locale = Components.classes["@mozilla.org/preferences-service;1"]
                   .getService(Components.interfaces.nsIPrefBranch).getCharPref("general.useragent.locale");
*/  const locale = '';
    if (this.getVer() > 3.0) {
      // "Recently Closed Windows"
      let idPrefix = id.substring(0, id.length - 15);
      menu = document.createElement("menu");
      //menu.setAttribute("id", "historyUndoWindowMenu3");
      menu.setAttribute("id", idPrefix + "HistoryUndoWindowMenu3");
      menu.setAttribute("label", "K\u00FCrzlich geschlossene Fenster");
      menu.setAttribute("accesskey", "F");
      menu.setAttribute("disabled", "true");
      popup.insertBefore(menu, refItem);
/*
      this.historyUndoWindowPopup3 = menu = menu.appendChild(document.createElement("menupopup"));
      menu.setAttribute("id", "historyUndoWindowPopup3");
      menu.setAttribute("onpopupshowing", "UndoListInTabmenu.populateUndoWindowSubmenu();");
*/
      var undoPopup = (document.createElement("menupopup"));
      undoPopup.setAttribute("id", idPrefix + "HistoryUndoWindowPopup3");
      undoPopup.setAttribute("onpopupshowing", "UndoListInTabmenu.populateUndoWindowSubmenu(this);");
      menu.appendChild(undoPopup);
    }

    //UndoClose Tab List  最近閉じたタブ
    const LABELTEXT = locale.indexOf("ja") == -1?"K\u00FCrzlich geschlossene Tabs":"\u6700\u8fd1\u9589\u3058\u305f\u30bf\u30d6";    //create menu
    menu = document.createElement("menu");
    menu.setAttribute("label", LABELTEXT);
    menu.setAttribute("accesskey", "T");
    if (id)
      menu.setAttribute("id", id);
    //menu.setAttribute("disabled", true);
    var menupopup = document.createElement("menupopup");
    if (this.getVer()<3) {
      menupopup.setAttribute("onpopupshowing", "UndoListInTabmenu.populateUndoSubmenu(this);");
    } else if (this.getVer()<3.6) {
      menupopup.setAttribute("onpopupshowing", "UndoListInTabmenu.populateUndoSubmenu3(this);");
    } else {
      menupopup.setAttribute("onpopupshowing", "UndoListInTabmenu.populateUndoSubmenu36(this);");
    }
    menu.appendChild(menupopup);
    popup.insertBefore(menu, refItem);

    //add event listener
    popup.addEventListener('popupshowing',function(event) {
      if (UndoListInTabmenu.getVer() > 3.0)
        UndoListInTabmenu.toggleRecentlyClosedWindows(undoPopup);
      // no restorable tabs, so make sure menu is disabled, and return
      if (UndoListInTabmenu._ss.getClosedTabCount(window) == 0) {
        menu.setAttribute("disabled", true);
        //menu.setAttribute("hidden", true);
        return;
      }
        menu.removeAttribute("disabled");
      //menu.setAttribute("hidden", false);
    },false);
  },

  /**
   * Populate when the history menu is opened  (Fx2)
   */
  populateUndoSubmenu: function(undoPopup) {

    // remove existing menu items
    while (undoPopup.hasChildNodes())
      undoPopup.removeChild(undoPopup.firstChild);

    // populate menu
    var undoItems = eval("(" + UndoListInTabmenu._ss.getClosedTabData(window) + ")");
    for (var i = 0; i < undoItems.length; i++) {
        var m = undoPopup.appendChild(document.createElement("menuitem"));
      m.setAttribute("label", undoItems[i].title);
      m.setAttribute("value", i);
      m.setAttribute("oncommand", "undoCloseTab(" + i + ");");
      m.setAttribute("onclick", "UndoListInTabmenu._undoCloseMiddleClick(event);");
    }

    // "open in tabs"
    var bundleService = Cc["@mozilla.org/intl/stringbundle;1"].
                        getService(Ci.nsIStringBundleService);
    var stringBundle = bundleService.createBundle("chrome://browser/locale/bookmarks/bookmarks.properties");
    undoPopup.appendChild(document.createElement("menuseparator"));
    m = undoPopup.appendChild(document.createElement("menuitem"));
    m.setAttribute("label", stringBundle.GetStringFromName("cmd_bm_openfolder"));
    m.setAttribute("accesskey", stringBundle.GetStringFromName("cmd_bm_openfolder_accesskey"));
    m.addEventListener("command", function() {
      for (var i = 0; i < undoItems.length; i++)
        undoCloseTab();
    }, false);
  },

  /**
    * Re-open a closed tab and put it to the end of the tab strip.
    * Used for a middle click.
    * @param aEvent
    *        The event when the user clicks the menu item
    */
  _undoCloseMiddleClick: function PHM__undoCloseMiddleClick(aEvent) {
    if (aEvent.button != 1)
      return;

    undoCloseTab(aEvent.originalTarget.value);
    gBrowser.moveTabToEnd();
    if (!aEvent.ctrlKey)
      aEvent.originalTarget.parentNode.parentNode.parentNode.hidePopup();
  },

  /**
   * Populate when the history menu is opened (Fx3)
   */
  populateUndoSubmenu3: function(undoPopup) {

    // remove existing menu items
    while (undoPopup.hasChildNodes())
      undoPopup.removeChild(undoPopup.firstChild);

    // "Open All in Tabs"
    var strings = gNavigatorBundle;
    m = undoPopup.appendChild(document.createElement("menuitem"));
    m.setAttribute("label", strings.getString("menuOpenAllInTabs.label"));
    m.setAttribute("accesskey", strings.getString("menuOpenAllInTabs.accesskey"));
    m.addEventListener("command", function() {
      for (var i = 0; i < undoItems.length; i++)
        undoCloseTab();
    }, false);

    undoPopup.appendChild(document.createElement("menuseparator"));

    // populate menu
    var undoItems = eval("(" + UndoListInTabmenu._ss.getClosedTabData(window) + ")");
    for (var i = 0; i < undoItems.length; i++) {
      var entries = undoItems[i].state.entries;
      var tooltiptext = "";
      for (var j = entries.length - 1; j > -1; j--){
        if (j != entries.length - 1)
          tooltiptext += "\n";
        tooltiptext += parseInt(j + 1, 10) + ". " + entries[j].title;
      }
      var m = document.createElement("menuitem");
      m.setAttribute("tooltiptext", tooltiptext);
      m.setAttribute("label", undoItems[i].title);
      if (undoItems[i].image)
        m.setAttribute("image", undoItems[i].image);
      m.setAttribute("class", "menuitem-iconic bookmark-item");
      m.setAttribute("value", i);
      m.setAttribute("oncommand", "undoCloseTab(" + i + ");");
      m.setAttribute("onclick", "UndoListInTabmenu._undoCloseMiddleClick(event);");
      if (i == 0)
        m.setAttribute("key", "key_undoCloseTab");
      undoPopup.appendChild(m);
    }

    // "Clear undo close tb list"
    undoPopup.appendChild(document.createElement("menuseparator"));

    m = undoPopup.appendChild(document.createElement("menuitem"));
    m.setAttribute("label", "Liste der letzten Tabs l\u00F6schen");
    m.setAttribute("accesskey", "l");
    m.addEventListener("command", function() {
      var max_undo = UndoListInTabmenu.getPref("browser.sessionstore.max_tabs_undo", "int", 10);
      UndoListInTabmenu.setPref("browser.sessionstore.max_tabs_undo", "int", 0);
      UndoListInTabmenu.setPref("browser.sessionstore.max_tabs_undo", "int", max_undo);
      if (max_undo != UndoListInTabmenu.getPref("browser.sessionstore.max_tabs_undo", "int", 10))
        UndoListInTabmenu.setPref("browser.sessionstore.max_tabs_undo", "int", max_undo);
    }, false);
  },

  /**
   * Populate when the history menu is opened (Fx3.6)
   */
  populateUndoSubmenu36: function(undoPopup) {

    // remove existing menu items
    while (undoPopup.hasChildNodes())
      undoPopup.removeChild(undoPopup.firstChild);

    // "Open All in Tabs"
    var strings = gNavigatorBundle;
    m = undoPopup.appendChild(document.createElement("menuitem"));
    m.setAttribute("label", strings.getString("menuRestoreAllTabs.label"));
    //m.setAttribute("class", "menuitem-iconic bookmark-item");
    m.setAttribute("accesskey", "R" /*strings.getString("menuRestoreAllTabs.accesskey")*/);
    m.addEventListener("command", function() {
      for (var i = 0; i < undoItems.length; i++)
        undoCloseTab();
    }, false);

    undoPopup.appendChild(document.createElement("menuseparator"));

    // populate menu
    var undoItems = eval("(" + UndoListInTabmenu._ss.getClosedTabData(window) + ")");
    for (var i = 0; i < undoItems.length; i++) {
      var entries = undoItems[i].state.entries;
      var tooltiptext = "";
      for (var j = entries.length - 1; j > -1; j--){
        if (j != entries.length - 1)
          tooltiptext += "\n";
        tooltiptext += parseInt(j + 1, 10) + ". " + entries[j].title;
      }
      var m = document.createElement("menuitem");
      m.setAttribute("tooltiptext", tooltiptext);
      m.setAttribute("label", undoItems[i].title);
      if (undoItems[i].image)
        m.setAttribute("image", undoItems[i].image);
      m.setAttribute("class", "menuitem-iconic bookmark-item");
      m.setAttribute("value", i);
      m.setAttribute("oncommand", "undoCloseTab(" + i + ");");
      m.setAttribute("onclick", "UndoListInTabmenu._undoCloseMiddleClick(event);");
      if (i == 0)
        m.setAttribute("key", "key_undoCloseTab");
      undoPopup.appendChild(m);
    }

    // "Clear undo close tb list"
    undoPopup.appendChild(document.createElement("menuseparator"));

    m = undoPopup.appendChild(document.createElement("menuitem"));
    m.setAttribute("label", "Liste der letzten Tabs l\u00F6schen");
    m.setAttribute("class", "menuitem-iconic bookmark-item");
    m.setAttribute("accesskey", "l");
    m.addEventListener("command", function() {
      var max_undo = UndoListInTabmenu.getPref("browser.sessionstore.max_tabs_undo", "int", 10);
      UndoListInTabmenu.setPref("browser.sessionstore.max_tabs_undo", "int", 0);
      UndoListInTabmenu.setPref("browser.sessionstore.max_tabs_undo", "int", max_undo);
      if (max_undo != UndoListInTabmenu.getPref("browser.sessionstore.max_tabs_undo", "int", 10))
        UndoListInTabmenu.setPref("browser.sessionstore.max_tabs_undo", "int", max_undo);
    }, false);
  },

  toggleRecentlyClosedWindows: function PHM_toggleRecentlyClosedWindows(undoPopup) {
    // enable/disable the Recently Closed Windows sub menu
/*
    let undoPopup = this.historyUndoWindowPopup3;
    // no restorable windows, so disable menu
    if (this._ss.getClosedWindowCount() == 0)
      this.historyUndoWindowPopup3.parentNode.setAttribute("disabled", true);
    else
      this.historyUndoWindowPopup3.parentNode.removeAttribute("disabled");
*/
    // no restorable windows, so disable menu
    if (this._ss.getClosedWindowCount() == 0)
      undoPopup.parentNode.setAttribute("disabled", true)
    else
      undoPopup.parentNode.removeAttribute("disabled");
  },

  /**
   * Populate when the history menu is opened
   */
  populateUndoWindowSubmenu: function PHM_populateUndoWindowSubmenu(undoPopup) {
    //let undoPopup = this.historyUndoWindowPopup3;
    let menuLabelString = gNavigatorBundle.getString("menuUndoCloseWindowLabel");
    let menuLabelStringSingleTab =
      gNavigatorBundle.getString("menuUndoCloseWindowSingleTabLabel");

    // remove existing menu items
    while (undoPopup.hasChildNodes())
      undoPopup.removeChild(undoPopup.firstChild);

    // no restorable windows, so make sure menu is disabled, and return
    if (this._ss.getClosedWindowCount() == 0) {
      undoPopup.parentNode.setAttribute("disabled", true);
      return;
    }
    // enable menu
    undoPopup.parentNode.removeAttribute("disabled");
    let undoItems = JSON.parse(this._ss.getClosedWindowData());
    // "Open All in Windows"
    let m = undoPopup.appendChild(document.createElement("menuitem"));
    m.setAttribute("label", gNavigatorBundle.getString("menuRestoreAllWindows.label"));
    //m.setAttribute("class", "menuitem-iconic bookmark-item");
    m.setAttribute("accesskey", "W"/*gNavigatorBundle.getString("menuRestoreAllWindows.accesskey")*/);
    m.setAttribute("oncommand",
      "for (var i = 0; i < " + undoItems.length + "; i++) UndoListInTabmenu.undoCloseWindow();");
    undoPopup.appendChild(document.createElement("menuseparator"));
    // populate menu
    for (let i = 0; i < undoItems.length; i++) {
      let undoItem = undoItems[i];
      let otherTabsCount = undoItem.tabs.length - 1;
      let label = (otherTabsCount == 0) ? menuLabelStringSingleTab
                                        : PluralForm.get(otherTabsCount, menuLabelString);
      let menuLabel = label.replace("#1", undoItem.title)
                           .replace("#2", otherTabsCount);
      let m = document.createElement("menuitem");
      m.setAttribute("label", menuLabel);
      let selectedTab = undoItem.tabs[undoItem.selected - 1];
      if (selectedTab.attributes.image) {
        let iconURL = selectedTab.attributes.image;
        // don't initiate a connection just to fetch a favicon (see bug 467828)
        if (/^https?:/.test(iconURL))
          iconURL = "moz-anno:favicon:" + iconURL;
        m.setAttribute("image", iconURL);
      }
      m.setAttribute("class", "menuitem-iconic bookmark-item");
      m.setAttribute("oncommand", "UndoListInTabmenu.undoCloseWindow(" + i + ");");
      if (i == 0)
        m.setAttribute("key", "key_undoCloseWindow");
      undoPopup.appendChild(m);
    }
  },


  /**
   * Re-open a closed window.
   * @param aIndex
   *        The index of the window (via nsSessionStore.getClosedWindowData)
   * @returns a reference to the reopened window.
   */
  undoCloseWindow: function (aIndex) {
/*  let ss = Cc["@mozilla.org/browser/sessionstore;1"].
             getService(Ci.nsISessionStore);
*/  let ss = SessionStore;
    let window = null;
    if (ss.getClosedWindowCount() > (aIndex || 0))
      window = ss.undoCloseWindow(aIndex || 0);

    return window;
  },

  getPref: function(aPrefString, aPrefType, aDefault){
    var xpPref = Components.classes['@mozilla.org/preferences-service;1']
                  .getService(Components.interfaces.nsIPrefBranch);
    try{
      switch (aPrefType){
        case 'complex':
          return xpPref.getComplexValue(aPrefString, Components.interfaces.nsILocalFile); break;
        case 'str':
          return xpPref.getCharPref(aPrefString).toString(); break;
        case 'int':
          return xpPref.getIntPref(aPrefString); break;
        case 'bool':
        default:
          return xpPref.getBoolPref(aPrefString); break;
      }
    }catch(e){
    }
    return aDefault;
  },

  setPref: function(aPrefString, aPrefType, aValue){
    var xpPref = Components.classes['@mozilla.org/preferences-service;1']
                  .getService(Components.interfaces.nsIPrefBranch);
    try{
      switch (aPrefType){
        case 'complex':
          return xpPref.setComplexValue(aPrefString, Components.interfaces.nsILocalFile, aValue); break;
        case 'str':
          return xpPref.setCharPref(aPrefString, aValue); break;
        case 'int':
          aValue = parseInt(aValue);
          return xpPref.setIntPref(aPrefString, aValue);  break;
        case 'bool':
        default:
          return xpPref.setBoolPref(aPrefString, aValue); break;
      }
    }catch(e){
    }
    return null;
  },

  //Fxのバージョンを得る
    //Fxのバージョン
  getVer: function(){
    const Cc = Components.classes;
    const Ci = Components.interfaces;
    var info = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULAppInfo);
    var ver = parseInt(info.version.substr(0,3) * 10,10) / 10;
    return ver;
  }
};

if(!('TM_init' in window)) UndoListInTabmenu.init();


Antworten

Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 3 Gäste