Click on every instance of the word "Follow" with JQuery

Cyrus Cook
Cyrus Cook used Ask the Experts™
on
I'm trying to get the bot to continuously scan the page for any instances for the word "Follow" (But also checking that it is not "Following") and then click on all of these instances but with a set delay between each click. Is there any way to do this?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
leakim971Multitechnician
Top Expert 2014

Commented:
What is "instances" ? a link ? a div ? any HTML element ?
C C

Commented:
Instances as in every time the text appears, it could be in a div, could be a link or could be in an element, all it means is every time it appears on the page
leakim971Multitechnician
Top Expert 2014

Commented:
what should happen for <div> Follow and Following</div> ?
Multitechnician
Top Expert 2014
Commented:
	jQuery(function($) {
		var checkForFollow = function() {
			var t = 0;
// https://api.jquery.com/all-selector/
// https://api.jquery.com/not-selector/
// https://api.jquery.com/has-selector/
// http://api.jquery.com/filter/
			$("body *:not(:has(*)):not('script,link'):contains('Follow')").filter(function() {
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test
				return /Follow[^i]*/.test($(this).text());
// https://api.jquery.com/each/
			}).each(function(i,v) {
				var that = this;
// https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout
				setTimeout(function() {
					$(that).click();
					//window.location.href = $(that).attr("href");
				}, t * 1000); // click on every link found every 10s
				t++;
			});
		};
		checkForFollow();
// https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setInterval
		setInterval(checkForFollow, 10 * 60 * 1000); // check the page every 10 min for the word "Follow"
	});

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial