Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override Ctrl+M hotkey of Facebook in Firefox

I'm working on a bookmarklet which will let users to write on any input fields in our language. We choose Ctrl+M for switching layout between default and our language (Inspired by Wikipedia). It was working fine in almost every website with chrome. When we started checking with Firefox we found that it only fails in Facebook.

Moreover, Facebook catches the Ctrl+M from outside the window scope. Like, form the address bar, search bar, firebug console, etc.

I've tried with raw javascript, jQuery and also with the jQuery Hotkeys plugin by John Resig but no luck :(

Here is a version that I had tried. You can run it on your Firebug console for testing purpose -

(function(){
    var noConflictMode = false;
    if(typeof $ !== 'undefined') noConflictMode = true;
    if(typeof jQuery === 'undefined') {
        var root = (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]);
        var ns = document.createElementNS && document.documentElement.namespaceURI;
        var script = ns ? document.createElementNS(ns, 'script') : document.createElement('script');
        script.type = 'text/javascript';
        script.onreadystatechange = function () {
            if (this.readyState == 'complete') test();
        }
        script.onload= test;
        script.src= 'https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.min.js';
        root.appendChild(script);
    } else {
        test();
    }

    function test() {
        if(noConflictMode) jQuery.noConflict();
        jQuery(window).on('keydown keyup keypress', function(e){
            e.preventDefault();
            // For Firefox
            e.stopPropagation();
            // Extra effort :|
            e.stopImmediatePropagation()
            e.cancelBubble = true;
            console.log(e);
            return false;
        });
    }

})();
like image 476
Rifat Avatar asked Nov 22 '11 00:11

Rifat


1 Answers

You can NOT do that on client-side web for security reasons, you can code anything in JS or JQ or any language you want but MOZ never will take care of your code.

Take care, one thing is that the browser "compile" your code and work with it, and another thing is that you can change the browser itself. For that reasons there's the "add-on". For example, you can't change the kernel of Visual Studio programming in V.S. :D

BUT...

... you can ask to the user re-bind the keys, you have 3 ways to do that:

1) installing a MOZ add-on (or your own addon)

2) Working with: http://mxr.mozilla.org/seamonkey/source/dom/public/idl/events/nsIDOMKeyEvent.idl

3) installing a shortcut keyb at OS level with higher priority than the App (in this case, MOZ) (you can do it with C#). Alt+tab combination is an example of high level shortcut, or "Prnt Scrn"

There is NO way to do that with about:config, neither.

Maybe this url can help you, but i suggest you try asking for changes in MOZ and not asking for Javascript code.

http://www-archive.mozilla.org/unix/customizing.html#keys

like image 63
Leandro Bardelli Avatar answered Oct 11 '22 08:10

Leandro Bardelli