How do I automatically click this button with tampermonkey?

心已入冬 提交于 2019-12-14 03:33:02

问题


I am wondering how I can make a script that automatically clicks a button with tampermonkey.

Here is the button:

<button class="confirm" tabindex="1" style="display: inline-block; background-color: rgb(91, 155, 209); box-shadow: rgba(91, 155, 209, 0.8) 0px 0px 2px, rgba(0, 0, 0, 0.05) 0px 0px 0px 1px inset;">Next Video</button>

回答1:


You can do the following:

$(document).ready(function() {
  $("button:contains('Next Video')").click();
});

Hope that helps!

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<script>
$(document).ready(function() {
  $("#result").hide();
  $("#btnNextVideo").trigger('click');

$("#btnNextVideo").click(function() {
   $("#result").show();
});
});
</script>


<button id="btnNextVideo" class="confirm" tabindex="1" style="display: inline-block; background-color: rgb(91, 155, 209); box-shadow: rgba(91, 155, 209, 0.8) 0px 0px 2px, rgba(0, 0, 0, 0.05) 0px 0px 0px 1px inset;">Next Video</button>

<div id="result">
It worked!
</div>


<script>
$(document).ready(function() {
  $("#result").hide();
  $("#btnNextVideo").trigger('click');

$("#btnNextVideo").click(function() {
   $("#result").show();
});
});
</script>


来源:https://stackoverflow.com/questions/47444367/how-do-i-automatically-click-this-button-with-tampermonkey

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