MozillaZine

keyconfig 20110522

Announce and Discuss the Latest Theme and Extension Releases.
avada
 
Posts: 1847
Joined: February 10th, 2008, 6:30 am
Location: Hungary

Post Posted June 27th, 2019, 6:37 am

morat wrote:@avada

Try something like:

Code: Select all
var css = [];
css.push("#TabsToolbar { visibility: collapse !important; }");
// css.push("...");
// css.push("...");
var ios = Components.classes["@mozilla.org/network/io-service;1"].
  getService(Components.interfaces.nsIIOService);
var uri = ios.newURI("data:text/css," + encodeURIComponent(css.join("\n")), null, null);
var sss = Components.classes["@mozilla.org/content/style-sheet-service;1"].
  getService(Components.interfaces.nsIStyleSheetService);
if (sss.sheetRegistered(uri, sss.USER_SHEET)) {
  sss.unregisterSheet(uri, sss.USER_SHEET);
} else {
  sss.loadAndRegisterSheet(uri, sss.USER_SHEET);
}


Thanks. I'll try it.

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

Post Posted September 22nd, 2019, 10:14 am

The developer of Dorando keyconfig is having trouble updating the extension for Thunderbird 68.

Thunderbird 68 support
http://github.com/trlkly/dorando-keyconfig/issues/30

Anyone available to help port to Thunderbird 68?
http://thunderbird.topicbox.com/groups/addons/T94970ef450a23064-Medc14b58f96dc7654d8d20f5

pintassilgo
 
Posts: 163
Joined: August 30th, 2013, 3:50 pm

Post Posted September 22nd, 2019, 10:32 pm

keyconfig for Fx 68:
https://github.com/xiaoxiaoflood/firefo ... config.xpi

Tb 68 uses Gecko 68, right? So it should be similar.

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

Post Posted September 23rd, 2019, 6:43 am

@pintassilgo

Thanks.

In the keyconfig.xpi install.rdf file...

Firefox minVersion: 66.0a1
Firefox maxVersion: *

Thunderbird minVersion: 5.0b1
Thunderbird maxVersion: 61.0

I tried the extension after added a manifest.json file. I got a number of errors as expected.

* manifest.json

Code: Select all
{
  "manifest_version": 2,
  "name": "Dorando keyconfig",
  "description": "Rebind your keys.",
  "version": "2018.2.69.2019.07.07-xiao",
  "author": "Dorando",
  "homepage_url": "http://mozilla.dorando.at/",
  "icons": {
    "32": "icon.png",
    "64": "icon64.png"
  },
  "legacy": {
    "type" : "bootstrap",
    "options": {
      "page": "chrome://keyconfig/content/",
      "open_in_tab": false
    }
  },
  "applications": {
    "gecko": {
      "id": "keyconfig@mozilla.dorando.at",
      "strict_min_version": "68.0"
    }
  }
}

Lightning 68.1.0
Thunderbird Portable 68.1.0
Windows 7 SP1 32-bit

I posted the info about a Dorando keyconfig version that works with Firefox 68 in the Thunderbird 68 support thread.

About Thunderbird Addons
http://developer.thunderbird.net/add-ons/about-add-ons

Changes in Thunderbird 61-68
http://developer.thunderbird.net/add-ons/updates/tb68

Thunderbird WebExtension APIs
http://thunderbird-webextensions.readthedocs.io/
http://thunderbird-webextensions.readthedocs.io/en/68/legacy.html

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

Post Posted September 25th, 2019, 10:23 am

You can use the userChromeJS extension to modify key bindings in Thunderbird 68. (for advance users only)

Example:

Code: Select all
/* Thunderbird userChrome.js */

(function () {

  /* List of common chrome urls:
   *
   * 3pane window > chrome://messenger/content/messenger.xul
   * message window > chrome://messenger/content/messageWindow.xul
   * compose window > chrome://messenger/content/messengercompose/messengercompose.xul
   * address book window > chrome://messenger/content/addressbook/addressbook.xul
   * prompt window > chrome://global/content/commonDialog.xul
   *
   */

  if (location == "chrome://messenger/content/messenger.xul") {
    setTimeout(function () {
      try {

        /* unbind Help F1 */

        var keyset = document.getElementById("mailKeys");
        var key = document.getElementById("key_openHelp");
        keyset.removeChild(key);

        /* bind Example F1 */

        window.__unique_identifier_example = function (event) {
          alert("Example 1");
        };
        var keyset = document.getElementById("mailKeys");
        var key = document.createXULElement("key");
        key.setAttribute("id", "__unique_identifier_key_example");
     // key.setAttribute("key", "A"); // A
     // key.setAttribute("modifiers", "control,shift"); // Ctrl+Shift
     // key.setAttribute("modifiers", "alt"); // Alt
        key.setAttribute("keycode", "VK_F1"); // F1
     // key.setAttribute("command", "cmd_toggleQuickFilterBar");
        key.setAttribute("oncommand", "__unique_identifier_example(event);");
     // key.setAttribute("oncommand", "alert('Example 2');");
        keyset.appendChild(key);

      } catch (e) {
        Components.utils.reportError(e);
      };
    }, 1000);
  }
  if (location == "chrome://messenger/content/messageWindow.xul") {}
  if (location == "chrome://messenger/content/messengercompose/messengercompose.xul") {}
  if (location == "chrome://messenger/content/addressbook/addressbook.xul") {}
  if (location == "chrome://global/content/commonDialog.xul") {}

})();

userChromeJS by jikamens
http://addons.thunderbird.net/thunderbird/addon/986610

Instructions:

1. install userChromeJS extension
2. close email client
3. create or edit the userChrome.js file in the chrome folder
4. open email client

You do not need to purge the caches with jikamens' version.

userChromeJS by alta88 (obsolete)
http://userchromejs.mozdev.org/
http://userchromejs.mozdev.org/faq.html

P.S.

You can view the source of a common chrome url using the error console.

i.e. Tools > Developer Tools > Error Console (Ctrl+Shift+J)

Code: Select all
(function () {
  var urls = ["chrome://messenger/content/messenger.xul",
    "chrome://messenger/content/messageWindow.xul",
    "chrome://messenger/content/messengercompose/messengercompose.xul",
    "chrome://messenger/content/addressbook/addressbook.xul",
    "chrome://global/content/commonDialog.xul"];
  document.getElementById("tabmail").openTab("contentTab", {
    contentPage: "view-source:" + urls[0],
  });
})();

Reference
http://dxr.mozilla.org/comm-release/search?q=mailKeys+file%3Amessenger.xul
http://dxr.mozilla.org/comm-release/search?q=key_openHelp+file%3AmainKeySet.inc.xul
http://dxr.mozilla.org/comm-release/search?q=productHelp.commandkey+ext%3Adtd
http://dxr.mozilla.org/comm-release/source/mail/config/version.txt
Last edited by morat on September 27th, 2019, 5:16 am, edited 1 time in total.

bege
 
Posts: 119
Joined: January 23rd, 2009, 9:14 pm
Location: Germany

Post Posted September 26th, 2019, 10:42 am

morat wrote:You can use the userChromeJS extension to modify key bindings in Thunderbird 68. (for advance users only)

Thank you very much!

How must these be named in Firefox?
("key_openHelp")
("mailKeys")

How can I find the IDs of other keys in Thunderbird and Firefox?

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

Post Posted September 26th, 2019, 1:25 pm

@bege

userChromeJS is a legacy bootstrap extension. It doesn't work with Firefox.

You can use a trick to show the <keyset> and <key> elements using the error console.

i.e. Tools > Developer Tools > Error Console (Ctrl+Shift+J)

Code: Select all
setTimeout(function () {
  function getCommand(event) {
    window.removeEventListener("command", getCommand, true);
    event.preventDefault();
    event.stopPropagation();
    console.log(event.originalTarget.parentElement);
    console.log(event.originalTarget);
    console.log("event listener is removed");
    Services.wm.getMostRecentWindow("devtools:webconsole").focus();
  }
  window.addEventListener("command", getCommand, true);
  console.log("event listener is added");
}, 2000);

For example, pressing F8 in the 3pane window after running the code in the error console would output the following elements.

<keyset id="mailKeys">

<key id="key_toggleMessagePane" keycode="VK_F8" oncommand="goDoCommand('cmd_toggleMessagePane');">

The trick does not work for all user interface elements.

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

Post Posted September 28th, 2019, 11:45 am

@bege

I got an example script working with Firefox Portable 69 in Windows.

Deploying Firefox in an enterprise environment
http://developer.mozilla.org/docs/Mozilla/Firefox/Enterprise_deployment_before_60

* C:\FirefoxPortable\App\Firefox\defaults\pref\autoconfig.js

Code: Select all
// autoconfig.js file needs to start with a comment line

// mozilla.cfg file is sandboxed by default i.e. can't use the Components object
// disable the sandbox by setting the general.config.sandbox_enabled pref to false

pref("general.config.sandbox_enabled", false);
pref("general.config.filename", "mozilla.cfg");
pref("general.config.obscure_value", 0);

* C:\FirefoxPortable\App\Firefox\mozilla.cfg

Code: Select all
// mozilla.cfg file needs to start with a comment line

Components.utils.import("resource://gre/modules/Services.jsm");

Services.obs.addObserver(function (aSubject, aTopic, aData) {
  // Services.obs.removeObserver(arguments.callee, "browser-delayed-startup-finished");
  var chromeWindow = aSubject;
  chromeWindow.setTimeout(function () {
    // Services.console.logStringMessage("test mozilla.cfg");
    // Services.prompt.alert(chromeWindow, "example", "test mozilla.cfg");
    try {

      /* unbind Find Again F3, note: key element has no id attribute */

      var keyset = chromeWindow.document.getElementById("mainKeyset");
      var key = chromeWindow.document.querySelector('key[keycode="VK_F3"][command="cmd_findAgain"]');
      keyset.removeChild(key);

      /* bind Example F3 */

      chromeWindow.__unique_identifier_example = function (event) {
        chromeWindow.alert("Example 1");
      };
      var keyset = chromeWindow.document.getElementById("mainKeyset");
      var key = chromeWindow.document.createXULElement("key");
      key.setAttribute("id", "__unique_identifier_key_example");
   // key.setAttribute("key", "A"); // A
   // key.setAttribute("modifiers", "control,shift"); // Ctrl+Shift
   // key.setAttribute("modifiers", "alt"); // Alt
      key.setAttribute("keycode", "VK_F3"); // F3
   // key.setAttribute("command", "cmd_toggleOfflineStatus");
      key.setAttribute("oncommand", "__unique_identifier_example(event);");
   // key.setAttribute("oncommand", "alert('Example 2');");
      keyset.appendChild(key);

    } catch (e) {
      Components.utils.reportError(e); // [check] Show Content Messages
    };
  }, 1000);
}, "browser-delayed-startup-finished", false);

Observer Notifications
http://developer.mozilla.org/docs/Mozilla/Tech/XPCOM/Observer_Notifications

Reference
view-source:chrome://browser/content/browser.xhtml
view-source:chrome://browser/locale/browser.dtd

bege
 
Posts: 119
Joined: January 23rd, 2009, 9:14 pm
Location: Germany

Post Posted September 29th, 2019, 8:59 am

@morat
Thank you very much.
If I want to unbind a key, e.g. F1, do I need to know the command or is the keycode enough? If not, how do I find out the command? I tried the code you posted for Thunderbird, but that works only for very few keys in Firefox.

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

Post Posted September 29th, 2019, 10:22 am

@bege

The example script like the keyconfig extension only works with shortcuts created with a key element, not with shortcuts created with an event listener.

key element
http://developer.mozilla.org/docs/Archive/Mozilla/XUL/key

You need to find the key element for the Find Again F3 shortcut to unbind the key.

Try searching for a line with the "F3" string in the browser.dtd file.

Code: Select all
<!ENTITY findAgainCmd.commandkey2 "VK_F3">

Try searching for a line with the "findAgainCmd.commandkey2" string in the browser.xhtml file.

Code: Select all
<key keycode="&findAgainCmd.commandkey2;" command="cmd_findAgain"/>

The key element doesn't have an id attribute, so I'm using the document.querySelector() method instead of the document.getElementById() method.

P.S.

I didn't think Firefox had a F1 shortcut.

Firefox shortcuts
http://support.mozilla.org/kb/keyboard-shortcuts-perform-firefox-tasks-quickly

bege
 
Posts: 119
Joined: January 23rd, 2009, 9:14 pm
Location: Germany

Post Posted September 30th, 2019, 7:39 am

Thank you again.
morat wrote:I didn't think Firefox had a F1 shortcut.

What may be the reason that binding a command to F1 does not work in Firefox?
This script works with Alt+W but not with F1.

Code: Select all
// ==UserScript==
// key.CloseAllTabs_aborix.uc.js
// https://www.camp-firefox.de/forum/viewtopic.php?p=1099118#p1099118
// ==/UserScript==

(function() {

  var browser_chrome = AppConstants.BROWSER_CHROME_URL;

  if (location != browser_chrome)
    return;
 
  let key = document.createXULElement('key');
  key.id = 'key_closeAllTabs';
  key.setAttribute('key', 'W');
  // key.setAttribute('keycode', 'VK_F1')
  key.setAttribute('modifiers', 'alt');
  key.setAttribute('oncommand',
    'gBrowser.removeAllTabsBut(gBrowser.selectedTab); gBrowser.removeTab(gBrowser.selectedTab);');
  document.getElementById('mainKeyset').appendChild(key);

})();

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

Post Posted September 30th, 2019, 9:14 am

The code snippets succeed for me using the browser console.

Code: Select all
(function () {
  var browser_chrome = AppConstants.BROWSER_CHROME_URL;
  if (location != browser_chrome) return;
  var key = document.createXULElement('key');
  key.id = 'key_closeAllTabs';
  key.setAttribute('keycode', 'VK_F1');
  key.setAttribute('oncommand', 'gBrowser.removeAllTabsBut(gBrowser.selectedTab); gBrowser.removeTab(gBrowser.selectedTab);');
  document.getElementById('mainKeyset').appendChild(key);
})();

Code: Select all
(function () {
  var keyset = document.getElementById('mainKeyset');
  var key = document.createXULElement('key');
  key.setAttribute('id', '__unique_identifier_key_test');
  key.setAttribute('keycode', 'VK_F1');
  key.setAttribute('oncommand', 'alert("test");');
  keyset.appendChild(key);
})();

If the code snippets fail for you, then try disabling all extensions, restart and test again using the browser console.

Browser Console command line
http://developer.mozilla.org/docs/Tools ... mmand_line

bege
 
Posts: 119
Joined: January 23rd, 2009, 9:14 pm
Location: Germany

Post Posted September 30th, 2019, 10:08 am

After entering the code in the console this error is in the console:
NS_NOINTERFACE: Component returned failure code: 0x80004002 (NS_NOINTERFACE) [nsISupports.QueryInterface] stack-trace-collector.js:90

If I then press F1 the console shows this error:
uncaught exception: Object

Do you have any idea before I do more testing?

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

Post Posted September 30th, 2019, 12:33 pm

Try checking for key elements with the keycode="VK_F1" attribute using the browser console.

Code: Select all
console.log(document.querySelectorAll('key[keycode="VK_F1"]').length); // 0

Code: Select all
console.log(document.querySelectorAll('key[keycode="VK_F3"]').length); // 2
console.log(document.querySelectorAll('key[keycode="VK_F3"]')[0]);     // Find Again    F3
console.log(document.querySelectorAll('key[keycode="VK_F3"]')[1]);     // Find Previous Shift+F3

Try testing the second code snippet using the browser console in a fresh profile or a fresh Firefox Portable install.

Firefox Portable
http://portableapps.com/apps/internet/firefox_portable

I get the stack-trace-collector.js error as well. Ignore it.

stack-trace-collector.js error message
http://bugzilla.mozilla.org/show_bug.cgi?id=1565343

highfalutin
New Member
 
Posts: 1
Joined: October 1st, 2019, 7:13 pm

Post Posted October 1st, 2019, 7:21 pm

Thanks to the guidance from previous posters, I installed userChromeJs and successfully brought back some of my favorite Gmail-style keyboard shortcuts with the following chrome/userChrome.js file inside my TB profile directory:

Code: Select all
/* Thunderbird userChrome.js */

(function () {

  function unbindKey(id, keyChar, keycode, modifiers) {
    var key;
    if (typeof id == "string") {
      key = document.getElementById(id);
    } else {
      if (typeof modifiers == "string") {
        modifierClause = '[modifiers="' + modifiers + '"]';
      } else {
        modifierClause = ':not([modifiers])'
      }
      if (typeof keyChar == "string") {
        key = document.querySelector('key[key="' + keyChar + '"]' + modifierClause);
      } else if (typeof keycode == "string") {
        key = document.querySelector('key[keycode="' + keycode + '"]' + modifierClause);
      }
    }
    if ((key !== null) && (typeof key == 'object') && (typeof key.removeAttribute == 'function')) {
      key.removeAttribute("key");
      key.removeAttribute("keycode");
    }
  }

  function changeKeyStrokeForKeyId(id, keyChar, keycode, modifiers) {
    unbindKey(null, keyChar, keycode, modifiers);
    var key = document.getElementById(id);
    if (typeof keyChar == "string") {
      key.setAttribute("key", keyChar);
      key.removeAttribute("keycode");
    } else if (typeof keycode == "string") {
      key.setAttribute("keycode", keycode);
      key.removeAttribute("key");
    }
    if (typeof modifiers == "string") {
      key.setAttribute("modifiers", modifiers);
    } else {
      key.removeAttribute("modifiers");
    }
  }

  function changeMessageViewShortcuts() {
    changeKeyStrokeForKeyId("key_archive", "e");
    changeKeyStrokeForKeyId("key_reply", "r");
    changeKeyStrokeForKeyId("key_replyall", "a");
    changeKeyStrokeForKeyId("key_forward", "f");
    changeKeyStrokeForKeyId("key_newMessage", "c");
    changeKeyStrokeForKeyId("key_searchMail", "/");
    changeKeyStrokeForKeyId("key_delete", "3", null, "shift");
    unbindKey(null, "3", null, "shift any");
  }

  /* List of common chrome urls:
   *
   * 3pane window > chrome://messenger/content/messenger.xul
   * message window > chrome://messenger/content/messageWindow.xul
   * compose window > chrome://messenger/content/messengercompose/messengercompose.xul
   * address book window > chrome://messenger/content/addressbook/addressbook.xul
   * prompt window > chrome://global/content/commonDialog.xul
   *
   */

  if (location == "chrome://messenger/content/messenger.xul") {
    setTimeout(function () {
      try {
        changeMessageViewShortcuts();
      } catch (e) {
        Components.utils.reportError(e);
      };
    }, 1000);
  }

  if (location == "chrome://messenger/content/messageWindow.xul") {
    setTimeout(function () {
      try {
        changeMessageViewShortcuts();
      } catch (e) {
        Components.utils.reportError(e);
      };
    }, 1000);
  }

  if (location == "chrome://messenger/content/messengercompose/messengercompose.xul") {}
  if (location == "chrome://messenger/content/addressbook/addressbook.xul") {}
  if (location == "chrome://global/content/commonDialog.xul") {}

})();

Return to Extension/Theme Releases


Who is online

Users browsing this forum: Bing [Bot] and 2 guests