Unable to disable ctrl-w in Firefox with userchrome.js

Viewed 401

I have been spending too much time using nano in linux, and now I find myself trying to use control-w in Firefox to search. Unfortunately control-w maps to "close tab" in Firefox and the results are unfortunate.

I have loaded the userchromeJS add-on (this is an older version of Firefox and userchromeJS will work) and told it to load all files in the chrome directory:

/*
 * userChromeJS 
 * 
 * This file can be used to customize the functioning of Mozilla's user
 * interface.  Usage and syntax follow below; for useful code snippets see
 * http://mozilla.zeniko.ch/userchrome.js.html.
 */


/* 
 * NOTE: userChromeJS includes an 'import' function to facilitate file management.
 * An absolute path or relative path with Directory name property token can be
 * used, as follows:
 * 
 * // Single file (javascript .js or overlay .xul file)
 * userChrome.import("Full file path");
 * userChrome.import("Relative file path", "Token");
 * // All .js and .xul files in a folder will be loaded. 
 * userChrome.import("Full file folder path");
 * userChrome.import("Relative file folder path/name", "Token");
 * userChrome.import("*", "Token");
 * 
 * NOTE: absolute windows files and folders must be have backslash escaped:
 * "C:\\Program Files\\Mozilla\\scripts\\myscript.js"
 * 
 * Examples:
 * // Import script in [ProfileDir]/chrome/scripts/myscript.js
 * userChrome.import("scripts/myscript.js", "UChrm");
 * // Import script in [Profiles]/scripts/myscript.js (share same script in
 * // multiple profiles
 * userChrome.import("scripts/myscript.js", "DefProfRt");
 * // All .js or .xul in profile chrome directory
 * userChrome.import("*", "UChrm");
 * // Import overlay
 * userChrome.import("C:\\Program Files\\Mozilla\\scripts\\myOverlay.xul");
 * // Import everything in Desktop folder /scripts
 * userChrome.import("scripts", "Desk");
 * // Perhaps the only thing you need in this file.
 * if (location == "chrome://browser/content/browser.xul") {
 *  userChrome.import("scripts", "DefProfRt");
 * }
 */

/* Import all .js or .xul in profile chrome directory */
userChrome.import("*", "UChrm");

And added an interception for control-w in file disable_ctrl_w.js as follows:

var kwa = document.getElementById('key_closeTab');
if (kwa) kwa.remove();

based on the interception for control-q:

var kqa = document.getElementById('key_quitApplication');
if (kqa) kqa.remove();

I was unable to find an example of disabling control-w using userchrome.js, but based on the key definitions at the link below I believe key_closeTab is the correct name.

https://hg.mozilla.org/releases/mozilla-release/file/9f3cb9952ec4/mobile/chrome/content/browser.xul

Unfortunately control-w is still terminating Firefox. Firefox tampering is not my long suit; does someone see where the failure is?

0 Answers
Related