Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restart button + filemenu / hamburgermenu Einträge #8

Open
stonecrusher opened this issue Feb 12, 2018 · 0 comments
Open

Restart button + filemenu / hamburgermenu Einträge #8

stonecrusher opened this issue Feb 12, 2018 · 0 comments

Comments

@stonecrusher
Copy link

stonecrusher commented Feb 12, 2018

Dieses Skript ist das beste, das ich bisher gefunden habe und ist zukunftssicher, da ohne XUL:

via https://luke-baker.github.io/chrome/Buttons_restart.uc.js

// ==UserScript==
// @name                 Restart button and menu entries
// @version              1.0.1
// @description          A toolbar button and menu entries that restart Firefox.
// @author               https://www.reddit.com/user/Luke-Baker/
// @license              https://creativecommons.org/licenses/by-sa/4.0/
// @credits              This is Sporif's restart button + menu entries + different icon | https://gist.github.com/Sporif/ad6e917d87787491538bac80d3c8918c
// @compatibility        Created 2018-01-15. Tested on Firefox 69.
// ==/UserScript==

(function() {
	if(location != 'chrome://browser/content/browser.xhtml')
    return;

  const text = "Restart";
  const icon = "list-style-image: url(chrome://browser/skin/sync.svg)";

  try {
    CustomizableUI.createWidget({
      id: 'restart-button',
      type: 'custom',
      defaultArea: CustomizableUI.AREA_NAVBAR,
      onBuild: function(aDocument) {
        var toolbaritem = aDocument.createElementNS('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul', 'toolbarbutton');
        toolbaritem.onclick = event => restartNow(event);
        var props = {
          id: 'restart-button',
          class: 'toolbarbutton-1 chromeclass-toolbar-additional',
          label: text,
          tooltiptext: text,
          style: icon
        };
        for(var p in props)
          toolbaritem.setAttribute(p, props[p]);
        return toolbaritem;
      }
    });
  } catch(e) {};
  
  function restartNow(event) {
    if(event.button == 1)
      Services.appinfo.invalidateCachesOnRestart();
    else if(event.button == 2) 
      return;

    let cancelQuit = Cc["@mozilla.org/supports-PRBool;1"].createInstance(Ci.nsISupportsPRBool);
    Services.obs.notifyObservers(cancelQuit, "quit-application-requested", "restart");
    if(!cancelQuit.data) 
      Services.startup.quit(Services.startup.eAttemptQuit | Services.startup.eRestart);
  }

  // Hamburger menu entry
  var menupanelexit = document.getElementById("appMenu-quit-button");
  var menupanelrestart = document.createElementNS('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul', 'toolbarbutton');
  menupanelrestart.setAttribute("id","appMenu-restart-button");
  menupanelrestart.setAttribute("class","subviewbutton subviewbutton-iconic");
  menupanelrestart.setAttribute("label",text);
  menupanelrestart.setAttribute("style",icon);
  menupanelrestart.onclick = event => restartNow(event);
  menupanelexit.parentNode.insertBefore(menupanelrestart, menupanelexit);

  // File menu entry
  var menufileexit = document.getElementById("menu_FileQuitItem");
  var menufilerestart = document.createElementNS('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul', 'menuitem');
  menufilerestart.setAttribute("id","menu_FileRestartItem");
  menufilerestart.setAttribute("label",text);
  menufilerestart.setAttribute("accesskey","R");
  menufilerestart.addEventListener("command", restartNow, false);
  menufileexit.parentNode.insertBefore(menufilerestart, menufileexit);
/**/
})();

Ist angesichts des Alters der Restartbuttonskripte hier imho eine Überlegung wert für die Sammlung.

Flexibel, da man evtl ungewünschte Teile wie die Dateimenü-Einträge einfach löschen kann und den Toolbarbutton kann man anpassen wie alle anderen Toolbarbuttons auch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant