简体   繁体   中英

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. I've made a lot of progress but I seem to be stuck. On the page's onload, this function executes:

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. 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. Any ideas? I prefer to not use 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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