Skip to content

Commit 0a56509

Browse files
committed
Show 3p table
1 parent 6ed6799 commit 0a56509

File tree

2 files changed

+28
-20
lines changed

2 files changed

+28
-20
lines changed

lighthouse-core/report/html/renderer/report-ui-features.js

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -134,42 +134,50 @@ class ReportUIFeatures {
134134

135135
// get all tables with a text url
136136
/** @type {Array<Element>} */
137-
const tables = Array.from(document.querySelectorAll('.lh-table'));
137+
const tables = Array.from(this._document.querySelectorAll('.lh-table'));
138138
tables.filter(el => el.querySelector('td.lh-table-column--url'))
139+
.filter(el => el.closest('.lh-audit').id !== 'uses-rel-preconnect')
139140
.forEach((el, index) => {
140-
const replacements = new Map();
141141
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+
}
142154

143155
// create input box
144156
const filterTemplate = this._dom.cloneTemplate('#tmpl-lh-3p-filter', this._document);
145157
const filterInput = filterTemplate.querySelector('input');
146158
const id = `lh-3p-filter-label--${index}`;
147159
filterTemplate.querySelector('label').setAttribute('for', id);
148160
filterInput.setAttribute('id', id);
161+
filterTemplate.querySelector('.lh-3p-filter-count').innerHTML = Object.keys(thirdPartyRows).length;
149162

150163
filterInput.addEventListener('change', e => {
151164
// remove elements from the dom and keep track of them to readd on uncheck
152165
// why removing instead of hiding? nth-child(even) background-colors keep working
153166
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];
158169

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);
169172
} else {
170-
el.tBodies[0].appendChild(urlRow);
173+
Array.from(el.tBodies[0].children)[Number(position) - 1].insertAdjacentElement('afterend', row);
171174
}
172-
}
175+
});
176+
} else {
177+
Object.keys(thirdPartyRows).forEach(position => {
178+
const row = thirdPartyRows[position];
179+
row.parentNode.removeChild(row);
180+
});
173181
}
174182
});
175183

lighthouse-core/report/html/templates.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -666,8 +666,8 @@
666666
</style>
667667
<div class="lh-3p-filter">
668668
<label class="lh-3p-filter-label">
669-
Filter out 3rd-parties:
670-
<input type="checkbox" class="lh-3p-filter-input">
669+
<input type="checkbox" class="lh-3p-filter-input" checked />
670+
Show 3th party resources (<span class="lh-3p-filter-count"></span>)
671671
</label>
672672
</div>
673673
</template>

0 commit comments

Comments
 (0)