HEX
Server: Apache/2.4.68 (Debian)
System: Linux as-cs-widget-demo-us-central1 6.1.0-44-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.164-1 (2026-03-09) x86_64
User: root (0)
PHP: 8.2.32
Disabled: NONE
Upload Files
File: /var/www/html/wp-content/plugins/wp-recipe-maker/assets/js/public/cookpal.js
window.WPRecipeMaker = typeof window.WPRecipeMaker === "undefined" ? {} : window.WPRecipeMaker;

window.WPRecipeMaker.cookPal = {
	init: () => {
		if ( ! WPRecipeMaker.cookPal.hasShortcode() ) {
			return;
		}

		WPRecipeMaker.cookPal.checkAndShow();

		let checkInterval = setInterval( () => {
			if ( WPRecipeMaker.cookPal.hasButton() ) {
				WPRecipeMaker.cookPal.checkAndShow();
				clearInterval( checkInterval );
			}
		}, 100 );

		setTimeout( () => {
			clearInterval( checkInterval );
		}, 10000 );

		document.addEventListener( 'click', function( e ) {
			for ( let target = e.target; target && target !== this; target = target.parentNode ) {
				if ( target.matches( '.wprm-recipe-cookpal' ) ) {
					WPRecipeMaker.cookPal.onClick( e );
					break;
				}
			}
		}, false );
	},
	hasButton: () => {
		return !! document.getElementById( 'cookpal-chat-button' );
	},
	hasShortcode: () => {
		return !! document.querySelector( '.wprm-recipe-cookpal' );
	},
	checkAndShow: () => {
		if ( WPRecipeMaker.cookPal.hasButton() ) {
			const elements = document.querySelectorAll( '.wprm-recipe-cookpal' );
			elements.forEach( ( el ) => {
				if ( el.style.visibility === 'hidden' ) {
					el.style.visibility = 'visible';
				}
			} );
		}
	},
	onClick: ( event ) => {
		event.preventDefault();

		const button = document.getElementById( 'cookpal-chat-button' );

		if ( button ) {
			button.click();
		} else {
			console.warn( 'WPRM CookPal: widget is not available yet.' );
		}
	},
};

ready( () => {
	window.WPRecipeMaker.cookPal.init();
} );

function ready( fn ) {
	if ( document.readyState != 'loading' ) {
		fn();
	} else {
		document.addEventListener( 'DOMContentLoaded', fn );
	}
}