1
- // Setup
1
+ //Setup
2
2
export default async function ( { login, q, imports, data, account} , { enabled = false , extras = false } = { } ) {
3
3
try {
4
- // Check if the plugin is enabled and requirements are met
4
+ //Check if the plugin is enabled and requirements are met
5
5
if ( ( ! q [ "16personalities" ] ) || ( ! imports . metadata . plugins [ "16personalities" ] . enabled ( enabled , { extras} ) ) )
6
6
return null
7
7
8
- // Load inputs
8
+ //Load inputs
9
9
let { url, sections, scores} = imports . metadata . plugins [ "16personalities" ] . inputs ( { data, account, q} )
10
10
if ( ! url )
11
11
throw { error : { message : "URL is not set" } }
12
12
13
- // Start puppeteer and navigate to page
13
+ //Start puppeteer and navigate to page
14
14
console . debug ( `metrics/compute/${ login } /plugins > 16personalities > starting browser` )
15
15
const browser = await imports . puppeteer . launch ( )
16
16
console . debug ( `metrics/compute/${ login } /plugins > 16personalities > started ${ await browser . version ( ) } ` )
17
17
const page = await browser . newPage ( )
18
18
console . debug ( `metrics/compute/${ login } /plugins > 16personalities > loading ${ url } ` )
19
19
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 ( ) } ` )
24
24
}
25
25
} )
26
26
27
- await page . goto ( url , { waitUntil : ' networkidle2' } )
27
+ await page . goto ( url , { waitUntil : " networkidle2" } )
28
28
29
- // Fetch raw data
29
+ //Fetch raw data
30
30
const raw = await page . evaluate ( ( ) => {
31
- const getInnerText = ( selector ) => document . querySelector ( selector ) ?. innerText || ""
31
+ const getInnerText = selector => document . querySelector ( selector ) ?. innerText || ""
32
32
33
- // Default map personality category to RGB colors
33
+ //Default map personality category to RGB colors
34
34
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)"
40
40
}
41
41
let defaultColor = defaultPersonalityColors . default
42
42
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" )
45
45
if ( personalityType . includes ( "Virtuoso" ) || personalityType . includes ( "Adventurer" ) || personalityType . includes ( "Entrepreneur" ) || personalityType . includes ( "Entertainer" ) )
46
46
defaultColor = defaultPersonalityColors . explorers
47
47
else if ( personalityType . includes ( "Logistician" ) || personalityType . includes ( "Defender" ) || personalityType . includes ( "Executive" ) || personalityType . includes ( "Consul" ) )
48
48
defaultColor = defaultPersonalityColors . sentinels
49
49
else if ( personalityType . includes ( "Advocate" ) || personalityType . includes ( "Mediator" ) || personalityType . includes ( "Protagonist" ) || personalityType . includes ( "Campaigner" ) )
50
50
defaultColor = defaultPersonalityColors . diplomats
51
51
else if ( personalityType . includes ( "Architect" ) || personalityType . includes ( "Logician" ) || personalityType . includes ( "Commander" ) || personalityType . includes ( "Debater" ) )
52
- defaultColor = defaultPersonalityColors . analysts ;
52
+ defaultColor = defaultPersonalityColors . analysts
53
53
54
54
console . debug ( `Personality Type: ${ personalityType } ` )
55
55
56
56
return {
57
- // Type extraction
57
+ //Type extraction
58
58
type : getInnerText ( ".type__code" ) ,
59
59
60
- // Personality details extraction
60
+ //Personality details extraction
61
61
personality : [ ...document . querySelectorAll ( ".slider__slides > div" ) ] . map ( card => {
62
- // Extract image data
62
+ //Extract image data
63
63
let image = ""
64
64
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
66
66
if ( cardElement . querySelector ( "img" ) ) {
67
67
image = cardElement . querySelector ( "img" ) . src
68
68
console . debug ( `Image for ${ card . querySelector ( ".card__title" ) ?. innerText } : ${ image } ` )
69
69
}
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
71
71
else if ( cardElement . querySelector ( "svg" ) ) {
72
72
image = new XMLSerializer ( ) . serializeToString ( cardElement . querySelector ( "svg" ) )
73
73
image = `data:image/svg+xml,${ encodeURIComponent ( image ) } `
74
74
console . debug ( `Image for ${ card . querySelector ( ".card__title" ) ?. innerText } is a svg` )
75
75
}
76
76
77
77
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
82
82
}
83
83
} ) ,
84
84
85
- // Traits details extraction
85
+ //Traits details extraction
86
86
traits : [ ...document . querySelectorAll ( ".traits__boxes > div" ) ] . map ( card => {
87
87
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"
89
89
90
- console . debug ( `Parsing Trait category ${ categoryText } ${ scoreText } ` ) ;
90
+ console . debug ( `Parsing Trait category ${ categoryText } ${ scoreText } ` )
91
91
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 ( " " )
94
94
95
- // Return the traits details
95
+ //Return the traits details
96
96
return {
97
- category : categoryText || "" , // Trait category name, e.g., "Energy"
98
- value : traitArray . join ( " " ) || "" , // Extracted trait, e.g., "Extraverted"
99
- score : percentage || "" , // Extracted percentage, e.g., "75%"
100
- text : card . querySelector ( "p" ) . innerText || "" // Description of the trait
97
+ category : categoryText || "" , //Trait category name, e.g., "Energy"
98
+ value : traitArray . join ( " " ) || "" , //Extracted trait, e.g., "Extraverted"
99
+ score : percentage || "" , //Extracted percentage, e.g., "75%"
100
+ text : card . querySelector ( "p" ) . innerText || "" //Description of the trait
101
101
}
102
102
} ) ,
103
103
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
106
106
}
107
107
} )
108
108
109
- // Format data
109
+ //Format data
110
110
const { color} = raw
111
111
const type = raw . type . replace ( "(" , "" ) . replace ( ")" , "" ) . trim ( )
112
112
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
122
122
text : text . trim ( )
123
123
} ) )
124
124
125
- // Close browser
126
- await browser . close ( ) ;
125
+ //Close browser
126
+ await browser . close ( )
127
127
128
- // Results
128
+ //Results
129
129
return { sections, color, type, personality, traits}
130
130
}
131
- // Handle errors
131
+ //Handle errors
132
132
catch ( error ) {
133
133
throw imports . format . error ( error )
134
134
}
0 commit comments