File tree Expand file tree Collapse file tree 1 file changed +29
-8
lines changed Expand file tree Collapse file tree 1 file changed +29
-8
lines changed Original file line number Diff line number Diff line change
1
+ const hideShadowElement = ( shadowRoot , selector , timeout = 5000 ) => {
2
+ if ( ! shadowRoot ) return ;
3
+
4
+ const hideElement = ( ) => {
5
+ const el = shadowRoot . querySelector ( selector ) ;
6
+ if ( el ) {
7
+ el . style . display = 'none' ;
8
+ return true ;
9
+ }
10
+ return false ;
11
+ } ;
12
+
13
+ if ( hideElement ( ) ) {
14
+ return ;
15
+ }
16
+
17
+ const observer = new MutationObserver ( ( _mutations , obs ) => {
18
+ if ( hideElement ( ) ) {
19
+ obs . disconnect ( ) ;
20
+ }
21
+ } ) ;
22
+
23
+ observer . observe ( shadowRoot , { childList : true , subtree : true } ) ;
24
+
25
+ setTimeout ( ( ) => observer . disconnect ( ) , timeout ) ;
26
+ } ;
27
+
1
28
function isJwtExpired ( token ) {
2
29
const parts = token . split ( '.' ) ;
3
30
if ( parts . length !== 3 ) {
@@ -90,14 +117,8 @@ async function atomicCoveo() {
90
117
await searchBarSidebar . executeFirstSearch ( ) ;
91
118
}
92
119
93
- /* Hide atomic-relevance-inspector */
94
- const shadowElements = searchBarHeader . shadowRoot . childNodes ;
95
- for ( let i = 0 ; i < shadowElements . length ; i ++ ) {
96
- const val = shadowElements [ i ] ;
97
- if ( val . localName === 'atomic-relevance-inspector' ) {
98
- val . style . display = 'none' ;
99
- break ;
100
- }
120
+ if ( searchBarHeader ?. shadowRoot ) {
121
+ hideShadowElement ( searchBarHeader . shadowRoot , 'atomic-relevance-inspector' ) ;
101
122
}
102
123
}
103
124
You can’t perform that action at this time.
0 commit comments