jfsaliba / Act-On - Check Automation Program Email Steps

// ==UserScript==
// @name         Act-On - Check Automation Program Email Steps
// @namespace    https://openuserjs.org/users/jfsaliba
// @version      1.2
// @description  Adds a button to run a check of your automation program steps to ensure that any "email" step is always immediately followed by a "wait" step. Reports success or errors (and their location).
// @author       James Saliba
// @homepageURL  https://github.com/jfsaliba
// @license      Attribution-ShareAlike 4.0 International (CC BY-SA 4.0); http://creativecommons.org/licenses/by-sa/4.0/
// @match        http://*.actonsoftware.com/acton/ng-ui/
// @grant        none
// ==/UserScript==

var checkEmailWaitSteps = function() {
	
	var badcounter = 0;
	var errorlist = 'Problem(s) detected at the following steps: \n\n';
	
	if($('.stepicon.fa-envelope:not(:hidden)').length > 0) {
		//for each
		$('.stepicon.fa-envelope:not(:hidden)').each(function(){
			if($(this).parents('tr').next().find('.fa-clock-o').length <= 0) {
				badcounter++;
				errorlist += '> Step ' + $(this).parents('tr').children('td').first().text() + '\n';
			}
		});


		if(badcounter > 0) {
			//bad! give error message with report
			alert('ERROR.\n\n'+errorlist);
		} else {
			//yay, no problems
			alert('SUCCESS. No problems with email steps detected.');
		}
	} else {
		alert('No email steps detected.');
	}
}

var GOcheck = function(){

        ///////////SCRIPT STARTS HERE//////////////////////
		
		if($('#checkbtn').length <= 0) {
			$('.nav-pills').before('<a href="#" id="checkbtn" style="float: right;" class="btn btn-success btn-md">Check for Email Step Problems</a>');
			
			$('body').on('click','#checkbtn',function(){
				checkEmailWaitSteps();
			});
		}
		
        ///////////SCRIPT ENDS HERE//////////////////////
}

var start_check = function() {

	if($('data-ng-include[src*="feature/program/include/tabSteps.html"] > div').is(':visible')) {
		GOcheck();
	} else {
		$('body').off('click','#checkbtn');
		if($('#checkbtn').length > 0) {
			$('#checkbtn').remove();
		}
	}

    setTimeout(function(){
        start_check();
    },1000);
}

start_check();