创建一个书签,单击一页上的多个按钮 [英] Create a Bookmarklet that clicks multiple buttons on one page

查看:75
本文介绍了创建一个书签,单击一页上的多个按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为网站创建了一个书签,该书签在页面上的多个复选框上打勾:

I created a bookmarklet for a site a while back that ticks multiple checkboxes on a page:

javascript:javascript:;$("input[name='unfollow[]']").attr({checked:true});

javascript:javascript:;$("input[name='unfollow[]']").attr({checked:true});

不幸的是,UI发生了变化,需要单击一些按钮而不是复选框.这是其中一个按钮的HTML的示例:

Unfortunately the UI has changed and instead of checkboxes there are buttons that need to be clicked. Here is an example of the HTML of one of the buttons:

<button class="process mode-basic Unfollow" data-verb="unfollow">Unfollow</button>

<button class="process mode-basic Unfollow" data-verb="unfollow">Unfollow</button>

这些按钮最多可以有100个.如何创建单击所有这些按钮的书签?是否可以在每次点击之间建立延迟?

There can be up to 100 of these buttons. How do I create a bookmarklet that clicks all of these buttons? Is it possible to build up a delay between each click?

谢谢.

推荐答案

假设页面已加载jQuery,您可以单击每个jQuery,并且之间存在延迟:

Assuming the page has jQuery loaded, you can click each one with a delay in between:

(function(){
    var unfollowButtons = $('button.Unfollow');
    var index = unfollowButtons.length-1;
    unfollow();

    function unfollow(){
        if(index >= 0){
            $(unfollowButtons[index--]).click();
            setTimeout(unfollow, 500);
        }
    }
})();

这篇关于创建一个书签,单击一页上的多个按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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