1- // Setup
1+ //Setup
22export default async function ( { login, q, imports, data, account} , { enabled = false , extras = false } = { } ) {
33 try {
4- // Check if the plugin is enabled and requirements are met
4+ //Check if the plugin is enabled and requirements are met
55 if ( ( ! q [ "16personalities" ] ) || ( ! imports . metadata . plugins [ "16personalities" ] . enabled ( enabled , { extras} ) ) )
66 return null
77
8- // Load inputs
8+ //Load inputs
99 let { url, sections, scores} = imports . metadata . plugins [ "16personalities" ] . inputs ( { data, account, q} )
1010 if ( ! url )
1111 throw { error : { message : "URL is not set" } }
1212
13- // Start puppeteer and navigate to page
13+ //Start puppeteer and navigate to page
1414 console . debug ( `metrics/compute/${ login } /plugins > 16personalities > starting browser` )
1515 const browser = await imports . puppeteer . launch ( )
1616 console . debug ( `metrics/compute/${ login } /plugins > 16personalities > started ${ await browser . version ( ) } ` )
1717 const page = await browser . newPage ( )
1818 console . debug ( `metrics/compute/${ login } /plugins > 16personalities > loading ${ url } ` )
1919
20- // Capture console messages from the browser context
21- page . on ( ' console' , msg => {
22- if ( msg . type ( ) === ' debug' ) {
23- console . debug ( `BROWSER: ${ msg . text ( ) } ` ) ;
20+ //Capture console messages from the browser context
21+ page . on ( ` console` , msg => {
22+ if ( msg . type ( ) === ` debug` ) {
23+ console . debug ( `BROWSER: ${ msg . text ( ) } ` )
2424 }
2525 } )
2626
27- await page . goto ( url , { waitUntil : ' networkidle2' } )
27+ await page . goto ( url , { waitUntil : ` networkidle2` } )
2828
29- // Fetch raw data
29+ //Fetch raw data
3030 const raw = await page . evaluate ( ( ) => {
31- const getInnerText = ( selector ) => document . querySelector ( selector ) ?. innerText || ""
31+ const getInnerText = selector => document . querySelector ( selector ) ?. innerText || ""
3232
33- // Default map personality category to RGB colors
33+ //Default map personality category to RGB colors
3434 const defaultPersonalityColors = {
35- explorers : ' rgb(228, 174, 58)' , // Virtuoso, Adventurer, Entrepreneur, Entertainer
36- sentinels : ' rgb(66, 152, 180)' , // Logistician, Defender, Executive, Consul
37- diplomats : ' rgb(51, 164, 116)' , // Advocate, Mediator, Protagonist, Campaigner
38- analysts : ' rgb(136, 97, 154)' , // Architect, Logician, Commander, Debater
39- default : ' rgb(0, 0, 0)'
35+ explorers : ` rgb(228, 174, 58)` , //Virtuoso, Adventurer, Entrepreneur, Entertainer
36+ sentinels : ` rgb(66, 152, 180)` , //Logistician, Defender, Executive, Consul
37+ diplomats : ` rgb(51, 164, 116)` , //Advocate, Mediator, Protagonist, Campaigner
38+ analysts : ` rgb(136, 97, 154)` , //Architect, Logician, Commander, Debater
39+ default : ` rgb(0, 0, 0)`
4040 }
4141 let defaultColor = defaultPersonalityColors . default
4242
43- // Choose the default color based on the personality type
44- const personalityType = getInnerText ( ".link--inline" ) ;
43+ //Choose the default color based on the personality type
44+ const personalityType = getInnerText ( ".link--inline" )
4545 if ( personalityType . includes ( "Virtuoso" ) || personalityType . includes ( "Adventurer" ) || personalityType . includes ( "Entrepreneur" ) || personalityType . includes ( "Entertainer" ) )
4646 defaultColor = defaultPersonalityColors . explorers
4747 else if ( personalityType . includes ( "Logistician" ) || personalityType . includes ( "Defender" ) || personalityType . includes ( "Executive" ) || personalityType . includes ( "Consul" ) )
4848 defaultColor = defaultPersonalityColors . sentinels
4949 else if ( personalityType . includes ( "Advocate" ) || personalityType . includes ( "Mediator" ) || personalityType . includes ( "Protagonist" ) || personalityType . includes ( "Campaigner" ) )
5050 defaultColor = defaultPersonalityColors . diplomats
5151 else if ( personalityType . includes ( "Architect" ) || personalityType . includes ( "Logician" ) || personalityType . includes ( "Commander" ) || personalityType . includes ( "Debater" ) )
52- defaultColor = defaultPersonalityColors . analysts ;
52+ defaultColor = defaultPersonalityColors . analysts
5353
5454 console . debug ( `Personality Type: ${ personalityType } ` )
5555
5656 return {
57- // Type extraction
57+ //Type extraction
5858 type : getInnerText ( ".type__code" ) ,
5959
60- // Personality details extraction
60+ //Personality details extraction
6161 personality : [ ...document . querySelectorAll ( ".slider__slides > div" ) ] . map ( card => {
62- // Extract image data
62+ //Extract image data
6363 let image = ""
6464 const cardElement = card . querySelector ( ".card__image" )
65- // Check if the card has an image as an url, e.g., the "His Role" image or the "His Strategy" image
65+ //Check if the card has an image as an url, e.g., the "His Role" image or the "His Strategy" image
6666 if ( cardElement . querySelector ( "img" ) ) {
6767 image = cardElement . querySelector ( "img" ) . src
6868 console . debug ( `Image for ${ card . querySelector ( ".card__title" ) ?. innerText } : ${ image } ` )
6969 }
70- // Check if the card has a image as a svg, e.g., the "His personality" image
70+ //Check if the card has a image as a svg, e.g., the "His personality" image
7171 else if ( cardElement . querySelector ( "svg" ) ) {
7272 image = new XMLSerializer ( ) . serializeToString ( cardElement . querySelector ( "svg" ) )
7373 image = `data:image/svg+xml,${ encodeURIComponent ( image ) } `
7474 console . debug ( `Image for ${ card . querySelector ( ".card__title" ) ?. innerText } is a svg` )
7575 }
7676
7777 return {
78- category : card . querySelector ( ".card__title" ) ?. innerText || "" , // Category, e.g., "His role"
79- value : card . querySelector ( ".card__subtitle" ) ?. innerText || "" , // Value of the category, e.g., "Sentinel"
80- image, // Image of the category
81- text : card . querySelector ( ".prevent--drag.card__p" ) ?. innerText || "" // Description of the category
78+ category : card . querySelector ( ".card__title" ) ?. innerText || "" , //Category, e.g., "His role"
79+ value : card . querySelector ( ".card__subtitle" ) ?. innerText || "" , //Value of the category, e.g., "Sentinel"
80+ image, //Image of the category
81+ text : card . querySelector ( ".prevent--drag.card__p" ) ?. innerText || "" //Description of the category
8282 }
8383 } ) ,
8484
85- // Traits details extraction
85+ //Traits details extraction
8686 traits : [ ...document . querySelectorAll ( ".traits__boxes > div" ) ] . map ( card => {
8787 const categoryText = card . querySelector ( ".traitbox__label" ) ?. innerText
88- const scoreText = card . querySelector ( ".traitbox__value" ) ?. innerText . trim ( ) // Get the text like "75% Extraverted"
88+ const scoreText = card . querySelector ( ".traitbox__value" ) ?. innerText . trim ( ) //Get the text like "75% Extraverted"
8989
90- console . debug ( `Parsing Trait category ${ categoryText } ${ scoreText } ` ) ;
90+ console . debug ( `Parsing Trait category ${ categoryText } ${ scoreText } ` )
9191
92- // Split the score text into percentage and trait
93- const [ percentage , ...traitArray ] = scoreText . split ( ' ' ) ;
92+ //Split the score text into percentage and trait
93+ const [ percentage , ...traitArray ] = scoreText . split ( ` ` ) ;
9494
95- // Return the traits details
95+ //Return the traits details
9696 return {
9797 category : categoryText || "" , // Trait category name, e.g., "Energy"
9898 value : traitArray . join ( " " ) || "" , // Extracted trait, e.g., "Extraverted"
@@ -101,12 +101,12 @@ export default async function({login, q, imports, data, account}, {enabled = fal
101101 }
102102 } ) ,
103103
104- // Color
105- color : document . querySelector ( ".card__bg" ) ? getComputedStyle ( document . querySelector ( ".card__bg" ) ) . backgroundColor : defaultColor
104+ //Color
105+ color : document . querySelector ( ".card__bg" ) ? getComputedStyle ( document . querySelector ( ".card__bg" ) ) . backgroundColor : defaultColor //eslint-disable-line no-undef
106106 }
107107 } )
108108
109- // Format data
109+ //Format data
110110 const { color} = raw
111111 const type = raw . type . replace ( "(" , "" ) . replace ( ")" , "" ) . trim ( )
112112 const personality = await Promise . all ( raw . personality . map ( async ( { category, value, image, text} ) => ( {
@@ -122,13 +122,13 @@ export default async function({login, q, imports, data, account}, {enabled = fal
122122 text : text . trim ( )
123123 } ) )
124124
125- // Close browser
125+ //Close browser
126126 await browser . close ( ) ;
127127
128- // Results
128+ //Results
129129 return { sections, color, type, personality, traits}
130130 }
131- // Handle errors
131+ //Handle errors
132132 catch ( error ) {
133133 throw imports . format . error ( error )
134134 }
0 commit comments