@@ -28,9 +28,12 @@ const showTwitchViewers = getURLParam("showTwitchViewers", true);
2828const twitchStreamer = { } ;
2929
3030const twitchAvatars = new Map ( ) ;
31- const twitchPronouns = new Map ( ) ;
31+
3232const twitchGoals = new Map ( ) ;
3333
34+ let supportedPronouns = null ;
35+ const twitchPronouns = new Map ( ) ;
36+
3437const bitsGifAnimations = [
3538 { min : 1 , max : 99 , gifId : 1 } ,
3639 { min : 100 , max : 999 , gifId : 100 } ,
@@ -1805,7 +1808,7 @@ async function getTwitchMessageFromParts(parts) {
18051808}
18061809
18071810
1808- async function getTwitchUserPronouns ( username ) {
1811+ /* async function getTwitchUserPronouns(username) {
18091812 if (twitchPronouns.has(username)) {
18101813 console.debug(`Pronouns found for ${username}. Getting it from Map...`);
18111814 return twitchPronouns.get(username);
@@ -1828,20 +1831,78 @@ async function getTwitchUserPronouns(username) {
18281831 console.error(`Couldn't retrieve pronouns for ${username}:`, err);
18291832 return '';
18301833 }
1834+ }*/
1835+
1836+
1837+
1838+ async function getTwitchUserPronouns ( username ) {
1839+
1840+ if ( ! supportedPronouns ) {
1841+ try {
1842+ console . debug ( '[ChatRD] Trying to fetch supported pronouns...' ) ;
1843+ const res = await fetch ( 'https://pronouns.alejo.io/api/pronouns' ) ;
1844+ supportedPronouns = await res . json ( ) ;
1845+ }
1846+ catch ( err ) {
1847+ console . error ( '[ChatRD] Could not fetch supported pronouns:' , err ) ;
1848+ return '' ;
1849+ }
1850+ }
1851+
1852+ if ( twitchPronouns . has ( username ) ) {
1853+ console . debug ( `[ChatRD] Pronouns found for ${ username } . Getting it from Map...` ) ;
1854+ return twitchPronouns . get ( username ) ;
1855+ }
1856+
1857+ console . debug ( `[ChatRD] Pronouns not found for ${ username } in the Map! Retrieving...` ) ;
1858+
1859+ try {
1860+ const res = await fetch ( `https://api.pronouns.alejo.io/v1/users/${ username } ` ) ;
1861+ const data = await res . json ( ) ;
1862+
1863+ if ( data === 'not_found' ) {
1864+ console . debug ( `[ChatRD] No pronouns found for ${ username } . Setting it to empty...` ) ;
1865+ twitchPronouns . set ( username , '' ) ;
1866+ return '' ;
1867+ }
1868+
1869+ console . debug ( `[ChatRD] Got pronouns for ${ username } :` , data ) ;
1870+
1871+ const pronounId = data ?. pronoun_id ?? null ;
1872+ const altPronounId = data ?. alt_pronoun_id ?? null ;
1873+
1874+ const mainMatch = pronounId ? supportedPronouns . find ( p => p . name === pronounId ) : null ;
1875+
1876+ let pronoun = mainMatch ? mainMatch . display : '' ;
1877+
1878+ if ( altPronounId !== null ) {
1879+ const altDisplay = altPronounId === 'any' ? 'Any' : supportedPronouns . find ( p => p . name === altPronounId ) ?. display ?? null ;
1880+ if ( altDisplay ) pronoun += `/${ altDisplay } ` ;
1881+ }
1882+
1883+ const formatted = pronoun ? `<em>${ pronoun } </em>` : '' ;
1884+
1885+ twitchPronouns . set ( username , formatted ) ;
1886+ return formatted ;
1887+ }
1888+ catch ( err ) {
1889+ console . error ( `[ChatRD] Couldn't retrieve pronouns for ${ username } :` , err ) ;
1890+ return '' ;
1891+ }
18311892}
18321893
18331894function twitchConfettiBurst ( el ) {
1834- const rect = el . getBoundingClientRect ( ) ;
1835-
1836- myConfetti ( {
1837- particleCount : 100 ,
1838- spread : 135 ,
1839- startVelocity : 20 ,
1840- gravity : 1.5 ,
1841- ticks : 80 ,
1842- origin : {
1843- x : ( rect . left + rect . width / 2 ) / window . innerWidth ,
1844- y : ( rect . top + rect . height / 2 ) / window . innerHeight ,
1845- } ,
1846- } ) ;
1895+ const rect = el . getBoundingClientRect ( ) ;
1896+
1897+ myConfetti ( {
1898+ particleCount : 100 ,
1899+ spread : 135 ,
1900+ startVelocity : 20 ,
1901+ gravity : 1.5 ,
1902+ ticks : 80 ,
1903+ origin : {
1904+ x : ( rect . left + rect . width / 2 ) / window . innerWidth ,
1905+ y : ( rect . top + rect . height / 2 ) / window . innerHeight ,
1906+ } ,
1907+ } ) ;
18471908}
0 commit comments