Skip to content

feat: Add function to randmoly click on any link#301

Open
bhaskarmelkani wants to merge 1 commit intojohntitus:masterfrom
bhaskarmelkani:rand-click
Open

feat: Add function to randmoly click on any link#301
bhaskarmelkani wants to merge 1 commit intojohntitus:masterfrom
bhaskarmelkani:rand-click

Conversation

@bhaskarmelkani
Copy link
Copy Markdown

Proposal for issue #300 .

Add a function to click on a random anchor link.

@awlayton
Copy link
Copy Markdown
Collaborator

awlayton commented Sep 5, 2017

I am open to others' thoughts, but I feel this feature is unnecessary. Also, I feel the specific types of links you are filtering out would vary from use to use.

I doubt it would be used often, and it can somewhat easily be done with existing functionality:

var HORSEMAN_CLICK_ATRR = 'HORSEMAN_SELECTED_RANDOM_LINK';

horseman
  .evaluate(function pickALink(attr) {
    // Find all the links
    var links = document.getElementsByTagName('a');

    // Select specific kinds of links
    var goodLinks = Array.prototype.filter.call(links, function checkLink(l) {
      // Check whatever link stuff you like
      return foo(l);
    });

    // Pick a random link
    var link  = goodLinks[Math.floor(Math.random()*goodLinks.length)];

    // Mark the link
    link.setAttribute(attr, '');
  }, HORSEMAN_CLICK_ATTR)
  .click('[' + HORSEMAN_CLICK_ATTR + ']') // Click the marked link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants