diff --git a/examples/script.js b/examples/script.js index 26cbf66..b3496e5 100644 --- a/examples/script.js +++ b/examples/script.js @@ -123,6 +123,22 @@ const updateIdentities = async () => { } }; +/** + * Add a span to an element with text contents + * @param {HTMLElement} parent + * @param {string} text + * @param {string?} classes optional space-separated CSS classes to apply + * @param {{string: string}?} style optional CSS styles to apply + * @return {HTMLSpanElement} + */ +function addSpan(parent, text, classes, style) { + const span = document.createElement('span'); + span.textContent = text; + if (classes) span.classList.add(...classes.split(' ')); + if (style) Object.assign(span.style, style); + parent.appendChild(span); +} + // render a TSP message with debug information function renderMessage(message) { const card = document.createElement('div'); @@ -136,35 +152,53 @@ function renderMessage(message) {
- ${parts.map((part, index) => - message[part] ? `
+ ` : '' - ).join('')} -