JSFiddle - React, Tailwind, and code Playground

by Sahil Batla

JavaScript

var DELTA_TIME = 10;

function tryEval(js) {
	try {
		eval(js);
	} catch (e) {}
}

function executeSynchronously(operations, currentOperationId, forceRun) {
	//this can be a global constant
	currentOperationId = typeof currentOperationId === 'number' ? currentOperationId : 0;
	var operation = operations[currentOperationId];
	if (operation) {
		if (operation.xpath !== 'HEAD') {
			//if element is found execute code and move forward or else try replaying the action
			if (vwo_$(operation.xpath).length || window.domReady) {
				window.x = operation.xpath;
				tryEval(operation.js);
				currentOperationId++;
			}
		} else {
			//Xpath is head means either script/style or link are used
			try {
				if (['script', 'style', 'link'].indexOf(vwo_$(operation.js).get(0).tagName) !== -1) {
					vwo_$('head').append(operation.js);
				} else {
					tryEval(operation.js);
				}
			} catch (e) {
				//the code raised an exception and therefore not a script/style/link tag
				tryEval(operation.js);
			}
			currentOperationId++;
		}

		window.setTimeout(function () {
			//execute next operation
			executeSynchronously(operations, currentOperationId, forceRun);
		}, DELTA_TIME);
	}
}

vwo_$(document).ready(function () {
	window.domReady = true;
	DELTA_TIME = 0;
});