@@ -134,42 +134,50 @@ class ReportUIFeatures {
134
134
135
135
// get all tables with a text url
136
136
/** @type {Array<Element> } */
137
- const tables = Array . from ( document . querySelectorAll ( '.lh-table' ) ) ;
137
+ const tables = Array . from ( this . _document . querySelectorAll ( '.lh-table' ) ) ;
138
138
tables . filter ( el => el . querySelector ( 'td.lh-table-column--url' ) )
139
+ . filter ( el => el . closest ( '.lh-audit' ) . id !== 'uses-rel-preconnect' )
139
140
. forEach ( ( el , index ) => {
140
- const replacements = new Map ( ) ;
141
141
const urlItems = el . querySelectorAll ( '.lh-text__url' ) ;
142
+ const thirdPartyRows = { } ;
143
+
144
+ for ( const urlItem of urlItems ) {
145
+ const isThirdParty = ! urlItem . title . includes ( `${ pageTLDPlusOne } /` ) ;
146
+ if ( ! isThirdParty ) {
147
+ continue ;
148
+ }
149
+
150
+ const urlRow = urlItem . closest ( 'tr' ) ;
151
+ const rowPosition = Array . from ( el . tBodies [ 0 ] . children ) . indexOf ( urlRow ) ;
152
+ thirdPartyRows [ rowPosition ] = urlRow ;
153
+ }
142
154
143
155
// create input box
144
156
const filterTemplate = this . _dom . cloneTemplate ( '#tmpl-lh-3p-filter' , this . _document ) ;
145
157
const filterInput = filterTemplate . querySelector ( 'input' ) ;
146
158
const id = `lh-3p-filter-label--${ index } ` ;
147
159
filterTemplate . querySelector ( 'label' ) . setAttribute ( 'for' , id ) ;
148
160
filterInput . setAttribute ( 'id' , id ) ;
161
+ filterTemplate . querySelector ( '.lh-3p-filter-count' ) . innerHTML = Object . keys ( thirdPartyRows ) . length ;
149
162
150
163
filterInput . addEventListener ( 'change' , e => {
151
164
// remove elements from the dom and keep track of them to readd on uncheck
152
165
// why removing instead of hiding? nth-child(even) background-colors keep working
153
166
if ( e . target . checked ) {
154
- let i = 0 ;
155
- for ( const urlItem of urlItems ) {
156
- const isThirdParty = ! urlItem . title . includes ( `${ pageTLDPlusOne } /` ) ;
157
- if ( ! isThirdParty ) continue ;
167
+ Object . keys ( thirdPartyRows ) . forEach ( position => {
168
+ const row = thirdPartyRows [ position ] ;
158
169
159
- const urlRow = urlItem . closest ( 'tr' ) ;
160
- replacements . set ( urlRow , Array . from ( el . tBodies [ 0 ] . children ) . indexOf ( urlRow ) + i ++ ) ;
161
-
162
- urlRow . parentNode . removeChild ( urlRow ) ;
163
- }
164
- } else {
165
- for ( let [ urlRow , position ] of replacements . entries ( ) ) {
166
- // if we have children we add them on the right position, else we just append it to the list
167
- if ( el . tBodies [ 0 ] . children . length ) {
168
- Array . from ( el . tBodies [ 0 ] . children ) [ position - 1 ] . insertAdjacentElement ( 'afterend' , urlRow ) ;
170
+ if ( position == 0 ) {
171
+ el . tBodies [ 0 ] . appendChild ( row ) ;
169
172
} else {
170
- el . tBodies [ 0 ] . appendChild ( urlRow ) ;
173
+ Array . from ( el . tBodies [ 0 ] . children ) [ Number ( position ) - 1 ] . insertAdjacentElement ( 'afterend' , row ) ;
171
174
}
172
- }
175
+ } ) ;
176
+ } else {
177
+ Object . keys ( thirdPartyRows ) . forEach ( position => {
178
+ const row = thirdPartyRows [ position ] ;
179
+ row . parentNode . removeChild ( row ) ;
180
+ } ) ;
173
181
}
174
182
} ) ;
175
183
0 commit comments