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

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?
Cyrus CookAsked:
Who is Participating?
 
leakim971PluritechnicianCommented:
	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

0
 
leakim971PluritechnicianCommented:
What is "instances" ? a link ? a div ? any HTML element ?
0
 
Cyrus CookCommented:
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
0
 
leakim971PluritechnicianCommented:
what should happen for <div> Follow and Following</div> ?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.