I'm working on an extension for modifying specific text by traversing the DOM. It works fine for sites that don't obfuscate page structure too much but has trouble with Twitter.
This is the basic loop I'm using...
//iterate over DOM nodes and match text
var elements = document.body.getElementsByTagName("*"); //HTMLCollection
for (let i = 0; i < elements.length; i++) {
var e = elements[i];
for (let j = 0; j < e.childNodes.length; j++) {
var node = e.childNodes[j];
if (node.nodeType === 3) { //text node
//
Twitter buries tweet text in a span element like this, which is within DIVs and an ARTICLE element.
<span class="css-901oao css-16my406 r-poiln3 r-bcqeeo r-qvutc0">TEXT</span>
If anyone has any experience with this, should I be iterating through the InnerHTML (textContent?) of elements (nodeType 1)? Or starting with a different parent than BODY for the traversal? I'd like to find a better approach to matching all text on a page. Thanks.