diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md index 5865a23..519d825 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,39 @@ -# firefox-keyboard-shortcuts +# Firefox keyboard shortcuts +Had enough of accidentally hitting a wrong key? Wondering if you can do +something about it? Years of suffering, yet no real progress? Read on. -It's a surprisingly involved process to edit built-in shortcuts (like Ctrl-R) in Firefix, the browser that Hackmaster recommends. \ No newline at end of file +## Quick start + +1. Locate your firefox installation folder. On Windows check `C:\Program Files\Mozilla Firefox`. + You need the directory that contains the firefox executable. +2. Navigate to `defaults/pref` subfolder, it will probably contain a `channel-prefs.js` file. +3. Copy the `defaults/pref/autoconfig.js` file there. You will likely have to do this as superuser. +4. Copy the main `autoconfig.js` file (a different one) to the main folder, next to the firefox itself. +5. Restart firefox and enjoy. + +## Enjoy what, exactly? +The shipped config completely disables a number of built-in shortcuts. This is the functionality we +find most useful ourselves, if you need something else you'll have to edit the `autoconfig.js` to +suit your own purpose. + +## Anything else? +For debugging purposes it sets a superfluous preference that you can find in your `about:config` if +you search for `hackmaster`. If there's nothing, the file didn't load. + +## What if I want some of shortcuts back? +Edit the file and delete the ids you want to keep. + +## What if I want to disable more shortcuts? +Check out provided `keys.html`, locate the ids you want to disable and add them to the array. + +## What if I want to edit a shortcut? +You are in for quite a ride. The shipped config removes the attributes from XML nodes, you will have +to change their values instead. Theoretically, it should work, but please don't ask us for advice or +guidance. + +## Grumpy Mute wishes to add +Another sea of bullshit navigated. + +Don't you like getting your feet dirty in the crossover between moldy legacy +and undocumented changes? No API reference, shitty DX, unjustifiable complexity, +everything, everywhere, all at once. Delicious. diff --git a/autoconfig.js b/autoconfig.js new file mode 100644 index 0000000..51aa031 --- /dev/null +++ b/autoconfig.js @@ -0,0 +1,36 @@ +// based on https://support.mozilla.org/en-US/questions/1378404#answer-1510431 +try { + const hotkeys_to_disable = [ + 'openFileKb', + 'key_savePage', + 'printKb', + 'key_close', + 'key_closeWindow', + 'key_toggleMute', + 'key_reload', + 'key_reload_skip_cache', + 'key_quitApplication', + ]; + new (class { + attributes_to_remove = ['command', 'key', 'modifiers', 'oncommand', 'data-l10n-id']; + services = globalThis.Services || ChromeUtils.import('resource://gre/modules/Services.jsm').Services; + re_href = /^(chrome:(?!\/\/(global\/content\/commonDialog|browser\/content\/webext-panels)\.x?html)|about:(?!blank))/i; // whatever, I'm not refactoring this + constructor() { if (!this.services.appinfo.inSafeMode) this.services.obs.addObserver(this, 'chrome-document-global-created', false); } + observe(w) { w.addEventListener('DOMContentLoaded', this, {once: true}); } // Tempting to check location here, but we don't have it yet + handleEvent(e) { + const D = e.originalTarget, W = D.defaultView, L = W.location; + if (!L || !this.re_href.test(L.href)) return; + if (!W._gBrowser && !W.Tabbrowser) return; // https://bugzilla.mozilla.org/show_bug.cgi?id=1930654 +//displayError('debug', '[ ' + L.href + ' | ' + W.document.getElementById('key_reload') + ' ]'); + hotkeys_to_disable.forEach(n => { + const k = W.document.getElementById(n); +//displayError('debug', '[ ' + n + ' | ' + k + ' ]'); + if (k !== null) this.attributes_to_remove.forEach(a => k.removeAttribute(a)); + }); + } + })() +} catch (e) { + displayError('hackmaster', e); +} + +lockPref("hackmaster.autoconfig.loaded", "a miracle, really"); diff --git a/defaults/pref/autoconfig.js b/defaults/pref/autoconfig.js new file mode 100644 index 0000000..42f7d9b --- /dev/null +++ b/defaults/pref/autoconfig.js @@ -0,0 +1,7 @@ +// based on https://support.mozilla.org/en-US/questions/1378404#answer-1510431 +// apparently, this is a strange subset of JS +// semicolons are required +// basically, do not edit except for the filename below +pref('general.config.filename', 'autoconfig.js'); +pref('general.config.obscure_value', 0); +pref('general.config.sandbox_enabled', false); diff --git a/keys.html b/keys.html new file mode 100644 index 0000000..8dc136c --- /dev/null +++ b/keys.html @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +