const twitterData = Social.get("*/profile/linktree/twitter", "final"); if (!twitterData) { return ""; } function extractTwitterUsernames(data) { const usernames = []; for (const [key, value] of Object.entries(data)) { if ( value.profile && value.profile.linktree && value.profile.linktree.twitter ) { let username = value.profile.linktree.twitter; // Remove "https://twitter.com/", "https://www.twitter.com/", "https://mobile.twitter.com/", and "https://x.com/" regardless of capitalization username = username.replace(/https:\/\/(www\.)?twitter\.com\//i, ""); username = username.replace(/https:\/\/mobile\.twitter\.com\//i, ""); username = username.replace(/https:\/\/x\.com\//i, ""); // Remove "@" at the beginning if (username.startsWith("@")) { username = username.substring(1); } // Remove anything after "?t=" or "?s=" const patternsToRemove = ["?t=", "?s="]; patternsToRemove.forEach((pattern) => { const index = username.indexOf(pattern); if (index !== -1) { username = username.substring(0, index); } }); usernames.push(username); } } return usernames; } const twitterUsernames = extractTwitterUsernames(twitterData); return ( <div> <p>{JSON.stringify(twitterUsernames)}</p> </div> );