Skip to content

Commit b01f640

Browse files
Refactor updateModelDisplay to use DOM manipulation
Refactor model display update to use DOM methods instead of innerHTML for safer content insertion.
1 parent 94355ef commit b01f640

1 file changed

Lines changed: 28 additions & 33 deletions

File tree

src/html/index.html

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,6 @@
106106
#manager-info .model-tip { color: #6c757d; margin: 0; }
107107

108108
/* ── Charts container ────────────────────────────────── */
109-
/*
110-
* index.js checks getElementById('charts-container') first.
111-
* If found it uses it directly — no new div is created.
112-
* We pre-place it here with the right flex layout so the
113-
* chart wrappers index.js injects get the correct sizing.
114-
*/
115109
#charts-container {
116110
display: flex;
117111
flex-wrap: wrap;
@@ -121,11 +115,6 @@
121115
width: 100%;
122116
box-sizing: border-box;
123117
}
124-
125-
/*
126-
* index.js creates each wrapper with data-chart-wrapper="1"
127-
* and inline flex/size styles. We layer card styling on top.
128-
*/
129118
#charts-container > div[data-chart-wrapper="1"] {
130119
background: #fff;
131120
border-radius: var(--radius);
@@ -185,22 +174,11 @@ <h1>
185174
</div>
186175
</div>
187176

188-
<!-- ══ MODEL BANNER ══════════════════════════════════════ -->
189-
<!--
190-
index.js owns innerHTML of this div via renderManagerInfo().
191-
It also appends a <select> dropdown here via setupUI().
192-
Keep it empty — do not put static content inside.
193-
-->
177+
<!-- index.js owns innerHTML of this div via renderManagerInfo() -->
178+
<!-- It also appends a <select> dropdown here via setupUI() -->
194179
<div id="manager-info" role="status" aria-live="polite"></div>
195180

196-
<!-- ══ CHARTS ════════════════════════════════════════════ -->
197-
<!--
198-
Pre-placed so index.js → ensureChartElements() finds it
199-
immediately via getElementById('charts-container') and
200-
appends chart wrapper divs directly inside rather than
201-
creating a new container and inserting it after #manager-info.
202-
The CSS above styles each injected [data-chart-wrapper="1"].
203-
-->
181+
<!-- index.js → ensureChartElements() appends chart wrappers here -->
204182
<div id="charts-container"></div>
205183

206184
<!-- ══ FOOTER ════════════════════════════════════════════ -->
@@ -260,22 +238,39 @@ <h1>
260238

261239
/* ── model display (pre-index.js only; index.js overwrites innerHTML) ── */
262240
function updateModelDisplay(name, tip) {
263-
/* Once index.js has written its own HTML (contains the span), step back */
241+
/* Once index.js has written its own HTML (contains a span with inline color),
242+
step back and let it own the banner. */
264243
const m = $id('manager-info');
265244
if (m && m.querySelector('span[style*="color"]')) return;
266245

267246
const normalized = (typeof name === 'string' && name.trim()) ? name.trim() : null;
268247
if (!normalized) return;
269248

270249
if (m) {
271-
m.innerHTML =
272-
`<div style="font-weight:700;font-size:1rem;margin-bottom:4px">
273-
Active Model: <span class="model-name">${normalized}</span>
274-
</div>
275-
<p class="model-tip">${
276-
tip || MODEL_TIPS[normalized] || 'No tip available for this model.'
277-
}</p>`;
250+
/* ── FIX: build DOM with textContent instead of innerHTML ── */
251+
/* Clear existing children */
252+
while (m.firstChild) m.removeChild(m.firstChild);
253+
254+
/* Header div: "Active Model: <span.model-name>" */
255+
const headerDiv = document.createElement('div');
256+
headerDiv.style.fontWeight = '700';
257+
headerDiv.style.fontSize = '1rem';
258+
headerDiv.style.marginBottom = '4px';
259+
headerDiv.appendChild(document.createTextNode('Active Model: '));
260+
const nameSpan = document.createElement('span');
261+
nameSpan.className = 'model-name';
262+
nameSpan.textContent = normalized; /* safe: no HTML parsing */
263+
headerDiv.appendChild(nameSpan);
264+
265+
/* Tip paragraph */
266+
const tipP = document.createElement('p');
267+
tipP.className = 'model-tip';
268+
tipP.textContent = tip || MODEL_TIPS[normalized] || 'No tip available for this model.';
269+
270+
m.appendChild(headerDiv);
271+
m.appendChild(tipP);
278272
}
273+
279274
lastKnownModel = normalized;
280275
}
281276

0 commit comments

Comments
 (0)