Greasemonkey Jquery Script to Click Links

房东的猫 提交于 2019-11-28 11:45:45

See: wiki.greasespot.net/Generate_Click_Events .

That Reddit link fires JavaScript and not JS that was set with jQuery.

Which means that in this case, you need to send an actual mouse event, like so:

setInterval ( function () {

    var clickEvent  = document.createEvent ("HTMLEvents");
    clickEvent.initEvent ("click", true, true);

    $("a:contains('load more comments')")[0].dispatchEvent (clickEvent);
}, 10000);

Oops! I did not see that the question mentioned clicking "all of the 'load more comments'". (And that page has hundreds of them!)

To do that, use jQuery's each() function...

setInterval ( function () {

    var moreLinks       = $("a:contains('load more comments')");

    moreLinks.each ( function () {

        var clickEvent  = document.createEvent ("HTMLEvents");
        clickEvent.initEvent ("click", true, true);
        this.dispatchEvent (clickEvent);
    } );
}, 10000);

You are trying to simulate click event but this only works on events attached with jQuery. Events on load more comments links at reddit attached using html attributes. I.e:

onclick="return morechildren(this, 't3_i7hb5', 'c21ko21,c21kesz,c21klil,c21ko45,c21kro5,c21l90v,c21lo38', 3, '')"

to solve your problem you need to extract values from this attributes and call them separately.

If you have jQuery loaded on the page you could just trigger the click event using jQuery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!