Skip to content

Commit

Permalink
Collapse content whitespace before matching.
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed Apr 18, 2014
1 parent b1e2c0d commit b6c4609
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 6 additions & 2 deletions chrome-extension/content.js
Expand Up @@ -3,8 +3,12 @@ function getElementByText(scope, text) {
// iterate descendants of scope
for (var all = scope.childNodes, index = 0, element; (element = all[index]); ++index) {
// conditionally return element containing visible, case-sensitive text (matched)
if (element.nodeType === 1 && (element.innerText || element.textContent || '').indexOf(text) !== -1) {
return getElementByText(element, text);
if (element.nodeType == 1) {
var el_text = element.innerText || element.textContent || '';
el_text = el_text.replace(/\s+/g, ' ');
if (el_text.indexOf(text) !== -1) {
return getElementByText(element, text);
}
}
}

Expand Down
8 changes: 6 additions & 2 deletions script.js
Expand Up @@ -6,8 +6,12 @@
// iterate descendants of scope
for (var all = scope.childNodes, index = 0, element; (element = all[index]); ++index) {
// conditionally return element containing visible, case-sensitive text (matched)
if (element.nodeType == 1 && (element.innerText || element.textContent || '').indexOf(text) !== -1) {
return getElementByText(element, text);
if (element.nodeType == 1) {
var el_text = element.innerText || element.textContent || '';
el_text = el_text.replace(/\s+/g, ' ');
if (el_text.indexOf(text) !== -1) {
return getElementByText(element, text);
}
}
}

Expand Down

0 comments on commit b6c4609

Please sign in to comment.