简体   繁体   English

防止函数执行或删除匿名事件侦听器

[英]Prevent function from executing or removing anonymous event listeners

I'm creating a Chrome extension for a website that has no open API, so I'm stuck reading Closure Compiled spaghetti code for a long time.我正在为一个没有开放 API 的网站创建 Chrome 扩展程序,所以我很长时间都在阅读Closure Compiled spaghetti 代码。 I've made a lot of progress but I seem to be stuck.我已经取得了很大的进步,但我似乎被卡住了。 On the page's onload, this function executes:在页面的 onload 上,这个函数执行:

function comments_initReply(){
    var b=$("#ajax_comm div.com");
    for(var a=0;a<b.length;a++){var d=$(b[a]);
    var c=d.find(".commentReplyLink");
    if(c.length){
        d.on("dblclick",function(){$(this).closest("div.com").find(".commentReplyLink").click()}).find(".t")}
    }
} 

What it does is it takes a comment div on a website and it makes it into a large double-clickable area for you to open a reply.它的作用是将网站上的评论 div 变成一个大的可双击区域,供您打开回复。 All I want to do is remove the double-clicking property so you can double-click text and highlight it instead of opening a reply modal dialog.我想要做的就是删除双击属性,以便您可以双击文本并突出显示它,而不是打开回复模式对话框。

Since the function is anonymous, it cannot using removeEventListener to detach it.由于该函数是匿名的,所以它不能使用removeEventListener来分离它。 Any ideas?有任何想法吗? I prefer to not use jQuery.我更喜欢不使用 jQuery。

Well, although you prefer not to use jQuery, it's much easier to use it, and my solution here will be jQuery-based, and feel free to convert it into a normal Javascript, if you want to.好吧,虽然您不喜欢使用 jQuery,但使用它要容易得多,而且我在这里的解决方案将基于 jQuery,如果您愿意,可以随意将其转换为普通的 Javascript。

function comments_endReply() {
    $("#ajax_comm div.com").off("dblclick");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM