0

I'm trying to build a script that will click 3 buttons in succession but after clicking the first button, the script goes into infinite reloading.

The site I'm trying to click buttons on: JDoodle
You need to sign-in to see the buttons. As you can see in the screenshots:

Button 1

Button 2

// ==UserScript==
// @name         New Userscript
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        *.jdoodle.com/*
// @grant       none
// ==/UserScript==

'use strict';

  $ = jQuery;
  $(document).ready(function foo(){

    var node = document.querySelectorAll('a');
    node[8].click(); //clicking button 1

    node = document.querySelector('[title="User\'s Saved Files"]');
    node.click();    //clicking button 2
 }
);

Tried approaches:

1.

 unsafeWindow.r=0

 if(unsafeWindow.r==0){
    foo = function(){};
    unsafeWindow.r=1;
}

Result : unsafeWindow.r not defined

2.

f = 1;
while(f){
   if(document.querySelector('[title="User\'s Saved Files"]'))
     f=0;
}

Result: Infinite reloading.

  1. Simply executing without approaches 1 & 2, no button is being clicked on by the script.
4
  • Your script runs on load of the page and then clicks the button which causes the page to redirect. Then onload of the page your script runs and clicks the button which causes the page to redirect. Then onload of the page... Commented Aug 31, 2018 at 13:01
  • In other words, maybe it's a good idea check the URL you're on first, then click the button. It depends on the reason why you feel the need to raise the click event on that <a> element in the first place Commented Aug 31, 2018 at 13:02
  • @RoryMcCrossan The click event on the button doesn't redirects to a new webpage but changes the content of the page with javascript so the URL remains same. The <a> element is a link to the same page, even if I handle that without click event, I will still have 2 other elements to click on one after another. Commented Aug 31, 2018 at 14:38
  • You're not including jQuery in the script header... And if you'll use jQuery, why not go all the way and use it to locate the selectors? Also node[8] seems pretty arbitrary, it could change at any moment. Commented Sep 7, 2018 at 14:59

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.