node-horseman icon indicating copy to clipboard operation
node-horseman copied to clipboard

feat: Add function to randmoly click on any link

Open bhaskarmelkani opened this issue 8 years ago • 1 comments

Proposal for issue #300 .

Add a function to click on a random anchor link.

bhaskarmelkani avatar Jul 14 '17 16:07 bhaskarmelkani

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

awlayton avatar Sep 05 '17 16:09 awlayton