function(props) { // Avatar & Initials Generator - Programmatic Plugin const { publishState } = props.instance; // Helper function to generate random 5-character string const generateRandomString = () => { const chars = 'abcdefghijklmnopqrstuvwxyz'; let result = ''; for (let i = 0; i < 5; i++) { result += chars.charAt(Math.floor(Math.random() * chars.length)); } return result; }; // Random avatar function props.instance.data.random = function() { try { const randomStr = generateRandomString(); const gender = Math.random() < 0.5 ? 'boy' : 'girl'; const url = `https://avatar.iran.liara.run/public/${gender}?username=${randomStr}`; publishState("placeholder", url); return url; } catch (error) { // Silent error handling return null; } }; // Male avatar function props.instance.data.male = function() { try { const randomStr = generateRandomString(); const url = `https://avatar.iran.liara.run/public/boy?username=${randomStr}`; publishState("placeholder", url); return url; } catch (error) { // Silent error handling return null; } }; // Female avatar function props.instance.data.female = function() { try { const randomStr = generateRandomString(); const url = `https://avatar.iran.liara.run/public/girl?username=${randomStr}`; publishState("placeholder", url); return url; } catch (error) { // Silent error handling return null; } }; // Initials avatar function props.instance.data.init = function(first, last) { try { let username = ''; if (first) { username = first; // Add "+" after first name regardless of whether last name exists if (last) { username += `+${last}`; } else { username += '+'; } } const url = `https://avatar.iran.liara.run/username?username=${username}`; publishState("placeholder", url); return url; } catch (error) { // Silent error handling return null; } }; // No UI needed for programmatic plugin return null; }