class FeedItem extends HTMLElement { constructor() { super(); this.attachShadow({mode: 'open'}); } connectedCallback() { const template = document.createElement('template'); template.innerHTML = ` `; fetch(`/api/item/${this.getAttribute('item-id')}`) .then(res => res.json()) .then(item => { template.innerHTML += item.Content || item.Description; this.shadowRoot.appendChild(template.content.cloneNode(true)); [...this.shadowRoot.querySelectorAll('a[href^=http]')].forEach(a => { a.setAttribute("target", "_blank"); a.setAttribute("rel", "noopener"); }); [...this.shadowRoot.querySelectorAll('p')].forEach(p => { if (p.innerText.trim() == "") { p.remove(); } }) }) } } customElements.define('feed-item', FeedItem);