-1

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>
Yimin
  • 1
  • 2
  • Did you look already some manuals how it should be done? Why manual instructions did not work? – Heikki Nov 22 '17 at 22:02
  • Possible duplicate of [Choosing and activating the right controls on an AJAX-driven site](https://stackoverflow.com/questions/15048223/choosing-and-activating-the-right-controls-on-an-ajax-driven-site) – Brock Adams Nov 29 '17 at 06:07

1 Answers1

0

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>
Shawn J. Molloy
  • 2,457
  • 5
  • 41
  • 59