Skip to content

Instantly share code, notes, and snippets.

@jscher2000
Last active July 25, 2021 05:25
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jscher2000/1037c1e95015470289eb4241c3731fc5 to your computer and use it in GitHub Desktop.
Save jscher2000/1037c1e95015470289eb4241c3731fc5 to your computer and use it in GitHub Desktop.
Browser Console Script to Update Copy Link accelerator key to A (which also can be used for other context menu hotkeys)
/* Script for the Browser Console
NOTE: BEFORE RUNNING THIS SCRIPT, CHECK THIS SETTING:
Type or paste about:config into the address bar and press Enter
Click the button promising to be careful
In the search box paste devtools.chrome.enabled
If the preference is false, double-click it to toggle to true
Paste this entire script into the command line at the bottom of the Browser Console (Windows: Ctrl+Shift+j)
Then press Enter to run the script.
*/
(function(){
// Define an array of key change objects (so far, only one)
var myKeyChanges = [
{
id: 'context-copylink',
newkey: 'a',
newlabel: 'Copy Link Location'
},
{
id: 'context-copyemail',
newkey: 'A',
newlabel: 'Copy Email Address'
}
];
// Current window
for (var i=0; i<myKeyChanges.length; i++){
var menuitem = gBrowser.ownerDocument.getElementById(myKeyChanges[i].id);
if (menuitem){
if (myKeyChanges[i].newkey.length == 1){
menuitem.setAttribute('accesskey', myKeyChanges[i].newkey);
}
if (myKeyChanges[i].newlabel.length > 0){
menuitem.setAttribute('label', myKeyChanges[i].newlabel);
}
}
}
// All future windows -- based largely on
// https://www.reddit.com/r/firefox/comments/kilmm2/restore_ctrlshiftb_library_by_setting_configjs/
var acceleratorUpdater = {
observe: function (aSubject) {
aSubject.addEventListener('DOMContentLoaded', this, {once: true});
},
handleEvent: function (aEvent) {
let document = aEvent.originalTarget;
let window = document.defaultView;
let location = window.location;
if (/^(chrome:(?!\/\/(global\/content\/commonDialog|browser\/content\/webext-panels)\.x?html)|about:(?!blank))/i.test(location.href)) {
if (window._gBrowser) {
for (var i=0; i<myKeyChanges.length; i++){
var menuitem = window.document.getElementById(myKeyChanges[i].id);
if (menuitem){
if (myKeyChanges[i].newkey.length == 1){
menuitem.setAttribute('accesskey', myKeyChanges[i].newkey);
}
if (myKeyChanges[i].newlabel.length > 0){
menuitem.setAttribute('label', myKeyChanges[i].newlabel);
}
}
}
}
}
}
}
Services.obs.addObserver(acceleratorUpdater, "chrome-document-global-created", false);
})();
@b3n10
Copy link

b3n10 commented Jul 25, 2021

Make sure you are using the Browser Console and not the in-tab Web Console

I've been using Firefox since I started learning how to code (back in college?) but I just learned today that the Browser Console (CTRL+SHIFT+J) is not the same as in-tab Web Console (CTRL+SHIFT+I).

The [program folder] referenced in the script is the directory where Firefox's program files are installed -- not profile specific.

Thanks for clarifying. So what I found out, in Linux this path is located in /usr/lib/firefox (added files in /usr/lib/firefox/defaults/pref)

EDIT:
was getting parse error and i realized the config.js was on the wrong folder. Fixed by following steps above:

  • config-prefs.js is located in /usr/lib/firefox/defaults/pref/
  • config.js is in /usr/lib/firefox/

Followed your steps and it's working correctly now for me

Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment