JSFiddle - React, Tailwind, and code Playground
by brigand
HTML
<div class="noStandardTab"><div class="dataRow">
<br>https://files.support.bla/files
https://bla/,test,test
https://bla/
</div></div>
<div class="noStandardTab"><div class="dataRow">
<br>https://files.support||||/files/error
</div></div>
<ul>
<li id="li1"></li>
</ul>
JavaScript
const case_attachments = []
const related_list_items = [li1]
document.querySelectorAll('.noStandardTab .dataRow').forEach(node => {
// Build an array of all attachments linked in the case comments
if (node.innerHTML.match(/<br>https?:\/\/files.support.*\/files/)) {
let match = node.innerHTML.match(/https?:\/\/([-\w\d()@:%+.~#?&;/=]*)?/g);
if (match) {
case_attachments.push(...match);
}
}
// ..also other stuff
});
case_attachments.forEach((link, index) => {
related_list_items[0].insertAdjacentHTML('beforeend',`<li><a href="${link}" target="_blank">📁 File ${link.split('/').slice(-1)[0]} (${index})</a></li>`);
index++
});