2

I wanted to create a simple auto-skip with Greasemonkey, but I found that no solution found on Stack Overflow actually works for me.

I need to click this button:

<div tip="next" title="Next" class="linkable fa fa-arrow-right" ng-click="View.next()"></div>

It doesn't have any id nor name and is hidden deep inside many divs. I could bypass the click wiht simulating enter or right arrow press, but that also didn't work for me.

Brock Adams
  • 90,639
  • 22
  • 233
  • 295
Marek Lukáš
  • 47
  • 1
  • 7
  • why does this button does not have any id or name? – SaschaP Oct 09 '15 at 16:32
  • when you click the button an event is triggered and a function is called ? just call directly the function don't spend your time. – Anonymous0day Oct 09 '15 at 16:32
  • @SaschaP Don't know. It's not my site that's why I wanted to create a script with GreaseMoneky :-) – Marek Lukáš Oct 09 '15 at 16:34
  • @SaschaP It's not his code, and elements don't need to have an id, class or name. at: Anon The function might be scoped, so greasemonkey might not be able to run that function. – Dave Chen Oct 09 '15 at 16:34
  • @Anonymous0day Actually I don't know. I tried to call Vie.next(), but it did nothing – Marek Lukáš Oct 09 '15 at 16:35
  • What you can try is to find the parent element and then select the first child -> the div. Can you post more of the HTML? – Dave Chen Oct 09 '15 at 16:35
  • ah, I see... are there any other elements with the classes `linkable`, `fa` or `fa-arrow-right`? You could probably use `document.getElementsByClassName(...)[index_of_button]` – SaschaP Oct 09 '15 at 16:36
  • maybe something like that : `document.querySelector('div.linkable.fa.fa-arrow-right[ng-click="View.next()"]'` – Anonymous0day Oct 09 '15 at 16:41
  • @DaveChen the site is [BetterFap](http://betterfap.com/view/6517932). It's easier if you look at yourself. – Marek Lukáš Oct 09 '15 at 16:41
  • 1
    Where is button? I am only seeing block level element! – brk Oct 09 '15 at 16:51

1 Answers1

2

Try this:

document.querySelector('div[tip="next"]').click()

From what I saw these GreaseMonkey scripts run on page load. Using this I was able to simulate the click.

// ==UserScript==
// @name        test
// @namespace   blargtest
// @include     https://addons.mozilla.org/en-US/firefox/addon/greasemonkey/
// @version     1
// @grant       none
// ==/UserScript==
setTimeout(
    function () {
        document.querySelector('div[tip="next"]').click();
    }, 1000
);

You could make that a setInterval and have it click next every second.

AtheistP3ace
  • 9,611
  • 12
  • 43
  • 43