覆盖google.com匿名函数的一部分 [英] Overriding a portion of a google.com anonymous function

查看:129
本文介绍了覆盖google.com匿名函数的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果javascript函数是匿名声明的,有什么方法可以覆盖它或它的一部分吗?



我试图阻止google.com的即时搜索劫持向上和向下箭头键移动您的搜索排名。我已经确定了我认为是代码有问题的部分。键盘38和40用于上下键。

  if(b == 40)aa(f); 
else if(b == 38)aa(j);
else if(b == 37 || b == 39)if(!ca(b == 39))return f;
a.preventDefault&& a.preventDefault();
return a.returnValue = j

问题在于这是被调用函数的一部分Sb =函数(a){}位于大约三千行匿名函数中。在SO上发布了类似的问题在这里,作者最终以一种不适用于我的黑客方式工作。我意识到我可以关闭即时搜索功能,但我喜欢它,但我无法忍受我的箭头键不再有效。



解决方案:

>

我最终编写了 Chrome扩展程序将上/下箭头键功能恢复为滚动。我使用了下面的代码。感谢您的Raze和Mofle。

  if(event.keyCode == 40 || event.keyCode == 38){
event.cancelBubble = true;
event.stopPropagation();
返回false;


解决方案

匿名函数里面的另一个匿名函数。您不能更改任何现有函数的部分,您必须创建一个新函数并将其附加到需要的位置,尽管您可以获取函数的来源,操作它并从源创建一个新函数。 p>

这里有两个关于这个问题的建议,其中不涉及重新定义函数。

  • 在捕捉阶段为输入文本框添加事件侦听器,并在keyCode为UP或DOWN时取消事件 创建实际输入文本的覆盖文本框,将所有事件除UP键和DOWN键外的所有事件传递给下面的实际文本框。


  • If a javascript function is declared anonymously is there any way to override it or portions of it?

    I am attempting to stop google.com's instant search from hijacking the up and down arrow keys to move through your search rankings. I have identified what I believe is the problematic section of code. Keycodes 38 and 40 are for the down and up keys.

    if (b == 40) aa(f);
    else if (b == 38) aa(j);
    else if (b == 37 || b == 39) if (!ca(b == 39)) return f;
    a.preventDefault && a.preventDefault();
    return a.returnValue = j
    

    The problem is that this is part of a function called Sb = function (a) {} that lies inside of about a three thousand line anonymous function. There is a similar question posted on SO here that the author ended up working out in a hacky way that doesn't apply to me. I realize I can turn off instant search, but I like it, I just can't stand that my arrow keys don't work anymore.

    SOLUTION:

    I ended up writing a chrome extension to revert up/down arrow key functionality to scrolling. I used the following code. Thank you to Raze and Mofle.

    if (event.keyCode == 40 || event.keyCode == 38)  {
        event.cancelBubble = true;
        event.stopPropagation();            
        return false;
    }
    

    解决方案

    You can't override an anonymous function inside another anonymous function. You can't change portions of any existing function, you'll have to create a new function and attach it where required, though you could get the source of a function, manipulate it and create a new function out of the source.

    I have two suggestions for this problem here, which doesn't involve redefining the functions.

    1. Add an event listener for the input text box at the capture phase, and cancel the event if keyCode is UP or DOWN
    2. Create an overlayed text box where you actually enter text, and pass on all events except UP key and DOWN key to the actual text box underneath.

    这篇关于覆盖google.com匿名函数的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆