@@ -2,87 +2,91 @@ let buildWithAIInserted = false; // Flag to track if the Build with AI element i
2
2
3
3
// Function to create an SVG icon element
4
4
function createSVGIcon ( ) {
5
- const svg = document . createElementNS ( 'http://www.w3.org/2000/svg' , 'svg' ) ;
6
- svg . setAttribute ( 'xmlns' , 'http://www.w3.org/2000/svg' ) ;
7
- svg . setAttribute ( 'viewBox' , '0 0 384 512' ) ;
8
- svg . setAttribute ( 'width' , '50px' ) ;
9
- svg . setAttribute ( 'height' , '50px' ) ;
10
-
11
- const path = document . createElementNS ( 'http://www.w3.org/2000/svg' , 'path' ) ;
5
+ const svg = document . createElementNS ( 'http://www.w3.org/2000/svg' , 'svg' ) ;
6
+ svg . setAttribute ( 'xmlns' , 'http://www.w3.org/2000/svg' ) ;
7
+ svg . setAttribute ( 'viewBox' , '0 0 384 512' ) ;
8
+ svg . setAttribute ( 'width' , '50px' ) ;
9
+ svg . setAttribute ( 'height' , '50px' ) ;
10
+
11
+ const path = document . createElementNS (
12
+ 'http://www.w3.org/2000/svg' ,
13
+ 'path'
14
+ ) ;
12
15
path . setAttribute (
13
16
'd' ,
14
17
'M162.4 6c-1.5-3.6-5-6-8.9-6l-19 0c-3.9 0-7.5 2.4-8.9 6L104.9 57.7c-3.2 8-14.6 8-17.8 0L66.4 6c-1.5-3.6-5-6-8.9-6L48 0C21.5 0 0 21.5 0 48L0 224l0 22.4L0 256l9.6 0 364.8 0 9.6 0 0-9.6 0-22.4 0-176c0-26.5-21.5-48-48-48L230.5 0c-3.9 0-7.5 2.4-8.9 6L200.9 57.7c-3.2 8-14.6 8-17.8 0L162.4 6zM0 288l0 32c0 35.3 28.7 64 64 64l64 0 0 64c0 35.3 28.7 64 64 64s64-28.7 64-64l0-64 64 0c35.3 0 64-28.7 64-64l0-32L0 288zM192 432a16 16 0 1 1 0 32 16 16 0 1 1 0-32z'
15
18
) ;
16
- path . setAttribute ( 'fill' , '#8c8f94' ) ;
17
- svg . appendChild ( path ) ;
19
+ path . setAttribute ( 'fill' , '#8c8f94' ) ;
20
+ svg . appendChild ( path ) ;
18
21
19
22
return svg ;
20
23
}
21
24
22
25
// Function to create the 'Build with AI' element
23
- function createBuildWithAIElement ( themeDiv ) {
24
- const buildWithAIElement = document . createElement ( 'div' ) ;
25
- buildWithAIElement . classList . add ( 'theme' , 'build-with-ai' ) ;
26
- buildWithAIElement . style . height = `${ themeDiv . offsetHeight } px` ;
26
+ function createBuildWithAIElement ( themeDiv ) {
27
+ const buildWithAIElement = document . createElement ( 'div' ) ;
28
+ buildWithAIElement . classList . add ( 'theme' , 'build-with-ai' ) ;
29
+ buildWithAIElement . style . height = `${ themeDiv . offsetHeight } px` ;
27
30
28
- const newLink = document . createElement ( 'span' ) ;
29
- newLink . classList . add ( 'build-with-ai__link' ) ;
31
+ const newLink = document . createElement ( 'span' ) ;
32
+ newLink . classList . add ( 'build-with-ai__link' ) ;
30
33
31
- const themeScreenshot = document . createElement ( 'div' ) ;
32
- themeScreenshot . classList . add ( 'build-with-ai__icon' ) ;
34
+ const themeScreenshot = document . createElement ( 'div' ) ;
35
+ themeScreenshot . classList . add ( 'build-with-ai__icon' ) ;
33
36
34
- const iconSpan = document . createElement ( 'span' ) ;
35
- iconSpan . classList . add ( 'build-with-ai__icon-span' ) ;
36
- iconSpan . appendChild ( createSVGIcon ( ) ) ;
37
- themeScreenshot . appendChild ( iconSpan ) ;
37
+ const iconSpan = document . createElement ( 'span' ) ;
38
+ iconSpan . classList . add ( 'build-with-ai__icon-span' ) ;
39
+ iconSpan . appendChild ( createSVGIcon ( ) ) ;
40
+ themeScreenshot . appendChild ( iconSpan ) ;
38
41
39
- const themeName = document . createElement ( 'h2' ) ;
40
- themeName . classList . add ( 'build-with-ai__text' ) ;
42
+ const themeName = document . createElement ( 'h2' ) ;
43
+ themeName . classList . add ( 'build-with-ai__text' ) ;
41
44
themeName . textContent = window . nfdOnboardingRestartMeta ?. buttonText ;
42
45
43
- newLink . appendChild ( themeScreenshot ) ;
44
- newLink . appendChild ( themeName ) ;
45
- buildWithAIElement . appendChild ( newLink ) ;
46
+ newLink . appendChild ( themeScreenshot ) ;
47
+ newLink . appendChild ( themeName ) ;
48
+ buildWithAIElement . appendChild ( newLink ) ;
46
49
47
- buildWithAIElement . addEventListener ( 'click' , ( ) => {
50
+ buildWithAIElement . addEventListener ( 'click' , ( ) => {
48
51
window . location . href =
49
52
window . nfdOnboardingRestartMeta ?. buttonHref + '&restart=theme' ;
50
- } ) ;
53
+ } ) ;
51
54
52
55
return buildWithAIElement ;
53
56
}
54
57
55
58
// Function to handle the appearance of the themeDiv
56
59
function handleThemeDivAppearance ( ) {
57
- const themeDiv = document . querySelector ( '.add-new-theme' ) ;
60
+ const themeDiv = document . querySelector ( '.add-new-theme' ) ;
58
61
59
- if ( themeDiv && ! buildWithAIInserted ) {
62
+ if ( themeDiv && ! buildWithAIInserted ) {
60
63
// Check if the element exists and hasn't been inserted yet
61
64
62
- const buildWithAIElement = createBuildWithAIElement ( themeDiv ) ;
63
- themeDiv . parentNode . insertBefore ( buildWithAIElement , themeDiv ) ;
65
+ const buildWithAIElement = createBuildWithAIElement ( themeDiv ) ;
66
+ themeDiv . parentNode . insertBefore ( buildWithAIElement , themeDiv ) ;
64
67
65
68
buildWithAIInserted = true ; // Set the flag to true after insertion
66
69
}
67
70
}
68
71
69
72
// Setting up MutationObserver to detect the appearance of the themeDiv element
70
73
function observeForThemeDiv ( ) {
71
- const observer = new MutationObserver ( ( mutationsList , observer ) => {
72
- mutationsList . forEach ( ( mutation ) => {
73
- if ( mutation . type === 'childList' ) {
74
+ // eslint-disable-next-line no-undef
75
+ const observerObj = new MutationObserver ( ( mutationsList ) => {
76
+ mutationsList . forEach ( ( mutation ) => {
77
+ if ( mutation . type === 'childList' ) {
74
78
handleThemeDivAppearance ( ) ; // Check for the element whenever the DOM changes
75
79
}
76
- } ) ;
77
- } ) ;
80
+ } ) ;
81
+ } ) ;
78
82
79
- observer . observe ( document . body , {
83
+ observerObj . observe ( document . body , {
80
84
childList : true ,
81
85
subtree : true ,
82
- } ) ;
86
+ } ) ;
83
87
}
84
88
85
89
// Wait for the DOM to be fully loaded and then start observing
86
- window . addEventListener ( 'DOMContentLoaded' , function ( ) {
90
+ window . addEventListener ( 'DOMContentLoaded' , function ( ) {
87
91
observeForThemeDiv ( ) ;
88
- } ) ;
92
+ } ) ;
0 commit comments