Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New hotkey for swapping between the sample and original image needs to be overridden #34

Closed
ghost opened this issue Jun 10, 2014 · 3 comments

Comments

@ghost
Copy link

ghost commented Jun 10, 2014

The hotkey is bound to "v" at the document level and it doesn't have a namespace. The only simple method of removing it with jQuery appears to be one that ends up unbinding all the jQuery keypress/hotkey events. If there's a better method that doesn't involve "hacky" tactics, I'm all ears. If not, I've found one method that requires me editing jQuery's internal data so I can give the keypress event responsible for the hotkey a namespace for specifically targeting it with unbind.

function removeDanbHotkey(key) {
    try {
        var jkd = $._data(document, "events").keydown;

        for (var i = jkd.length - 1; i >= 0; i--) {
            if (jkd[i].data.keys === key) {
                jkd[i].namespace = "diekey";
                $(document).unbind("keydown.diekey");
            }
        }
    }
    catch (error) {
        console.log("Hotkey removal error: " + error.message);
    }
}
@ghost
Copy link
Author

ghost commented Jun 10, 2014

Hm... Never mind. I was doing this testing through the console, but if we assume the script keeps running before Danbooru's JavaScript does, I actually can add a keypress event listener at the same level (document) for "v" before Danbooru does and use stopPropagation, as I have been, to keep the keypress from reaching Danbooru's event listener.

@ghost ghost closed this as completed Jun 10, 2014
@ghost
Copy link
Author

ghost commented Jun 10, 2014

Then again, a method I could use within parsePost which happens to run after Danbooru's JavaScript would be optimal so the "hacky" method does have a plus side to it. Still open to suggestions. <_<

@ghost ghost reopened this Jun 10, 2014
@ghost
Copy link
Author

ghost commented Jan 8, 2015

Finally ended up having to use this method.

@ghost ghost closed this as completed Jan 8, 2015
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants