function(text, mode) {
const needle = mode === 'exact' ? text : text.toLowerCase();
const matches = el => {
const raw = (el.innerText || el.textContent || el.value || '').trim();
return mode === 'exact' ? raw === needle : raw.toLowerCase().includes(needle);
};
const interactive = Array.from(document.querySelectorAll('a,button,input[type="submit"],input[type="button"],[role="button"],[onclick]')).filter(matches);
if (interactive.length) return interactive;
return Array.from(document.querySelectorAll('label,span,div,p,h1,h2,h3,h4,h5,h6,li,td,th'))
.filter(matches)
.filter(el => !Array.from(el.children).some(matches));
}