Question: How to write code for an auto clicker that clicks on a particular link in a webpage in Chrome

Question

How to write code for an auto clicker that clicks on a particular link in a webpage in Chrome

Answers 2
Added at 2017-01-03 22:01
Tags
Question

So, I have very little coding background and hence have absolutely no idea how to even approach this.

I'm trying to browse Fortune Tech to read news from most of 2016 and there's a link when you scroll to the end which you need to click in order to view more headlines. It says " See more Tech Headlines". I wanted to somehow automate this process, like I'd scroll down and it'll automatically load the next set of headlines without me having to click there. How do I do this?

Answers to

How to write code for an auto clicker that clicks on a particular link in a webpage in Chrome

nr: #1 dodano: 2017-01-03 22:01

Using JQuery:

$('#section-see-more').click();
$('html, body').animate({ 
   scrollTop: $(document).height()-$(window).height()}, 
   1400, 
   "easeOutQuint"
);

The website you mentioned does not currently have jQuery on it, so you would have to load it into the page manually.

This is a tedious process unless you make a browser extension for this website and use the code to click the link that loads more information onto the screen.

nr: #2 dodano: 2017-01-03 22:01

I can help get you started. You will want to download the extension Tampermonkey so you can inject code into a webpage automatically. This is the code you want to have in a custom script.

// ==UserScript==
// @name      Fortune Tech Auto Click
// @author    Some Random Guy On The Internet
// @include   http://fortune.com/tech/
// @include   http://someothersite.com/*
// @require   https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js
// ==/UserScript==

(function() {
    'use strict';

    $(window).scroll(function() {
       if($(window).scrollTop() + $(window).height() == $(document).height()) {
          if (document.location.href.search('fortune.com/tech') !== -1) {  // This will run only on the fortune tech site
              $("#section-see-more").trigger("click"); 
          }else if (document.location.href.search('someothersite.com/*') !== -1) { // this will run on the someother.com/* site
              // Selector of the button.
              $("#other-button-id").trigger("click");
          }
       }
    });

})();

You will probably need to play around with it a little to get it working.

Edited to fit below comment better.

Source Show
◀ Wstecz