fix: safeHTML live NodeList issue + expanded common words
Fixed safeHTML in all three files — template.content.childNodes and doc.body.childNodes are live NodeLists that shrink as nodes are moved. Using Array.from() to create a static copy before spreading into replaceChildren(). Expanded proper noun common words filter with ~500 additional verbs, nouns, and adjectives (generate, design, manage, process, account, button, dashboard, etc.) to prevent false PPI flags on titles, headings, and UI button labels. https://claude.ai/code/session_01SWSwDfMVij53bCTNSCLMwn
This commit is contained in:
@@ -14,7 +14,8 @@
|
|||||||
function safeHTML(el, html) {
|
function safeHTML(el, html) {
|
||||||
const template = document.createElement('template');
|
const template = document.createElement('template');
|
||||||
template.innerHTML = html;
|
template.innerHTML = html;
|
||||||
el.replaceChildren(...template.content.childNodes);
|
// Convert to static array — childNodes is live and shrinks as nodes move
|
||||||
|
el.replaceChildren(...Array.from(template.content.childNodes));
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============================================================
|
// ============================================================
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ const $ = (sel) => document.querySelector(sel);
|
|||||||
// --- Safe innerHTML replacement (AMO-compliant) ---
|
// --- Safe innerHTML replacement (AMO-compliant) ---
|
||||||
function safeHTML(el, html) {
|
function safeHTML(el, html) {
|
||||||
const doc = new DOMParser().parseFromString(html, 'text/html');
|
const doc = new DOMParser().parseFromString(html, 'text/html');
|
||||||
el.replaceChildren(...doc.body.childNodes);
|
el.replaceChildren(...Array.from(doc.body.childNodes));
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', async () => {
|
document.addEventListener('DOMContentLoaded', async () => {
|
||||||
|
|||||||
+1
-1
@@ -21,7 +21,7 @@ const $$ = (sel) => document.querySelectorAll(sel);
|
|||||||
// --- Safe innerHTML replacement (AMO-compliant) ---
|
// --- Safe innerHTML replacement (AMO-compliant) ---
|
||||||
function safeHTML(el, html) {
|
function safeHTML(el, html) {
|
||||||
const doc = new DOMParser().parseFromString(html, 'text/html');
|
const doc = new DOMParser().parseFromString(html, 'text/html');
|
||||||
el.replaceChildren(...doc.body.childNodes);
|
el.replaceChildren(...Array.from(doc.body.childNodes));
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Init ---
|
// --- Init ---
|
||||||
|
|||||||
Reference in New Issue
Block a user